public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC 1/1] v4l2-subdev: Rework subdev format and selection macros to work without MC
@ 2019-06-04 17:57 Sakari Ailus
  2019-06-05 19:33 ` Janusz Krzysztofik
  0 siblings, 1 reply; 6+ messages in thread
From: Sakari Ailus @ 2019-06-04 17:57 UTC (permalink / raw)
  To: linux-media; +Cc: Janusz Krzysztofik, hverkuil, m.felsch

Rework the macros for accessing subdev try formats to work meaningfully
and relatively safely without V4L2 sub-device uAPI (and without MC). This
is done by simply reverting to accessing the pad number zero if
CONFIG_VIDEO_V4L2_SUBDEV_API isn't enabled, and emitting a kernel warning
if the pad is non-zero in that case.

The functions are seen useful if subdev uAPI is disabled for drivers that
can work without the Kconfig option but benefit from the option if it's
enabled.

As a by-product, the patch simplifies individual inline functions by
removing two lines of code from each of them and moving the functionality
to a common macro.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
Hi guys,

This might not be pretty but should provide some comfort for drivers
working with different Kconfig options. Comments are welcome...

 include/media/v4l2-subdev.h | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index e1e3c18c3fd6..3328f302326b 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -930,6 +930,17 @@ struct v4l2_subdev_fh {
 	container_of(fh, struct v4l2_subdev_fh, vfh)
 
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
+#define __v4l2_subdev_get_try_field(__sd, __cfg, __pad, __field)	\
+	(WARN_ON(!(__cfg)) ? NULL :		\
+	 ((__sd)->entity.graph_obj.mdev ?				\
+	  (WARN_ON((__pad) >= (__sd)->entity.num_pads) ?		\
+	   NULL : &(__cfg)[__pad].__field) :				\
+	  &(__cfg)[WARN_ON(__pad) && 0].__field))
+#else /* CONFIG_VIDEO_V4L2_SUBDEV_API */
+#define __v4l2_subdev_get_try_field(__sd, __cfg, __pad, __field)	\
+	(WARN_ON(!(__cfg)) ? NULL :					\
+	 &(__cfg)[WARN_ON(__pad) && 0].__field)
+#endif /* !CONFIG_VIDEO_V4L2_SUBDEV_API */
 
 /**
  * v4l2_subdev_get_try_format - ancillary routine to call
@@ -944,9 +955,7 @@ static inline struct v4l2_mbus_framefmt
 			    struct v4l2_subdev_pad_config *cfg,
 			    unsigned int pad)
 {
-	if (WARN_ON(pad >= sd->entity.num_pads))
-		pad = 0;
-	return &cfg[pad].try_fmt;
+	return __v4l2_subdev_get_try_field(sd, cfg, pad, try_fmt);
 }
 
 /**
@@ -962,9 +971,7 @@ static inline struct v4l2_rect
 			  struct v4l2_subdev_pad_config *cfg,
 			  unsigned int pad)
 {
-	if (WARN_ON(pad >= sd->entity.num_pads))
-		pad = 0;
-	return &cfg[pad].try_crop;
+	return __v4l2_subdev_get_try_field(sd, cfg, pad, try_crop);
 }
 
 /**
@@ -980,11 +987,8 @@ static inline struct v4l2_rect
 			     struct v4l2_subdev_pad_config *cfg,
 			     unsigned int pad)
 {
-	if (WARN_ON(pad >= sd->entity.num_pads))
-		pad = 0;
-	return &cfg[pad].try_compose;
+	return __v4l2_subdev_get_try_field(sd, cfg, pad, try_compose);
 }
-#endif
 
 extern const struct v4l2_file_operations v4l2_subdev_fops;
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-10 17:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-04 17:57 [RFC 1/1] v4l2-subdev: Rework subdev format and selection macros to work without MC Sakari Ailus
2019-06-05 19:33 ` Janusz Krzysztofik
2019-06-06 13:56   ` Sakari Ailus
2019-06-06 18:13     ` Janusz Krzysztofik
2019-06-10  8:54       ` Sakari Ailus
2019-06-10 17:49         ` Janusz Krzysztofik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox