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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Tomi Valkeinen <tomi.valkeinen+renesas@xxxxxxxxxxxxxxxx>

Add cleanup macros for active state. These can be used to call
v4l2_subdev_lock_and_get_active_state() and manage the unlocking either
in unscoped or scoped fashion:

This locks the state, gets it to the 'state' variable, and unlocks when
exiting the surrounding scope:

CLASS(v4l2_subdev_lock_and_get_active_state, state)(subdev);

This does the same, but inside the given scope:

scoped_v4l2_subdev_lock_and_get_active_state(subdev) {
}

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@xxxxxxxxxxxxxxxx>
---
 include/media/v4l2-subdev.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index bd235d325ff9..699007cfffd7 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -8,6 +8,7 @@
 #ifndef _V4L2_SUBDEV_H
 #define _V4L2_SUBDEV_H
 
+#include <linux/cleanup.h>
 #include <linux/types.h>
 #include <linux/v4l2-subdev.h>
 #include <media/media-entity.h>
@@ -1854,6 +1855,15 @@ v4l2_subdev_lock_and_get_active_state(struct v4l2_subdev *sd)
 	return sd->active_state;
 }
 
+DEFINE_CLASS(v4l2_subdev_lock_and_get_active_state, struct v4l2_subdev_state *,
+	     v4l2_subdev_unlock_state(_T),
+	     v4l2_subdev_lock_and_get_active_state(sd), struct v4l2_subdev *sd);
+
+#define scoped_v4l2_subdev_lock_and_get_active_state(sd)              \
+	for (CLASS(v4l2_subdev_lock_and_get_active_state, state)(sd), \
+	     *done = NULL;                                            \
+	     !done; done = (void *)1)
+
 /**
  * v4l2_subdev_init - initializes the sub-device struct
  *

-- 
2.43.0





[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux