On Wed, Oct 28, 2020 at 6:15 PM Linus Walleij <linus.walleij@xxxxxxxxxx> wrote: > > On Thu, Oct 22, 2020 at 6:26 PM Andy Shevchenko > <andy.shevchenko@xxxxxxxxx> wrote: > > > It _seems_ between > > 79a9becda894 ("gpiolib: export descriptor-based GPIO interface") > > and > > 14e85c0e69d5 ("gpio: remove gpio_descs global array") > > the "Interacting With the Legacy GPIO Subsystem" of GPIO consumer > > interface is correct. > > > > But is it the case afterwards? > > > > Details of the question are here [1]. > > > > [1]: https://stackoverflow.com/q/64455505/2511795 > > I don't know if I even understand the question right, but gpio_to_desc() > can be called at any time as long as there is a struct gpio_chip with > the global GPIO number assigned to it. It will just index into the > array of descriptors stored inside the chip and return a pointer. > The allocation of the memory lives with the struct gpio_chip. > > If for example that chip is on USB and you unplug that USB > cable, naturally referencing the descriptor after that point > will cause disasters. > > The gpio_request()/free() doesn't really allocate or free > any memory at all. This is why we call gpio_to_desc() first > thing in the legacy functions. The section titled "Interacting With the Legacy GPIO Subsystem" describes as far as I got it the interaction of gpio_to_desc() and desc_to_gpio() with new / legacy APIs along with their scope. But is that description correct after the above mentioned commit, i.e. 14e85c0e69d5 ("gpio: remove gpio_descs global array") when we lose the always-present data structure (if I'm not mistaken)? -- With Best Regards, Andy Shevchenko