Re: [PATCH] gpiolib: notify user-space about line state changes triggered by kernel

From: Andy Shevchenko
Date: Mon Aug 21 2023 - 06:43:58 EST


On Fri, Aug 18, 2023 at 09:09:44PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>

Interestingly why you keep submitter and author different...

> We currently only emit CHANGED_CONFIG events when the user-space changes
> GPIO config. We won't be notified if changes come from in-kernel. Let's
> call the notifier chain whenever kernel users change direction or any of
> the active-low, debounce or consumer name settings. We don't notify the
> user-space about the persistence as the uAPI has no notion of it.

...

> - if (!ret)
> + if (!ret) {
> set_bit(FLAG_IS_OUT, &desc->flags);
> + blocking_notifier_call_chain(&desc->gdev->notifier,
> + GPIO_V2_LINE_CHANGED_CONFIG,
> + desc);
> + }
> trace_gpio_value(desc_to_gpio(desc), 0, val);
> trace_gpio_direction(desc_to_gpio(desc), 0, ret);
> return ret;

The if (!ret) makes me a bit slower to understand as usual pattern to test
for the errors first.

That said, perhaps

if (ret)
goto out_trace_event;

set_bit(FLAG_IS_OUT, &desc->flags);
blocking_notifier_call_chain(&desc->gdev->notifier,
GPIO_V2_LINE_CHANGED_CONFIG, desc);

out_trace_event:
trace_gpio_value(desc_to_gpio(desc), 0, val);
trace_gpio_direction(desc_to_gpio(desc), 0, ret);
return ret;

...

> + ret = gpiod_set_config(desc, config);
> + if (!ret)
> + blocking_notifier_call_chain(&desc->gdev->notifier,
> + GPIO_V2_LINE_CHANGED_CONFIG,
> + desc);
> + return ret;

Ditto.

ret = gpiod_set_config(desc, config);
if (ret)
return ret;

blocking_notifier_call_chain(&desc->gdev->notifier,
GPIO_V2_LINE_CHANGED_CONFIG, desc);
return 0;

--
With Best Regards,
Andy Shevchenko