Linux Renesas SOC kernel development
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	Jacopo Mondi <jacopo+renesas@jmondi.org>,
	Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>,
	Ramesh Shanmugasundaram <rashanmu@gmail.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Steve Longerbeam <slongerbeam@gmail.com>
Subject: Re: [PATCH 4/5] media: rcar-csi2: Allocate v4l2_async_subdev dynamically
Date: Wed, 12 Aug 2020 01:14:19 +0300	[thread overview]
Message-ID: <20200811221419.GE17446@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20200811214324.GB1061689@oden.dyn.berto.se>

Hi Niklas,

On Tue, Aug 11, 2020 at 11:43:24PM +0200, Niklas Söderlund wrote:
> On 2020-08-11 23:59:38 +0300, Laurent Pinchart wrote:
> > v4l2_async_notifier_add_subdev() requires the asd to be allocated
> > dynamically, but the rcar-csi2 driver embeds it in the rcar_csi2
> > structure. This causes memory corruption when the notifier is destroyed
> > at remove time with v4l2_async_notifier_cleanup().
> > 
> > Fix this issue by registering the asd with
> > v4l2_async_notifier_add_fwnode_subdev(), which allocates it dynamically
> > internally.
> 
> This patch conflicts with [1] which I think is a nicer solution to the 
> problem, provided 1/2 of that series is palatable for everyone :-)
> 
> 1. [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier

That looks better to me too.

> > Fixes: 769afd212b16 ("media: rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver")
> > Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> >  drivers/media/platform/rcar-vin/rcar-csi2.c | 24 +++++++++------------
> >  1 file changed, 10 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > index c6cc4f473a07..a16c492b3143 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > @@ -362,7 +362,6 @@ struct rcar_csi2 {
> >  	struct media_pad pads[NR_OF_RCAR_CSI2_PAD];
> >  
> >  	struct v4l2_async_notifier notifier;
> > -	struct v4l2_async_subdev asd;
> >  	struct v4l2_subdev *remote;
> >  
> >  	struct v4l2_mbus_framefmt mf;
> > @@ -811,6 +810,8 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
> >  
> >  static int rcsi2_parse_dt(struct rcar_csi2 *priv)
> >  {
> > +	struct v4l2_async_subdev *asd;
> > +	struct fwnode_handle *fwnode;
> >  	struct device_node *ep;
> >  	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
> >  	int ret;
> > @@ -834,24 +835,19 @@ static int rcsi2_parse_dt(struct rcar_csi2 *priv)
> >  		return ret;
> >  	}
> >  
> > -	priv->asd.match.fwnode =
> > -		fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep));
> > -	priv->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
> > -
> > +	fwnode = fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep));
> >  	of_node_put(ep);
> >  
> > +	dev_dbg(priv->dev, "Found '%pOF'\n", to_of_node(fwnode));
> > +
> >  	v4l2_async_notifier_init(&priv->notifier);
> > -
> > -	ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
> > -	if (ret) {
> > -		fwnode_handle_put(priv->asd.match.fwnode);
> > -		return ret;
> > -	}
> > -
> >  	priv->notifier.ops = &rcar_csi2_notify_ops;
> >  
> > -	dev_dbg(priv->dev, "Found '%pOF'\n",
> > -		to_of_node(priv->asd.match.fwnode));
> > +	asd = v4l2_async_notifier_add_fwnode_subdev(&priv->notifier, fwnode,
> > +						    sizeof(*asd));
> > +	fwnode_handle_put(fwnode);
> > +	if (IS_ERR(asd))
> > +		return PTR_ERR(asd);
> >  
> >  	ret = v4l2_async_subdev_notifier_register(&priv->subdev,
> >  						  &priv->notifier);

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2020-08-11 22:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-11 20:59 [PATCH 0/5] media: Fix asd dynamic allocation Laurent Pinchart
2020-08-11 20:59 ` [PATCH 1/5] media: v4l2-async: Document asd allocation requirements Laurent Pinchart
2020-09-08  5:08   ` Laurent Pinchart
2020-09-16 15:44   ` Kieran Bingham
2020-08-11 20:59 ` [PATCH 2/5] media: rcar_drif: Fix fwnode reference leak when parsing DT Laurent Pinchart
2020-09-16 15:46   ` Kieran Bingham
2020-08-11 20:59 ` [PATCH 3/5] media: rcar_drif: Allocate v4l2_async_subdev dynamically Laurent Pinchart
2020-09-16 15:53   ` Kieran Bingham
2020-08-11 20:59 ` [PATCH 4/5] media: rcar-csi2: " Laurent Pinchart
2020-08-11 21:43   ` Niklas Söderlund
2020-08-11 22:14     ` Laurent Pinchart [this message]
2020-08-11 20:59 ` [PATCH 5/5] media: i2c: max9286: " Laurent Pinchart
2020-09-08  5:08   ` Laurent Pinchart
2020-09-14 12:55   ` Jacopo Mondi
2020-08-31 19:44 ` [PATCH 0/5] media: Fix asd dynamic allocation Ramesh Shanmugasundaram
2020-09-01 10:46   ` Chris Paterson
2020-09-10 15:53     ` Fabrizio Castro

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=20200811221419.GE17446@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=jacopo+renesas@jmondi.org \
    --cc=kieran.bingham+renesas@ideasonboard.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=rashanmu@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=slongerbeam@gmail.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