linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Linux Doc Mailing List <linux-doc@vger.kernel.org>
Subject: Re: [PATCH 15/24] media: v4l2-subdev: get rid of __V4L2_SUBDEV_MK_GET_TRY() macro
Date: Mon, 18 Dec 2017 17:27:04 -0200	[thread overview]
Message-ID: <20171218172704.57d250d0@vento.lan> (raw)
In-Reply-To: <20171009202355.ckhaf5xcba5z4tvh@valkosipuli.retiisi.org.uk>

Em Mon, 9 Oct 2017 23:23:56 +0300
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Mon, Oct 09, 2017 at 07:19:21AM -0300, Mauro Carvalho Chehab wrote:
> > 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.
> 
> BUG_ON() might actually be a better idea as this will lead to memory
> corruption. I presume it's not been hit often.

Well, let's then change the code to:

        if (WARN_ON(pad >= sd->entity.num_pads)) 
                return -EINVAL;

This way, it won't try to use an invalid value. As those are default
handlers for ioctls, userspace should be able to handle it.

> 
> That said, I, too, favour WARN_ON() in this case. In case pad exceeds the
> number of pads, then zero could be used, for instance. The only real
> problem comes if there were no pads to begin with. The callers of these
> functions also don't expect to receive NULL. Another option would be to
> define a static, dummy variable for the purpose that would be at least safe
> to access. Or we could just use the dummy entry whenever the pad isn't
> valid.
> 
> This will make the functions more complex and I might just keep the
> original macro. Even grep works on it nowadays.
> 
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
> > ---
> >  include/media/v4l2-subdev.h | 37 +++++++++++++++++++++++++------------
> >  1 file changed, 25 insertions(+), 12 deletions(-)
> > 
> > diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> > index 1f34045f07ce..35c4476c56ee 100644
> > --- a/include/media/v4l2-subdev.h
> > +++ b/include/media/v4l2-subdev.h
> > @@ -897,19 +897,32 @@ 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)
> > +{
> > +	WARN_ON(pad >= sd->entity.num_pads);
> > +	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)
> > +{
> > +	WARN_ON(pad >= sd->entity.num_pads);
> > +	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)
> > +{
> > +	WARN_ON(pad >= sd->entity.num_pads);
> > +	return &cfg[pad].try_compose;
> > +}
> >  #endif
> >  
> >  extern const struct v4l2_file_operations v4l2_subdev_fops;
> 



Thanks,
Mauro

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

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09 10:19 [PATCH 00/24] V4L2 kAPI cleanups and documentation improvements part 2 Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 01/24] media: v4l2-dev.h: add kernel-doc to two macros Mauro Carvalho Chehab
2017-10-09 11:14   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 02/24] media: v4l2-flash-led-class.h: add kernel-doc to two ancillary funcs Mauro Carvalho Chehab
2017-10-09 11:15   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 03/24] media: v4l2-mediabus: use BIT() macro for flags Mauro Carvalho Chehab
2017-10-09 11:16   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 04/24] media: v4l2-mediabus: convert flags to enums and document them Mauro Carvalho Chehab
2017-10-09 10:56   ` Hans Verkuil
2017-10-11 21:26   ` Pavel Machek
2017-12-18 18:43     ` Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 05/24] media: v4l2-dev: convert VFL_TYPE_* into an enum Mauro Carvalho Chehab
2017-10-09 10:59   ` Hans Verkuil
2017-10-09 13:38   ` Mike Isely
2017-10-10 20:47   ` Andrey Utkin
2017-12-18 16:48     ` Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 06/24] media: i2c-addr.h: get rid of now unused defines Mauro Carvalho Chehab
2017-10-09 10:59   ` Hans Verkuil
2017-10-09 10:19 ` [PATCH 07/24] media: get rid of i2c-addr.h Mauro Carvalho Chehab
2017-10-09 11:00   ` Hans Verkuil
2017-10-09 10:19 ` [PATCH 08/24] media: v4l2-dev: document VFL_DIR_* direction defines Mauro Carvalho Chehab
2017-10-09 11:00   ` Hans Verkuil
2017-10-09 10:19 ` [PATCH 09/24] media: v4l2-dev: document video_device flags Mauro Carvalho Chehab
2017-10-09 11:02   ` Hans Verkuil
2017-10-09 10:19 ` [PATCH 10/24] media: v4l2-subdev: use kernel-doc markups to document subdev flags Mauro Carvalho Chehab
2017-10-09 20:24   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 11/24] media: v4l2-subdev: create cross-references for ioctls Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 12/24] media: v4l2-subdev: fix description of tuner.s_radio ops Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 13/24] media: v4l2-subdev: better document IO pin configuration flags Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 14/24] media: v4l2-subdev: convert frame description to enum Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 15/24] media: v4l2-subdev: get rid of __V4L2_SUBDEV_MK_GET_TRY() macro Mauro Carvalho Chehab
2017-10-09 20:23   ` Sakari Ailus
2017-12-18 19:27     ` Mauro Carvalho Chehab [this message]
2017-12-19  8:24       ` Sakari Ailus
2017-12-19 11:03         ` Mauro Carvalho Chehab
2017-12-19 11:56           ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 16/24] media: v4l2-subdev: document remaining undocumented functions Mauro Carvalho Chehab
2017-10-09 20:45   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 17/24] media: v4l2-subdev: fix a typo Mauro Carvalho Chehab
2017-10-09 20:26   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 18/24] media: vb2-core: use bitops for bits Mauro Carvalho Chehab
2017-10-10 14:01   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 19/24] media: vb2-core: Improve kernel-doc markups Mauro Carvalho Chehab
2017-10-10 13:32   ` Sakari Ailus
2017-12-18 17:20     ` Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 20/24] media: vb2-core: document remaining functions Mauro Carvalho Chehab
2017-10-09 10:19 ` [PATCH 21/24] media: vb2-core: fix descriptions for VB2-only functions Mauro Carvalho Chehab
2017-10-10 13:49   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 22/24] media: vb2: add cross references at memops and v4l2 kernel-doc markups Mauro Carvalho Chehab
2017-10-10 13:51   ` Sakari Ailus
2017-10-09 10:19 ` [PATCH 23/24] media: v4l2-tpg*.h: move headers to include/media/tpg and merge them Mauro Carvalho Chehab
2017-10-09 10:28   ` Hans Verkuil
2017-10-09 10:19 ` [PATCH 24/24] media: v4l2-tpg.h: rename color structs Mauro Carvalho Chehab
2017-10-09 10:29   ` Hans Verkuil
2017-10-09 12:35 ` [PATCH 00/24] V4L2 kAPI cleanups and documentation improvements part 2 Mauro Carvalho Chehab
2017-12-18 17:30 ` 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=20171218172704.57d250d0@vento.lan \
    --to=mchehab@s-opensource.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=sakari.ailus@iki.fi \
    /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;
as well as URLs for NNTP newsgroup(s).