From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org, Tianshu Qiu <tian.shu.qiu@intel.com>,
Bingbu Cao <bingbu.cao@intel.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Jacopo Mondi <jacopo+renesas@jmondi.org>,
Rui Miguel Silva <rmfrfs@gmail.com>,
Martin Kepplinger <martink@posteo.de>
Subject: Re: [PATCH v2 12/12] media: mc: Check pad flag validity
Date: Tue, 19 Sep 2023 10:24:32 +0000 [thread overview]
Message-ID: <ZQl24DaMGeQSTPRa@kekkonen.localdomain> (raw)
In-Reply-To: <20230918134802.GH28874@pendragon.ideasonboard.com>
Hi Laurent,
Thanks for the review.
On Mon, Sep 18, 2023 at 04:48:02PM +0300, Laurent Pinchart wrote:
> Hi Sakari,
>
> Thank you for the patch.
>
> On Mon, Sep 18, 2023 at 03:51:38PM +0300, Sakari Ailus wrote:
> > Check the validity of pad flags on entity init. Exactly one of the flags
> > must be set.
> >
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> > drivers/media/mc/mc-entity.c | 20 ++++++++++++++++++--
> > 1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> > index 83468d4a440b..38d5bbae33d7 100644
> > --- a/drivers/media/mc/mc-entity.c
> > +++ b/drivers/media/mc/mc-entity.c
> > @@ -195,8 +195,9 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
> > struct media_pad *pads)
> > {
> > struct media_device *mdev = entity->graph_obj.mdev;
> > - struct media_pad *iter;
> > + struct media_pad *iter, *iter2;
> > unsigned int i = 0;
> > + int ret = 0;
> >
> > if (num_pads >= MEDIA_ENTITY_MAX_PADS)
> > return -E2BIG;
> > @@ -210,15 +211,30 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
> > media_entity_for_each_pad(entity, iter) {
> > iter->entity = entity;
> > iter->index = i++;
> > +
> > + if (hweight32(iter->flags & (MEDIA_PAD_FL_SINK |
> > + MEDIA_PAD_FL_SOURCE)) != 1) {
> > + ret = -EINVAL;
> > + break;
> > + }
> > +
> > if (mdev)
> > media_gobj_create(mdev, MEDIA_GRAPH_PAD,
> > &iter->graph_obj);
> > }
> >
> > + if (ret && mdev) {
> > + media_entity_for_each_pad(entity, iter2) {
> > + if (iter2 == iter)
> > + break;
> > + media_gobj_destroy(&iter->graph_obj);
>
> Wrong iterator.
>
> Instead of using a second iterator, which can be error-prone as shown
> here, how about breaking when !iter->graph_obj.mdev, which indicates an
> uninitialized object ?
media_gobj_destroy() is actually a no-op if it hasn't been initialised
(created).
It'd be still cleaner to make the pad flag checks first and only then call
media_gobj_create() on them. But if someone needs something more in the
future, then that doesn't mix as well anymore.
Both are fine IMO.
>
> > + }
> > + }
> > +
> > if (mdev)
> > mutex_unlock(&mdev->graph_mutex);
> >
> > - return 0;
> > + return ret;
> > }
> > EXPORT_SYMBOL_GPL(media_entity_pads_init);
> >
>
--
Regards,
Sakari Ailus
next prev parent reply other threads:[~2023-09-19 10:24 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 12:51 [PATCH v2 00/12] Small fixes and cleanups (ov2740 and ccs) Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 01/12] media: Documentation: Align numbered list, make it a proper ReST Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 02/12] media: ccs: Fix driver quirk struct documentation Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 03/12] media: ccs: Correctly initialise try compose rectangle Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 04/12] media: ccs: Correct error handling in ccs_register_subdev Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 05/12] media: ccs: Switch to init_cfg Sakari Ailus
2023-09-18 13:53 ` Laurent Pinchart
2023-09-18 12:51 ` [PATCH v2 06/12] media: ccs: Use sub-device active state Sakari Ailus
2023-09-18 13:59 ` Laurent Pinchart
2023-09-19 10:29 ` Sakari Ailus
2023-09-19 13:42 ` Laurent Pinchart
2023-09-18 12:51 ` [PATCH v2 07/12] media: ov2740: Enable runtime PM before registering the async subdev Sakari Ailus
2023-09-18 13:27 ` Laurent Pinchart
2023-09-18 12:51 ` [PATCH v2 08/12] media: ov2740: Use sub-device active state Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 09/12] media: ov2740: Return -EPROBE_DEFER if no endpoint is found Sakari Ailus
2023-09-18 13:24 ` Laurent Pinchart
2023-09-19 10:11 ` Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 10/12] media: v4l: subdev: Clear frame descriptor before get_frame_desc Sakari Ailus
2023-09-18 13:30 ` Laurent Pinchart
2023-09-19 8:04 ` Tomi Valkeinen
2023-09-18 12:51 ` [PATCH v2 11/12] media: v4l: subdev: Print debug information on frame descriptor Sakari Ailus
2023-09-18 13:39 ` Laurent Pinchart
2023-09-19 8:19 ` Tomi Valkeinen
2023-09-19 10:21 ` Sakari Ailus
2023-09-18 12:51 ` [PATCH v2 12/12] media: mc: Check pad flag validity Sakari Ailus
2023-09-18 13:48 ` Laurent Pinchart
2023-09-19 10:24 ` Sakari Ailus [this message]
2023-09-19 10:37 ` Laurent Pinchart
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=ZQl24DaMGeQSTPRa@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=bingbu.cao@intel.com \
--cc=jacopo+renesas@jmondi.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=martink@posteo.de \
--cc=rmfrfs@gmail.com \
--cc=tian.shu.qiu@intel.com \
--cc=tomi.valkeinen@ideasonboard.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