mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <jmkrzyszt@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Janusz Krzysztofik <jmkrzyszt@gmail.com>
Subject: [PATCH v4 2/2] media: v4l2-subdev: Verify pad config argument
Date: Sat, 11 May 2019 12:10:31 +0200	[thread overview]
Message-ID: <20190511101031.4777-3-jmkrzyszt@gmail.com> (raw)
In-Reply-To: <20190511101031.4777-1-jmkrzyszt@gmail.com>

Extend parameter checks performed by v4l2_subdev_call() with a check for
a non-NULL pad config pointer if V4L2_SUBDEV_FORMAT_TRY format type is
requested so drivers don't need to care.

Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
---
 drivers/media/v4l2-core/v4l2-subdev.c | 30 +++++++++++++++++++--------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index cd50fcb86c47..4540d8abff5f 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -126,6 +126,11 @@ static inline int check_which(__u32 which)
 	       which != V4L2_SUBDEV_FORMAT_ACTIVE ? -EINVAL : 0;
 }
 
+static inline int check_cfg(__u32 which, struct v4l2_subdev_pad_config *cfg)
+{
+	return which == V4L2_SUBDEV_FORMAT_TRY && !cfg ? -EINVAL : 0;
+}
+
 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
 static inline int check_pad(struct v4l2_subdev *sd, __u32 pad)
 {
@@ -136,16 +141,18 @@ static inline int check_pad(struct v4l2_subdev *sd, __u32 pad)
 #endif
 
 static int check_format(struct v4l2_subdev *sd,
+			struct v4l2_subdev_pad_config *cfg,
 			struct v4l2_subdev_format *format)
 {
-	return check_which(format->which) ? : check_pad(sd, format->pad);
+	return check_which(format->which) ? :
+	       check_cfg(format->which, cfg) ? : check_pad(sd, format->pad);
 }
 
 static int check_get_fmt(struct v4l2_subdev *sd,
 			 struct v4l2_subdev_pad_config *cfg,
 			 struct v4l2_subdev_format *format)
 {
-	return check_format(sd, format) ? :
+	return check_format(sd, cfg, format) ? :
 	       sd->ops->pad->get_fmt(sd, cfg, format);
 }
 
@@ -153,7 +160,7 @@ static int check_set_fmt(struct v4l2_subdev *sd,
 			 struct v4l2_subdev_pad_config *cfg,
 			 struct v4l2_subdev_format *format)
 {
-	return check_format(sd, format) ? :
+	return check_format(sd, cfg, format) ? :
 	       sd->ops->pad->set_fmt(sd, cfg, format);
 }
 
@@ -161,7 +168,8 @@ static int check_enum_mbus_code(struct v4l2_subdev *sd,
 				struct v4l2_subdev_pad_config *cfg,
 				struct v4l2_subdev_mbus_code_enum *code)
 {
-	return check_which(code->which) ? : check_pad(sd, code->pad) ? :
+	return check_which(code->which) ? : check_cfg(code->which, cfg) ? :
+	       check_pad(sd, code->pad) ? :
 	       sd->ops->pad->enum_mbus_code(sd, cfg, code);
 }
 
@@ -169,7 +177,8 @@ static int check_enum_frame_size(struct v4l2_subdev *sd,
 				 struct v4l2_subdev_pad_config *cfg,
 				 struct v4l2_subdev_frame_size_enum *fse)
 {
-	return check_which(fse->which) ? : check_pad(sd, fse->pad) ? :
+	return check_which(fse->which) ? : check_cfg(fse->which, cfg) ? :
+	       check_pad(sd, fse->pad) ? :
 	       sd->ops->pad->enum_frame_size(sd, cfg, fse);
 }
 
@@ -197,21 +206,24 @@ static int check_enum_frame_interval(struct v4l2_subdev *sd,
 				struct v4l2_subdev_pad_config *cfg,
 				struct v4l2_subdev_frame_interval_enum *fie)
 {
-	return check_which(fie->which) ? : check_pad(sd, fie->pad) ? :
+	return check_which(fie->which) ? : check_cfg(fie->which, cfg) ? :
+	       check_pad(sd, fie->pad) ? :
 	       sd->ops->pad->enum_frame_interval(sd, cfg, fie);
 }
 
 static int check_selection(struct v4l2_subdev *sd,
+			   struct v4l2_subdev_pad_config *cfg,
 			   struct v4l2_subdev_selection *sel)
 {
-	return check_which(sel->which) ? : check_pad(sd, sel->pad);
+	return check_which(sel->which) ? : check_cfg(sel->which, cfg) ? :
+	       check_pad(sd, sel->pad);
 }
 
 static int check_get_selection(struct v4l2_subdev *sd,
 			       struct v4l2_subdev_pad_config *cfg,
 			       struct v4l2_subdev_selection *sel)
 {
-	return check_selection(sd, sel) ? :
+	return check_selection(sd, cfg, sel) ? :
 	       sd->ops->pad->get_selection(sd, cfg, sel);
 }
 
@@ -219,7 +231,7 @@ static int check_set_selection(struct v4l2_subdev *sd,
 			       struct v4l2_subdev_pad_config *cfg,
 			       struct v4l2_subdev_selection *sel)
 {
-	return check_selection(sd, sel) ? :
+	return check_selection(sd, cfg, sel) ? :
 	       sd->ops->pad->set_selection(sd, cfg, sel);
 }
 
-- 
2.21.0


      parent reply	other threads:[~2019-05-11 10:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-11 10:10 [PATCH v4 0/2] media: v4l2-subdev: Verify arguments of v4l2_subdev_call() Janusz Krzysztofik
2019-05-11 10:10 ` [PATCH v4 1/2] " Janusz Krzysztofik
2019-05-14 11:10   ` Sakari Ailus
2019-05-14 11:12   ` Sakari Ailus
2019-05-11 10:10 ` Janusz Krzysztofik [this message]

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=20190511101031.4777-3-jmkrzyszt@gmail.com \
    --to=jmkrzyszt@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®