On Mon, Jun 07, 2021 at 09:55:45PM -0300, Jason Gunthorpe wrote: > Currently really_probe() returns 1 on success and 0 if the probe() call > fails. This return code arrangement is designed to be useful for > __device_attach_driver() which is walking the device list and trying every > driver. 0 means to keep trying. > > However, it is not useful for the other places that call through to > really_probe() that do actually want to see the probe() return code. > > For instance bind_store() would be better to return the actual error code > from the driver's probe method, not discarding it and returning -ENODEV. Why does that matter? Why does it need to know this? > Reorganize things so that really_probe() always returns an error code on > failure and 0 on success. Move the special code for device list walking > into the walker callback __device_attach_driver() and trigger it based on > an output flag from really_probe(). Update the rest of the API surface to > return a normal -ERR or 0 on success. > > Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx> > --- > drivers/base/bus.c | 6 +---- > drivers/base/dd.c | 61 ++++++++++++++++++++++++++++++---------------- > 2 files changed, 41 insertions(+), 26 deletions(-) > > diff --git a/drivers/base/bus.c b/drivers/base/bus.c > index 36d0c654ea6124..03591f82251302 100644 > --- a/drivers/base/bus.c > +++ b/drivers/base/bus.c > @@ -212,13 +212,9 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, > dev = bus_find_device_by_name(bus, NULL, buf); > if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { > err = device_driver_attach(drv, dev); > - > - if (err > 0) { > + if (!err) { > /* success */ > err = count; > - } else if (err == 0) { > - /* driver didn't accept device */ > - err = -ENODEV; > } > } > put_device(dev); > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > index c1a92cff159873..7fb58e6219b255 100644 > --- a/drivers/base/dd.c > +++ b/drivers/base/dd.c > @@ -513,7 +513,13 @@ static ssize_t state_synced_show(struct device *dev, > } > static DEVICE_ATTR_RO(state_synced); > > -static int really_probe(struct device *dev, struct device_driver *drv) > +enum { > + /* Set on output if the -ERR has come from a probe() function */ > + PROBEF_DRV_FAILED = 1 << 0, > +}; > + > +static int really_probe(struct device *dev, struct device_driver *drv, > + unsigned int *flags) Ugh, no, please no functions with random "flags" in them, that way lies madness and unmaintainable code for decades to come. Especially as I have no idea what this is trying to solve here at all... greg k-h