Re: [22/44] driver core: let dev_set_drvdata return int instead of void as it can fail

Uwe Kleine-König
2011-05-20T08:01:17Z

On Fri, May 20, 2011 at 02:53:30AM -0500, Milton Miller wrote:
> On Fri, 20 May 2011 about 00:10:40 -0000, Greg Kroah-Hartman wrote:
> >
> > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> >
> > Before commit
> >
> > b402843 (Driver core: move dev_get/set_drvdata to drivers/base/dd.c)
> >
> > calling dev_set_drvdata with dev=NULL was an unchecked error. After some
> > discussion about what to return in this case removing the check (and so
> > producing a null pointer exception) seems fine.
> >
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
> >
>
> I obviously didn't follow the discussions close enough and got
> confused[1], but I don't like the anticipated fallout of pushing this
> change though all the drivers. Let alone see the arguments that not
> being able to free the device when it fails is no reason to fail.
>
> So, my first question is: When is it legal for a driver to set driver
> data before a device is registered?
A driver cannot set driver data on an unregistered device because it
doesn't get it's hands on it before. So it's only the code that
registers a device that has a chance to do so.

A while back I thought about breaking these constructs by setting
driver_data to NULL before a device is handed to a driver. Never came
around to make a patch tough.

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |