On Tue, Dec 4, 2018 at 2:16 PM Marek Szyprowski <m.szyprowski@xxxxxxxxxxx> wrote: > gpiod_get_from_of_node() still needs a fix for non-exclusive access > (current linux-next lacks code for it), but I assume it will be handled > by separate patch. Yes but since that is not a regression I am just including it in the repost of the fixup series. > The only problem I predict is the lack of refcounting. Assuming that you > would like to continue 'Regulator ena_gpiod fixups' approach, the first > call to devm_gpiod_unhinge() will remove 'all allocated instances', so > if the same descriptor will be used for more than one regulator, it must > be somehow handled... I looked closer at it... so if you try to remove a resource from devres handling that is not handled by devres, it will return -ENOENT which spits a warning, so I will augment the patch adding the gpiod_unhinge() so it ignores this error. Since at that point we will immediately handle over the first user of the GPIO descriptor to the regulator core, the first call effectively transfers the ownership of *all* users of this descriptor to the regulator core. When the second descriptor is unhinged, nothing will happen (as it is no longer under managed resources) then it is passed to the regulator core that will identify that it is already managing this descriptor, and simply increase the refcount to 1. This happens in regulator_ena_gpio_request() where the regulator_ena_gpio_list is traversed and if the gpio desc is already in used it simply results in pin->request_count++. So AFAICT it is going to work just fine if I just make sure that devm_gpiod_unhinge() ignores -ENOENT. Adding this! Yours, Linus Walleij