[PATCH 0/4] media: v4l2-subdev: Add cleanup macros for active state

Tomi Valkeinen
2024-09-17T14:10:08Z

Add cleanup macros for the subdev active state. While we could add more
macros to handle state locking in different situations, I believe the
two macros introduced here are the ones most often needed.

A few drivers are changed to use the macros, as an example.

A few thoughts:

The scoped_v4l2_subdev_lock_and_get_active_state() macro will define an
implicitly named 'state' variable inside the scope. This is a bit
similar to scoped_guard(), which defined an implicitly named 'scope'
variable. However, adding the name of the variable as a parameter to the
macro is an easy addition, if needed. Then the usage would be:

scoped_v4l2_subdev_lock_and_get_active_state(subdev, state) {
}

Using the CLASS() version does take the name of the variable. The two
macros also look quite different, so I wonder if we should make a helper
macro to hide the CLASS() usage (I don't know what to call it...):

#define init_v4l2_subdev_lock_and_get_active_state(sd) \
CLASS(v4l2_subdev_lock_and_get_active_state, state)(sd)

The macro names are quite long, but so is the function name of
'v4l2_subdev_lock_and_get_active_state', which these macros often
replace.

Tomi

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
---
Tomi Valkeinen (4):
media: v4l2-subdev: Add cleanup macros for active state
media: v4l2-subdev: Use state cleanup macros
media: renesas: Use state cleanup macros
media: i2c: ds90ub9xx: Use state cleanup macros

drivers/media/i2c/ds90ub913.c | 11 +++------
drivers/media/i2c/ds90ub953.c | 11 +++------
drivers/media/i2c/ds90ub960.c | 27 +++++++---------------
drivers/media/platform/renesas/rcar-csi2.c | 14 ++++-------
.../media/platform/renesas/rzg2l-cru/rzg2l-csi2.c | 9 ++++----
.../media/platform/renesas/rzg2l-cru/rzg2l-ip.c | 9 ++------
drivers/media/v4l2-core/v4l2-subdev.c | 14 +++--------
include/media/v4l2-subdev.h | 10 ++++++++
8 files changed, 37 insertions(+), 68 deletions(-)
---
base-commit: 98f7e32f20d28ec452afb208f9cffc08448a2652
change-id: 20240917-scoped-state-a995cc0dba33

Best regards,
--
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>