All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Linux Media Mailing List <linux-media@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@s-opensource.com>,
	Mauro Carvalho Chehab <mchehab@infradead.org>
Subject: [PATCH 6/8] media: v4l2-subdev: get rid of __V4L2_SUBDEV_MK_GET_TRY() macro
Date: Mon, 18 Dec 2017 17:54:00 -0200	[thread overview]
Message-ID: <ed3f0ddfee43001fb9c538329b9cb13738f05fff.1513625884.git.mchehab@s-opensource.com> (raw)
In-Reply-To: <cover.1513625884.git.mchehab@s-opensource.com>
In-Reply-To: <cover.1513625884.git.mchehab@s-opensource.com>

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
---
 include/media/v4l2-subdev.h | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 71b8ff4b2e0e..1c280cf7dd41 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -896,19 +896,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))
+		return -EINVAL;
+	return &cfg[pad].try_fmt;
+}
 
-__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_crop(struct v4l2_subdev *sd,
+			  struct v4l2_subdev_pad_config *cfg,
+			  unsigned int pad)
+{
+	if (WARN_ON(pad >= sd->entity.num_pads))
+		return -EINVAL;
+	return &cfg[pad].try_crop;
+}
+
+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))
+		return -EINVAL;
+	return &cfg[pad].try_compose;
+}
 #endif
 
 extern const struct v4l2_file_operations v4l2_subdev_fops;
-- 
2.14.3

  parent reply	other threads:[~2017-12-18 19:54 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18 19:53 [PATCH 0/8] Some V4L2 documentation pending patches Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 1/8] media: v4l2-device.h: document helper macros Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 2/8] media: v4l2-ioctl.h: convert debug into an enum of bits Mauro Carvalho Chehab
2017-12-19 11:39   ` Sakari Ailus
2017-12-19 14:02     ` Laurent Pinchart
2017-12-19 14:05       ` Laurent Pinchart
2017-12-19 15:34         ` Mauro Carvalho Chehab
2017-12-20 10:47           ` Laurent Pinchart
2017-12-20 13:34             ` Mauro Carvalho Chehab
2017-12-19 14:12       ` Sakari Ailus
2017-12-19 15:37         ` Mauro Carvalho Chehab
2017-12-19 17:17           ` Laurent Pinchart
2017-12-19 19:20             ` Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 3/8] media: v4l2-async: simplify v4l2_async_subdev structure Mauro Carvalho Chehab
2017-12-18 19:53   ` Mauro Carvalho Chehab
2017-12-18 19:53   ` Mauro Carvalho Chehab
2017-12-18 20:01   ` Benoit Parrot
2017-12-18 20:01     ` Benoit Parrot
2017-12-18 20:01     ` Benoit Parrot
2017-12-18 22:27   ` Alexandre Belloni
2017-12-18 22:27     ` Alexandre Belloni
2017-12-18 22:27     ` Alexandre Belloni
2017-12-19  8:27   ` Sakari Ailus
2017-12-19  8:27     ` Sakari Ailus
2017-12-19  8:27     ` Sakari Ailus
2017-12-19  9:16   ` Philipp Zabel
2017-12-19  9:16     ` Philipp Zabel
2017-12-19  9:16     ` Philipp Zabel
2017-12-18 19:53 ` [PATCH 4/8] media: v4l2-async: better describe match union at async match struct Mauro Carvalho Chehab
2017-12-18 19:53 ` [PATCH 5/8] media: v4l2-mediabus: convert flags to enums and document them Mauro Carvalho Chehab
2017-12-19  9:30   ` Philipp Zabel
2017-12-19 11:11     ` Mauro Carvalho Chehab
2017-12-18 19:54 ` Mauro Carvalho Chehab [this message]
2017-12-18 19:54 ` [PATCH 7/8] media: v4l2-subdev: document remaining undocumented functions Mauro Carvalho Chehab
2017-12-18 19:54 ` [PATCH 8/8] media: v4l2-subdev: use kernel-doc markups to document subdev flags Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed3f0ddfee43001fb9c538329b9cb13738f05fff.1513625884.git.mchehab@s-opensource.com \
    --to=mchehab@s-opensource.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.