Re: subdevice config into pointer (was Re: [PATCH 1/4] v4l2: device_register_subdev_nodes: allow calling multiple times)

From: Sakari Ailus
Date: Thu Mar 02 2017 - 16:21:13 EST


Hi Laurent,

On Thu, Mar 02, 2017 at 08:39:51PM +0200, Laurent Pinchart wrote:
> Hi Sakari,
>
> On Thursday 02 Mar 2017 16:16:17 Sakari Ailus wrote:
> > On Thu, Mar 02, 2017 at 10:07:27AM +0100, Pavel Machek wrote:
> > > Hi!
> > >
> > > > Making the sub-device bus configuration a pointer should be in a
> > > > separate patch. It makes sense since the entire configuration is not
> > > > valid for all sub-devices attached to the ISP anymore. I think it
> > > > originally was a separate patch, but they probably have been merged at
> > > > some point. I can'tfind it right now anyway.
> > >
> > > Something like this?
> > >
> > > Pavel
> > >
> > > commit df9141c66678b549fac9d143bd55ed0b242cf36e
> > > Author: Pavel <pavel@xxxxxx>
> > > Date: Wed Mar 1 13:27:56 2017 +0100
> > >
> > > Turn bus in struct isp_async_subdev into pointer; some of our subdevs
> > > (flash, focus) will not need bus configuration.
> > >
> > > Signed-off-by: Pavel Machek <pavel@xxxxxx>
> >
> > I applied this to the ccp2 branch with an improved patch description.
> >
> > > diff --git a/drivers/media/platform/omap3isp/isp.c
> > > b/drivers/media/platform/omap3isp/isp.c index 8a456d4..36bd359 100644
> > > --- a/drivers/media/platform/omap3isp/isp.c
> > > +++ b/drivers/media/platform/omap3isp/isp.c
> > > @@ -2030,12 +2030,18 @@ enum isp_of_phy {
> > >
> > > static int isp_fwnode_parse(struct device *dev, struct fwnode_handle
> > > *fwn,
> > >
> > > struct isp_async_subdev *isd)
> > >
> > > {
> > >
> > > - struct isp_bus_cfg *buscfg = &isd->bus;
> > > + struct isp_bus_cfg *buscfg;
> > >
> > > struct v4l2_fwnode_endpoint vfwn;
> > > unsigned int i;
> > > int ret;
> > > bool csi1 = false;
> > >
> > > + buscfg = devm_kzalloc(dev, sizeof(*isd->bus), GFP_KERNEL);
>
> Given that you recently get rid of devm_kzalloc() in the driver, let's not
> introduce a new one here.

That's certainly a valid point.

Still, the entire async sub-devices array is allocated with devm_()
allocation functions still; that part wasn't addressed by the patchset
mostly removing devm_() memory allocation, so this patch does actually not
change how the memory is allocated.

Beyond that, I'm not entirely sure whether this is a problem to begin with:
devm resources are released after remove() callback and access to this data
structure should only happen as a direct result of user IOCTL. IOCTLs may
only be in progress as long as there are open file handles on a device ---
and such file handles must be closed until the remove() callback may finish.
(Referring to the Oslo meeting notes.)

Some of the above must be still verified; either way, but the options are
clear: either devm must be removed here as well (with the rest) or that it's
fine to use it here: from this point of view this patch makes no difference.

>
> > > + if (!buscfg)
> > > + return -ENOMEM;
> > > +
> > > + isd->bus = buscfg;
> > > +
> > > ret = v4l2_fwnode_endpoint_parse(fwn, &vfwn);
> > > if (ret)
> > >
> > > return ret;
> > >
>
> [snip]
>

--
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@xxxxxx XMPP: sailus@xxxxxxxxxxxxxx