Re: [PATCH] gpiolib: extend the critical sections of lookup tables
From: Bartosz Golaszewski
Date: Wed Sep 20 2023 - 05:33:10 EST
On Wed, 20 Sep 2023 11:12:58 +0200, Linus Walleij
<linus.walleij@xxxxxxxxxx> said:
> On Wed, Sep 20, 2023 at 10:56 AM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
>
>> From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
>>
>> There are two places in the code where we retrieve a lookup table using
>> gpiod_find_lookup_table() (which protects the table list with the lookup
>> table lock) and then use it after the lock is released.
>>
>> We need to keep the lookup table mutex locked the entire time we're using
>> the tables. Remove the locking from gpiod_find_lookup_table() and use
>> guards to protect the code actually using the table objects.
>>
>> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
>
> I convinced myself that this change is correct, good find!
>
>> @@ -3822,8 +3822,6 @@ static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev)
>
> Can we rename this function gpiod_find_lookup_table_locked()
> as per precedents in the kernel, to indicate that it needs to be
> called with a lock held?
>
I think you mean gpiod_find_lookup_table_unlocked() as with this change it
will no longer take the lock?
Bart
> Either way:
> Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
>
> Yours,
> Linus Walleij
>