On Fri, Jun 21, 2019 at 5:23 PM Thierry Reding <thierry.reding@xxxxxxxxx> wrote: > From: Thierry Reding <treding@xxxxxxxxxx> > > Create a device link between a GPIO consumer and the GPIO supplier (i.e. > the GPIO chip's parent). This makes the driver core aware of the > dependency between the two devices so that it can properly order the > suspend/resume sequence. > > As a side-effect the GPIO consumer will be force unloaded when the GPIO > supplier goes away, which prevents the consumer from accessing dangling > GPIOs. > > Signed-off-by: Thierry Reding <treding@xxxxxxxxxx> I was thinking we were gonna see this soon :D > +void gpiod_add_device_link(struct gpio_desc *desc, struct device *consumer) > +{ > + struct device_link *link; > + > + link = device_link_add(consumer, desc->gdev->dev.parent, > + DL_FLAG_AUTOREMOVE_CONSUMER); I think this needs a NULL check. Some GPIO chips still have NULL as parent here, they just register a gpio_chip right out of boardfile code without any corresponding device. MIPS does this for example IIRC. > + device_link_remove(desc->consumer, desc->gdev->dev.parent); And same on remove. But why not use desc->gdev->dev as link, simply? That device has the same lifetime as the gpio_chip, sometimes even longer I think, if e.g. there is userspace holding the GPIOs. Yours, Linus Walleij