From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Kieran Bingham <kbingham@kernel.org>,
niklas.soderlund@ragnatech.se, geert@glider.be,
linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Subject: Re: [PATCH v3.1 1/2] v4l: subdev: tolerate null in media_entity_to_v4l2_subdev
Date: Thu, 18 May 2017 23:54:46 +0300 [thread overview]
Message-ID: <1676271.nErFi1MvTr@avalon> (raw)
In-Reply-To: <20170518205033.GW3227@valkosipuli.retiisi.org.uk>
Hi Sakari,
On Thursday 18 May 2017 23:50:34 Sakari Ailus wrote:
> On Thu, May 18, 2017 at 07:08:00PM +0300, Laurent Pinchart wrote:
> > On Wednesday 17 May 2017 22:20:57 Sakari Ailus wrote:
> >> On Wed, May 17, 2017 at 04:38:14PM +0100, Kieran Bingham wrote:
> >>> From: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> >>>
> >>> Return NULL, if a null entity is parsed for it's v4l2_subdev
> >>>
> >>> Signed-off-by: Kieran Bingham
> >>> <kieran.bingham+renesas@ideasonboard.com>
> >>> ---
> >>>
> >>> include/media/v4l2-subdev.h | 2 +-
> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> >>> index 5f1669c45642..72d7f28f38dc 100644
> >>> --- a/include/media/v4l2-subdev.h
> >>> +++ b/include/media/v4l2-subdev.h
> >>> @@ -829,7 +829,7 @@ struct v4l2_subdev {
> >>> };
> >>>
> >>> #define media_entity_to_v4l2_subdev(ent) \
> >>> - container_of(ent, struct v4l2_subdev, entity)
> >>> + (ent ? container_of(ent, struct v4l2_subdev, entity) : NULL)
> >>> #define vdev_to_v4l2_subdev(vdev) \
> >>> ((struct v4l2_subdev *)video_get_drvdata(vdev))
> >>
> >> The problem with this is that ent is now referenced twice. If the ent
> >> macro argument has side effect, this would introduce bugs. It's
> >> unlikely, but worth avoiding. Either use a macro or a function.
> >>
> >> I think I'd use function for there's little use for supporting for const
> >> and non-const arguments presumably. A simple static inline function
> >> should do.
> >
> > Note that, if we want to keep using a macro, this could be written as
> >
> > #define media_entity_to_v4l2_subdev(ent) ({ \
> >
> > typeof(ent) __ent = ent; \
I just realized that this should be written
typeof(ent) __ent = (ent);
> > __ent ? container_of(__ent, struct v4l2_subdev, entity) : NULL; \
> >
> > })
> >
> > Bonus point if you can come up with a way to return a const struct
> > v4l2_subdev pointer when then ent argument is const.
>
> I can't think of a use case for that. I've never seen a const struct
> v4l2_subdev anywhere. I could be just oblivious though. :-)
I agree with you, it's overkill, at least for now. Although I'd like to see
how it could be done, for other similar constructs where both const and non-
const versions are useful.
> Better give a __ent a name that someone will not accidentally come up with.
> That can lead to problems that are difficult to debug --- for the code
> compiles, it just doesn't do what's expected.
Won't it generate a compilation error as the variable would be redefined by
the macro ?
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2017-05-18 20:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-17 14:13 [PATCH v3 0/2] ADV748x HDMI/Analog video receiver Kieran Bingham
2017-05-17 14:13 ` [PATCH v3 1/2] v4l: subdev: tolerate null in media_entity_to_v4l2_subdev Kieran Bingham
2017-05-17 14:25 ` Geert Uytterhoeven
2017-05-17 14:37 ` Kieran Bingham
[not found] ` <cover.ed561929790222fc2c4467d4e57072a8e4ba69f3.1495035409.git-series.kieran.bingham+renesas@ideasonboard.com>
2017-05-17 15:38 ` [PATCH v3.1 " Kieran Bingham
2017-05-17 19:20 ` Sakari Ailus
2017-05-18 16:08 ` Laurent Pinchart
2017-05-18 20:50 ` Sakari Ailus
2017-05-18 20:54 ` Laurent Pinchart [this message]
2017-05-18 21:05 ` Sakari Ailus
2017-05-18 21:59 ` Laurent Pinchart
2017-05-18 22:38 ` Sakari Ailus
2017-05-17 14:13 ` [PATCH v3 2/2] media: i2c: adv748x: add adv748x driver Kieran Bingham
2017-05-18 21:48 ` Laurent Pinchart
2017-05-23 17:09 ` Kieran Bingham
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=1676271.nErFi1MvTr@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=geert@glider.be \
--cc=kbingham@kernel.org \
--cc=kieran.bingham+renesas@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=niklas.soderlund@ragnatech.se \
--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