Re: [PATCH v2 07/11] gpiolib: replace find_chip_by_name() with gpio_device_find_by_label()

From: Andy Shevchenko
Date: Tue Sep 12 2023 - 07:09:49 EST


On Tue, Sep 12, 2023 at 12:07:23PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
>
> Remove all remaining uses of find_chip_by_name() (and subsequently:
> gpiochip_find()) from gpiolib.c and use the new
> gpio_device_find_by_label() instead.

...

> for (hog = &hogs[0]; hog->chip_label; hog++) {
> + struct gpio_device *gdev __free(gpio_device_put) = NULL;

In the loop?! How does it work when loop goes second iteration and so on?

> list_add_tail(&hog->list, &gpio_machine_hogs);
>
> /*
> * The chip may have been registered earlier, so check if it
> * exists and, if so, try to hog the line now.
> */
> - gc = find_chip_by_name(hog->chip_label);
> - if (gc)
> - gpiochip_machine_hog(gc, hog);
> + gdev = gpio_device_find_by_label(hog->chip_label);
> + if (gdev)
> + gpiochip_machine_hog(gpio_device_get_chip(gdev), hog);

So, do we expect the chip_label be different between hogs? Ah, seems so
as it covers _all_ hogs in the system.

> }

Even if the __free() scope works fine, I think this algorithm should be
revisited to make sure we have iterating only on hogs of the same chip.
Hence, the hogs should be placed into tree structure with a label being
the key in it.

...

> + struct gpio_device *gdev __free(gpio_device_put) = NULL;

> + gc = gpio_device_get_chip(gdev);

Similar wish here, perhaps maple tree can be utilized in the future for both of them.

--
With Best Regards,
Andy Shevchenko