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 spi subdev

Introduce a new video4linux2 spi helper, to unregister a subdev.
This allows to get rid of some more ifdefs.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Ezequiel Garcia and committed by
Mauro Carvalho Chehab
a9cff393 02283b98

+19 -12
+2 -12
drivers/media/v4l2-core/v4l2-device.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/i2c.h> 13 13 #include <linux/slab.h> 14 - #if defined(CONFIG_SPI) 15 - #include <linux/spi/spi.h> 16 - #endif 17 14 #include <linux/videodev2.h> 18 15 #include <media/v4l2-device.h> 19 16 #include <media/v4l2-ctrls.h> ··· 121 124 continue; 122 125 } 123 126 #endif 124 - #if defined(CONFIG_SPI) 125 - if (sd->flags & V4L2_SUBDEV_FL_IS_SPI) { 126 - struct spi_device *spi = v4l2_get_subdevdata(sd); 127 - 128 - if (spi && !spi->dev.of_node && !spi->dev.fwnode) 129 - spi_unregister_device(spi); 130 - continue; 131 - } 132 - #endif 127 + else if (sd->flags & V4L2_SUBDEV_FL_IS_SPI) 128 + v4l2_spi_subdev_unregister(sd); 133 129 } 134 130 /* Mark as unregistered, thus preventing duplicate unregistrations */ 135 131 v4l2_dev->name[0] = '\0';
+8
drivers/media/v4l2-core/v4l2-spi.c
··· 8 8 #include <media/v4l2-common.h> 9 9 #include <media/v4l2-device.h> 10 10 11 + void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd) 12 + { 13 + struct spi_device *spi = v4l2_get_subdevdata(sd); 14 + 15 + if (spi && !spi->dev.of_node && !spi->dev.fwnode) 16 + spi_unregister_device(spi); 17 + } 18 + 11 19 void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 12 20 const struct v4l2_subdev_ops *ops) 13 21 {
+9
include/media/v4l2-common.h
··· 285 285 void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 286 286 const struct v4l2_subdev_ops *ops); 287 287 288 + /** 289 + * v4l2_spi_subdev_unregister - Unregister a v4l2_subdev 290 + * 291 + * @sd: pointer to &struct v4l2_subdev 292 + */ 293 + void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd); 294 + 288 295 #else 289 296 290 297 static inline struct v4l2_subdev * ··· 306 299 const struct v4l2_subdev_ops *ops) 307 300 {} 308 301 302 + static inline void v4l2_spi_subdev_unregister(struct v4l2_subdev *sd) 303 + {} 309 304 #endif 310 305 311 306 /* ------------------------------------------------------------------------- */