media: v4l2-subdev: get rid of __V4L2_SUBDEV_MK_GET_TRY() macro
authorMauro Carvalho Chehab <mchehab@s-opensource.com>
Tue, 19 Dec 2017 11:03:55 +0000 (06:03 -0500)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Thu, 8 Mar 2018 11:06:41 +0000 (06:06 -0500)
X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com
media: v4l2-subdev: get rid of __V4L2_SUBDEV_MK_GET_TRY() macro

The __V4L2_SUBDEV_MK_GET_TRY() macro is used to define
3 functions that have the same arguments. The code of those
functions is simple enough to just declare them, de-obfuscating
the code.

While here, replace BUG_ON() by WARN_ON() as there's no reason
why to panic the Kernel if this fails.

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
include/media/v4l2-subdev.h

index 457917e9237fb76fd2b4293839d0f7ae07a892a8..c9628db3bfa2d4406f049adf1403ea8945c81b12 100644 (file)
@@ -890,19 +890,35 @@ struct v4l2_subdev_fh {
        container_of(fh, struct v4l2_subdev_fh, vfh)
 
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
-#define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name)          \
-       static inline struct rtype *                                    \
-       fun_name(struct v4l2_subdev *sd,                                \
-                struct v4l2_subdev_pad_config *cfg,                    \
-                unsigned int pad)                                      \
-       {                                                               \
-               BUG_ON(pad >= sd->entity.num_pads);                     \
-               return &cfg[pad].field_name;                            \
-       }
+static inline struct v4l2_mbus_framefmt
+*v4l2_subdev_get_try_format(struct v4l2_subdev *sd,
+                           struct v4l2_subdev_pad_config *cfg,
+                           unsigned int pad)
+{
+       if (WARN_ON(pad >= sd->entity.num_pads))
+               pad = 0;
+       return &cfg[pad].try_fmt;
+}
+
+static inline struct v4l2_rect
+*v4l2_subdev_get_try_crop(struct v4l2_subdev *sd,
+                         struct v4l2_subdev_pad_config *cfg,
+                         unsigned int pad)
+{
+       if (WARN_ON(pad >= sd->entity.num_pads))
+               pad = 0;
+       return &cfg[pad].try_crop;
+}
 
-__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, v4l2_subdev_get_try_format, try_fmt)
-__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, v4l2_subdev_get_try_crop, try_crop)
-__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, v4l2_subdev_get_try_compose, try_compose)
+static inline struct v4l2_rect
+*v4l2_subdev_get_try_compose(struct v4l2_subdev *sd,
+                            struct v4l2_subdev_pad_config *cfg,
+                            unsigned int pad)
+{
+       if (WARN_ON(pad >= sd->entity.num_pads))
+               pad = 0;
+       return &cfg[pad].try_compose;
+}
 #endif
 
 extern const struct v4l2_file_operations v4l2_subdev_fops;