media: entity: Add a nop variant of media_entity_cleanupr
Subsystems (6)
Sakari Ailus
maintainerPATCH 1/1 media: entity: Add a nop variant of media_entity_cleanupr
Add nop variant of media_entity_cleanup. This allows calling media_entity_cleanup whether or not Media controller is enabled, simplifying driver code.
Also drop #ifdefs on a few drivers around media_entity_cleanup() and drop the extra semicolon from media_entity_cleanup prototype.
---
Hi Arnd,
I thought about doing something similar with media_entity_pads_init which is equally commonly used in drivers that support MC/non-MC cases. The trouble with that is that the drivers set up the struct first before calling media_entity_pads_init, requiring the #ifdefs in any case. So the benefit would be questionable at least. So just media_entity_cleanup this time.
drivers/media/i2c/mt9m111.c | 2 -- drivers/media/i2c/ov2640.c | 4 ---- drivers/media/i2c/ov2659.c | 4 ---- drivers/media/i2c/ov7670.c | 4 ---- drivers/media/i2c/ov7740.c | 2 -- drivers/media/i2c/tvp514x.c | 4 ---- include/media/media-entity.h | 6 +++++- 7 files changed, 5 insertions(+), 21 deletions(-)
drivers/media/i2c/mt9m111.c +0 -2
@@ -1046,9 +1046,7 @@ static int mt9m111_remove(struct i2c_client *client)struct mt9m111 *mt9m111 =to_mt9m111 (client);v4l2_async_unregister_subdev (&mt9m111->subdev); -#ifdef CONFIG_MEDIA_CONTROLLER media_entity_cleanup (&mt9m111->subdev.entity); -#endif v4l2_clk_put (mt9m111->clk);v4l2_ctrl_handler_free (&mt9m111->hdl);
drivers/media/i2c/ov2640.c +0 -4
@@ -1147,9 +1147,7 @@ static int ov2640_probe(struct i2c_client *client,return 0 ; err_videoprobe: -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&priv->subdev.entity); -#endif err_hdl:v4l2_ctrl_handler_free (&priv->hdl); err_clk:
@@ -1163,9 +1161,7 @@ static int ov2640_remove(struct i2c_client *client)v4l2_async_unregister_subdev (&priv->subdev);v4l2_ctrl_handler_free (&priv->hdl); -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&priv->subdev.entity); -#endif v4l2_device_unregister_subdev (&priv->subdev);clk_disable_unprepare (priv->clk);return 0 ;
drivers/media/i2c/ov2659.c +0 -4
@@ -1474,9 +1474,7 @@ static int ov2659_probe(struct i2c_client *client, error:v4l2_ctrl_handler_free (&ov2659->ctrls); -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&sd->entity); -#endif mutex_destroy (&ov2659->lock);return ret; }
@@ -1488,9 +1486,7 @@ static int ov2659_remove(struct i2c_client *client)v4l2_ctrl_handler_free (&ov2659->ctrls);v4l2_async_unregister_subdev (sd); -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&sd->entity); -#endif mutex_destroy (&ov2659->lock);return 0 ;
drivers/media/i2c/ov7670.c +0 -4
@@ -1846,9 +1846,7 @@ static int ov7670_probe(struct i2c_client *client,return 0 ; entity_cleanup: -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&info->sd.entity); -#endif hdl_free:v4l2_ctrl_handler_free (&info->hdl); power_off:
@@ -1867,9 +1865,7 @@ static int ov7670_remove(struct i2c_client *client)v4l2_async_unregister_subdev (sd);v4l2_ctrl_handler_free (&info->hdl);clk_disable_unprepare (info->clk); -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&info->sd.entity); -#endif ov7670_s_power (sd,0 );return 0 ; }
drivers/media/i2c/ov7740.c +0 -2
@@ -1148,9 +1148,7 @@ static int ov7740_remove(struct i2c_client *client)mutex_destroy (&ov7740->mutex);v4l2_ctrl_handler_free (ov7740->subdev.ctrl_handler); -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&ov7740->subdev.entity); -#endif v4l2_async_unregister_subdev (sd);ov7740_free_controls (ov7740);
drivers/media/i2c/tvp514x.c +0 -4
@@ -1131,9 +1131,7 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id) done:if (ret <0 ) {v4l2_ctrl_handler_free (&decoder->hdl); -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&decoder->sd.entity); -#endif }return ret; }
@@ -1151,9 +1149,7 @@ static int tvp514x_remove(struct i2c_client *client)struct tvp514x_decoder *decoder =to_decoder (sd);v4l2_async_unregister_subdev (&decoder->sd); -#if defined(CONFIG_MEDIA_CONTROLLER )media_entity_cleanup (&decoder->sd.entity); -#endif v4l2_ctrl_handler_free (&decoder->hdl);return 0 ; }
include/media/media-entity.h +5 -1
@@ -634,7 +634,11 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,* This function must be called during the cleanup phase after unregistering * the entity (currently, it does nothing). */ -static inline void media_entity_cleanup (struct media_entity *entity) {}; +#if IS_ENABLED (CONFIG_MEDIA_CONTROLLER ) +static inline void media_entity_cleanup (struct media_entity *entity) {} +#else +#define media_entity_cleanup (entity) do { } while (false) +#endif /** * media_create_pad_link() - creates a link between two entities.
Signature · 1 line
2.11.0
Quoted 8 lines · Sakari Ailus
Add nop variant of
media_entity_cleanup. This allows callingmedia_entity_cleanupwhether or not Media controller is enabled, simplifying driver code.Also drop #ifdefs on a few drivers around
media_entity_cleanup()and drop the extra semicolon frommedia_entity_cleanupprototype.Signed-off-by Sakari Ailus <[email protected]>
Quoted 8 lines
---
Hi Arnd,I thought about doing something similar with
media_entity_pads_initwhich is equally commonly used in drivers that support MC/non-MC cases. The trouble with that is that the drivers set up the struct first before callingmedia_entity_pads_init, requiring the #ifdefs in any case. So the benefit would be questionable at least. So justmedia_entity_cleanupthis time.
Looks good overall, just two thoughts:
Quoted 5 lines
include/media/media-entity.h +0
-0
include/media/media-entity.h int media_entity_pads_init(struct media_entity *entity, u16 num_pads, · line 641
Quoted 9 lines
include/media/media-entity.h +5
-1@@ -634,7 +634,11 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,* This function must be called during the cleanup phase after unregistering * the entity (currently, it does nothing). */ -static inline void media_entity_cleanup (struct media_entity *entity) {}; +#if IS_ENABLED (CONFIG_MEDIA_CONTROLLER ) +static inline void media_entity_cleanup (struct media_entity *entity) {} +#else +#define media_entity_cleanup (entity) do { } while (false) +#endif
This might cause a harmless warning about an unused variable in case we have a driver that does:
void f(struct i2c_client *client)
{
struct v4l2_subdev *sd = to_subdev(client);
media_entity_cleanup(sd);
}None of the drivers you changed would have an unused variable after your change (otherwise they would already have it before your change), so it's probably fine.
and second, I'm trying the patch below on top of yours now, will see how far that gets us ;-)
drivers/media/i2c/Kconfig +6 -7
@@ -310,14 +310,14 @@ config VIDEO_ML86V7667 config VIDEO_AD5820 tristate "AD5820 lens voice coil support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 ---help--- This is a driver for the AD5820 camera lens voice coil. It is used for example in Nokia N900 (RX-51). config VIDEO_DW9714 tristate "DW9714 lens voice coil support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on VIDEO_V4L2_SUBDEV_API ---help--- This is a driver for the DW9714 camera lens voice coil.
@@ -636,7 +636,6 @@ config VIDEO_OV5670 tristate "OmniVision OV5670 sensor support" depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API depends on MEDIA_CAMERA_SUPPORT - depends on MEDIA_CONTROLLER select V4L2_FWNODE ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision
@@ -667,7 +666,7 @@ config VIDEO_OV7670 config VIDEO_OV7740 tristate "OmniVision OV7740 sensor support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision
@@ -815,7 +814,7 @@ comment "Flash devices" config VIDEO_ADP1653 tristate "ADP1653 flash support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT ---help--- This is a driver for the ADP1653 flash controller. It is used for
@@ -823,7 +822,7 @@ config VIDEO_ADP1653 config VIDEO_LM3560 tristate "LM3560 dual flash driver support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT select REGMAP_I2C ---help---
@@ -832,7 +831,7 @@ config VIDEO_LM3560 config VIDEO_LM3646 tristate "LM3646 dual flash driver support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT select REGMAP_I2C ---help---
Arnd
Sakari Ailus
maintainerHi Arnd,
Quoted 39 lines · Arnd Bergmann
Quoted 8 lines · Sakari Ailus
Add nop variant of
media_entity_cleanup. This allows callingmedia_entity_cleanupwhether or not Media controller is enabled, simplifying driver code.Also drop #ifdefs on a few drivers around
media_entity_cleanup()and drop the extra semicolon frommedia_entity_cleanupprototype.Signed-off-by Sakari Ailus <[email protected]>Quoted 8 lines
---
Hi Arnd,I thought about doing something similar with
media_entity_pads_initwhich is equally commonly used in drivers that support MC/non-MC cases. The trouble with that is that the drivers set up the struct first before callingmedia_entity_pads_init, requiring the #ifdefs in any case. So the benefit would be questionable at least. So justmedia_entity_cleanupthis time.Looks good overall, just two thoughts:
Quoted 5 lines
include/media/media-entity.h +0
-0include/media/media-entity.h int media_entity_pads_init(struct media_entity *entity, u16 num_pads, · line 641
Quoted 9 lines
include/media/media-entity.h +5
-1@@ -634,7 +634,11 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,* This function must be called during the cleanup phase after unregistering * the entity (currently, it does nothing). */ -static inline void media_entity_cleanup (struct media_entity *entity) {}; +#if IS_ENABLED (CONFIG_MEDIA_CONTROLLER ) +static inline void media_entity_cleanup (struct media_entity *entity) {} +#else +#define media_entity_cleanup (entity) do { } while (false) +#endif This might cause a harmless warning about an unused variable in case we have a driver that does:
Quoted 4 lines
void
f(struct i2c_client *client){ struct v4l2_subdev *sd = to_subdev(client); media_entity_cleanup(sd);
That'd be:
media_entity_cleanup(&sd->entity);
Quoted 5 lines
}
None of the drivers you changed would have an unused variable after your change (otherwise they would already have it before your change), so it's probably fine.
I thought of that, too. There are drivers that define the entity (as in struct v4l2_subdev) only if CONFIG_MEDIA_CONTROLLER is enabled. As the entity field isn't there, this won't compile; that's actually why I turned it into a macro. This should be actually mentioned in the commit message.
I guess that could be changed, too, but the purpose, I believe, is to avoid wasting memory on things that aren't there. I didn't see compiler warnings from those drivers by disabling MC either, so presume that should be a change for better...
Quoted 12 lines
and second, I'm trying the patch below on top of yours now, will see how far that gets us ;-)
drivers/media/i2c/Kconfig +0
-0@@ -310,14 +310,14 @@ config VIDEO_ML86V7667 config VIDEO_AD5820 tristate "AD5820 lens voice coil support"
drivers/media/i2c/Kconfig config VIDEO_ML86V7667 · line 320
Quoted 10 lines
drivers/media/i2c/Kconfig +2
-2- depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 ---help--- This is a driver for the AD5820 camera lens voice coil. It is used for example in Nokia N900 (RX-51). config VIDEO_DW9714 tristate "DW9714 lens voice coil support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2
Both drivers call media_entity_pads_init() unconditionally.
drivers/media/i2c/Kconfig config VIDEO_OV5670 · line 639
Quoted 8 lines
drivers/media/i2c/Kconfig +0
-1depends on VIDEO_V4L2_SUBDEV_API ---help--- This is a driver for the DW9714 camera lens voice coil.@@ -636,7 +636,6 @@ config VIDEO_OV5670 tristate "OmniVision OV5670 sensor support" depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API depends on MEDIA_CAMERA_SUPPORT - depends on MEDIA_CONTROLLER
ov5670 does depend on MC at least right now. I guess it might not take much to make it optional. But it's more than this patch. :-)
drivers/media/i2c/Kconfig config VIDEO_OV7670 · line 669
Quoted 9 lines
drivers/media/i2c/Kconfig +1
-1select V4L2_FWNODE ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision@@ -667,7 +666,7 @@ config VIDEO_OV7670 config VIDEO_OV7740 tristate "OmniVision OV7740 sensor support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2
Hmm. In here the ov7740 driver doesn't seem to depend on MC.
Quoted 22 lines
drivers/media/i2c/Kconfig +2
-2depends on MEDIA_CAMERA_SUPPORT ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision@@ -815,7 +814,7 @@ comment "Flash devices" config VIDEO_ADP1653 tristate "ADP1653 flash support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT ---help--- This is a driver for the ADP1653 flash controller. It is used for@@ -823,7 +822,7 @@ config VIDEO_ADP1653 config VIDEO_LM3560 tristate "LM3560 dual flash driver support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT select REGMAP_I2C ---help---
drivers/media/i2c/Kconfig config VIDEO_LM3560 · line 837
Quoted 8 lines
drivers/media/i2c/Kconfig +1
-1@@ -832,7 +831,7 @@ config VIDEO_LM3560 config VIDEO_LM3646 tristate "LM3646 dual flash driver support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT select REGMAP_I2C ---help---
These also call media_entity_pads_init() unconditionally.
How was this tested? :-)
Signature · 4 lines
Regards, Sakari Ailus [email protected]
Quoted 17 lines · Sakari Ailus
Review config VIDEO_OV5670 · line 639
Quoted 8 lines
depends on
VIDEO_V4L2_SUBDEV_API
---help---
This is a driver for the DW9714 camera lens voice coil.(quoted diff) +0
-1@@ -636,7 +636,6 @@ config VIDEO_OV5670 tristate "OmniVision OV5670 sensor support" depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API depends on MEDIA_CAMERA_SUPPORT - depends on MEDIA_CONTROLLERov5670 does depend on MC at least right now. I guess it might not take much to make it optional. But it's more than this patch. :-)
Quoted 5 lines
(quoted diff) +0
-0select V4L2_FWNODE ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision@@ -667,7 +666,7 @@ config VIDEO_OV7670
Quoted 6 lines
Review config VIDEO_OV7670 · line 669
Quoted 4 lines
(quoted diff) +1
-1config VIDEO_OV7740 tristate "OmniVision OV7740 sensor support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2Hmm. In here the ov7740 driver doesn't seem to depend on MC.
Right, this was on top of the earlier patch I sent that you rejected ;-)
Quoted 14 lines
Quoted 14 lines
(quoted diff) +1
-1depends on MEDIA_CAMERA_SUPPORT ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision@@ -815,7 +814,7 @@ comment "Flash devices" config VIDEO_ADP1653 tristate "ADP1653 flash support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT ---help--- This is a driver for the ADP1653 flash controller. It is used for@@ -823,7 +822,7 @@ config VIDEO_ADP1653
Quoted 7 lines
Review config VIDEO_ADP1653 · line 828
Quoted 7 lines
(quoted diff) +1
-1config VIDEO_LM3560 tristate "LM3560 dual flash driver support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT select REGMAP_I2C ---help---
Those two also failed to build
Quoted 12 lines
Review config VIDEO_LM3560 · line 837
Quoted 9 lines
(quoted diff) +1
-1@@ -832,7 +831,7 @@ config VIDEO_LM3560 config VIDEO_LM3646 tristate "LM3646 dual flash driver support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT select REGMAP_I2C ---help---These also call
media_entity_pads_init()unconditionally.
Quoted 1 line
How was this tested? :-)
Not before I sent it, what I meant is that I'd give it a try, blindly applying the patch to my randconfig build tree to see what breaks.
The result after a day worth of randconfig builds is this one, which basically matches what you concluded already:
drivers/media/i2c/Kconfig +3 -4
@@ -310,14 +310,14 @@ config VIDEO_ML86V7667 config VIDEO_AD5820 tristate "AD5820 lens voice coil support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 ---help--- This is a driver for the AD5820 camera lens voice coil. It is used for example in Nokia N900 (RX-51). config VIDEO_DW9714 tristate "DW9714 lens voice coil support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on VIDEO_V4L2_SUBDEV_API ---help--- This is a driver for the DW9714 camera lens voice coil.
@@ -636,7 +636,6 @@ config VIDEO_OV5670 tristate "OmniVision OV5670 sensor support" depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API depends on MEDIA_CAMERA_SUPPORT - depends on MEDIA_CONTROLLER select V4L2_FWNODE ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision
@@ -667,7 +666,7 @@ config VIDEO_OV7670 config VIDEO_OV7740 tristate "OmniVision OV7740 sensor support" - depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision
include/media/media-entity.h +0 -0
@@ -636,6 +636,11 @@ int media_entity_pads_init(struct media_entity
*entity, u16 num_pads,
*/
static inline void media_entity_cleanup(struct media_entity *entity) {};
+#ifndef CONFIG_MEDIA_CONTROLLER
+#define media_entity_pads_init(e, n, p) 0
+#define media_entity_cleanup(e) do { } while (0) +#endif
+
/**
* media_create_pad_link() - creates a link between two entities. *
I'll just drop that patch then from my build tree.
Arnd