Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil-cisco@xs4all.nl: fix checkpatch warning]
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Ezequiel Garcia and committed by
Mauro Carvalho Chehab
51ff392c a9cff393

+32 -23
+2 -23
drivers/media/v4l2-core/v4l2-device.c
··· 9 9 #include <linux/types.h> 10 10 #include <linux/ioctl.h> 11 11 #include <linux/module.h> 12 - #include <linux/i2c.h> 13 12 #include <linux/slab.h> 14 13 #include <linux/videodev2.h> 15 14 #include <media/v4l2-device.h> ··· 98 99 /* Unregister subdevs */ 99 100 list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) { 100 101 v4l2_device_unregister_subdev(sd); 101 - #if IS_ENABLED(CONFIG_I2C) 102 - if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) { 103 - struct i2c_client *client = v4l2_get_subdevdata(sd); 104 - 105 - /* 106 - * We need to unregister the i2c client 107 - * explicitly. We cannot rely on 108 - * i2c_del_adapter to always unregister 109 - * clients for us, since if the i2c bus is a 110 - * platform bus, then it is never deleted. 111 - * 112 - * Device tree or ACPI based devices must not 113 - * be unregistered as they have not been 114 - * registered by us, and would not be 115 - * re-created by just probing the V4L2 driver. 116 - */ 117 - if (client && 118 - !client->dev.of_node && !client->dev.fwnode) 119 - i2c_unregister_device(client); 120 - continue; 121 - } 122 - #endif 102 + if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) 103 + v4l2_i2c_subdev_unregister(sd); 123 104 else if (sd->flags & V4L2_SUBDEV_FL_IS_SPI) 124 105 v4l2_spi_subdev_unregister(sd); 125 106 }
+20
drivers/media/v4l2-core/v4l2-i2c.c
··· 8 8 #include <media/v4l2-common.h> 9 9 #include <media/v4l2-device.h> 10 10 11 + void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd) 12 + { 13 + struct i2c_client *client = v4l2_get_subdevdata(sd); 14 + 15 + /* 16 + * We need to unregister the i2c client 17 + * explicitly. We cannot rely on 18 + * i2c_del_adapter to always unregister 19 + * clients for us, since if the i2c bus is a 20 + * platform bus, then it is never deleted. 21 + * 22 + * Device tree or ACPI based devices must not 23 + * be unregistered as they have not been 24 + * registered by us, and would not be 25 + * re-created by just probing the V4L2 driver. 26 + */ 27 + if (client && !client->dev.of_node && !client->dev.fwnode) 28 + i2c_unregister_device(client); 29 + } 30 + 11 31 void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client, 12 32 const char *devname, const char *postfix) 13 33 {
+10
include/media/v4l2-common.h
··· 211 211 */ 212 212 const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type); 213 213 214 + /** 215 + * v4l2_i2c_subdev_unregister - Unregister a v4l2_subdev 216 + * 217 + * @sd: pointer to &struct v4l2_subdev 218 + */ 219 + void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd); 220 + 214 221 #else 215 222 216 223 static inline struct v4l2_subdev * ··· 256 249 { 257 250 return NULL; 258 251 } 252 + 253 + static inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd) 254 + {} 259 255 260 256 #endif 261 257