Re: [PATCH v2 4/9] gpio: regmap: add the .fixed_direction_output configuration parameter

From: Bartosz Golaszewski
Date: Tue Sep 16 2025 - 05:52:46 EST


On Mon, 15 Sep 2025 14:45:58 +0200, Michael Walle <mwalle@xxxxxxxxxx> said:
> Hi Ioana,
>
> On Mon Sep 15, 2025 at 2:23 PM CEST, Ioana Ciornei wrote:
>> There are GPIO controllers such as the one present in the LX2160ARDB
>> QIXIS FPGA which have fixed-direction input and output GPIO lines mixed
>> together in a single register. This cannot be modeled using the
>> gpio-regmap as-is since there is no way to present the true direction of
>> a GPIO line.
>>
>> In order to make this use case possible, add a new configuration
>> parameter - fixed_direction_output - into the gpio_regmap_config
>> structure. This will enable user drivers to provide a bitmap that
>> represents the fixed direction of the GPIO lines.
>
> I wonder about the ownership of that allocated memory in the config
> structure (and btw, I guess you leak the memory in your driver) and
> if it's not better and more error proof to allocate and copy the
> bitmap in gpio-regmap too (and maybe use devm_bitmap_alloc()) and
> leave it to the caller to handle the passed bitmap. I.e. it could
> also be on the stack.
>

I was under the impression that whatever is in the config structure for GPIO
regmap init function is only required to stay alive until that call returns?

If so, then yes, a deep copy of everything from this structure is required.

> Otherwise, this looks good.
>

[snip]

>>
>> + if (offset >= chip->ngpio)
>> + return -EINVAL;
>
> Not sure this can happen. I tried to look into gpiolib.c but
> couldn't find anything obvious that it can't happen. Maybe Linus or
> Bartosz can comment on that.
>

Indeed, this is handed by GPIO core, please drop it.

[snip]

Bartosz