From 51ff392c280733aa9e6bd47b3f5e83e32bfdf16a Mon Sep 17 00:00:00 2001 From: Ezequiel Garcia Date: Thu, 15 Aug 2019 13:48:05 -0300 Subject: media: v4l2-core: introduce a helper to unregister a i2c subdev Introduce a new video4linux2 i2c helper, to unregister a subdev. This allows to get rid of yet another ifdef. Signed-off-by: Ezequiel Garcia Signed-off-by: Hans Verkuil [hverkuil-cisco@xs4all.nl: fix checkpatch warning] Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-device.c | 25 ++----------------------- drivers/media/v4l2-core/v4l2-i2c.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 23 deletions(-) (limited to 'drivers') diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c index c2811238996f..63d6b147b21e 100644 --- a/drivers/media/v4l2-core/v4l2-device.c +++ b/drivers/media/v4l2-core/v4l2-device.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -99,28 +98,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev) /* Unregister subdevs */ list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) { v4l2_device_unregister_subdev(sd); -#if IS_ENABLED(CONFIG_I2C) - if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) { - struct i2c_client *client = v4l2_get_subdevdata(sd); - - /* - * We need to unregister the i2c client - * explicitly. We cannot rely on - * i2c_del_adapter to always unregister - * clients for us, since if the i2c bus is a - * platform bus, then it is never deleted. - * - * Device tree or ACPI based devices must not - * be unregistered as they have not been - * registered by us, and would not be - * re-created by just probing the V4L2 driver. - */ - if (client && - !client->dev.of_node && !client->dev.fwnode) - i2c_unregister_device(client); - continue; - } -#endif + if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) + v4l2_i2c_subdev_unregister(sd); else if (sd->flags & V4L2_SUBDEV_FL_IS_SPI) v4l2_spi_subdev_unregister(sd); } diff --git a/drivers/media/v4l2-core/v4l2-i2c.c b/drivers/media/v4l2-core/v4l2-i2c.c index f393dd4f1c00..a26d48f23a2d 100644 --- a/drivers/media/v4l2-core/v4l2-i2c.c +++ b/drivers/media/v4l2-core/v4l2-i2c.c @@ -8,6 +8,26 @@ #include #include +void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + + /* + * We need to unregister the i2c client + * explicitly. We cannot rely on + * i2c_del_adapter to always unregister + * clients for us, since if the i2c bus is a + * platform bus, then it is never deleted. + * + * Device tree or ACPI based devices must not + * be unregistered as they have not been + * registered by us, and would not be + * re-created by just probing the V4L2 driver. + */ + if (client && !client->dev.of_node && !client->dev.fwnode) + i2c_unregister_device(client); +} + void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client, const char *devname, const char *postfix) { -- cgit v1.2.3