linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: notify user-space about line status changes after flags are set
@ 2020-05-09 14:15 Bartosz Golaszewski
  2020-05-16  9:30 ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2020-05-09 14:15 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij, Andy Shevchenko
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently we emit the REQUESTED line state event after the line is
requested but before the flags are configured. This is obviously wrong
as we want to pass the updated lineinfo to user-space together with the
event.

Since the flags can be configured in different ways depending on how the
line is being requested - we need to call the notifier chain in different
places separately.

Fixes: 51c1064e82e7 ("gpiolib: add new ioctl() for monitoring changes in line info")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
This comes late in the release cycle but I only recently got down to
writing libgpiod support for this new ioctl(). When writing test cases
I noticed this doesn't really work as expected. This patch fixes the
issue I identified this week. There may be more coming the following
week though...

 drivers/gpio/gpiolib.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 40f2d7f69be2..550751a6e51c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -729,6 +729,10 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
 			if (ret)
 				goto out_free_descs;
 		}
+
+		atomic_notifier_call_chain(&desc->gdev->notifier,
+					   GPIOLINE_CHANGED_REQUESTED, desc);
+
 		dev_dbg(&gdev->dev, "registered chardev handle for line %d\n",
 			offset);
 	}
@@ -1083,6 +1087,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
 	if (ret)
 		goto out_free_desc;
 
+	atomic_notifier_call_chain(&desc->gdev->notifier,
+				   GPIOLINE_CHANGED_REQUESTED, desc);
+
 	le->irq = gpiod_to_irq(desc);
 	if (le->irq <= 0) {
 		ret = -ENODEV;
@@ -2975,8 +2982,6 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)
 	}
 done:
 	spin_unlock_irqrestore(&gpio_lock, flags);
-	atomic_notifier_call_chain(&desc->gdev->notifier,
-				   GPIOLINE_CHANGED_REQUESTED, desc);
 	return ret;
 }
 
@@ -4938,6 +4943,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 		return ERR_PTR(ret);
 	}
 
+	atomic_notifier_call_chain(&desc->gdev->notifier,
+				   GPIOLINE_CHANGED_REQUESTED, desc);
+
 	return desc;
 }
 EXPORT_SYMBOL_GPL(gpiod_get_index);
@@ -5003,6 +5011,9 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
 		return ERR_PTR(ret);
 	}
 
+	atomic_notifier_call_chain(&desc->gdev->notifier,
+				   GPIOLINE_CHANGED_REQUESTED, desc);
+
 	return desc;
 }
 EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod);
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpiolib: notify user-space about line status changes after flags are set
  2020-05-09 14:15 [PATCH] gpiolib: notify user-space about line status changes after flags are set Bartosz Golaszewski
@ 2020-05-16  9:30 ` Linus Walleij
  2020-05-16 13:58   ` Manivannan Sadhasivam
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2020-05-16  9:30 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Kent Gibson, Andy Shevchenko, open list:GPIO SUBSYSTEM,
	linux-kernel, Bartosz Golaszewski

On Sat, May 9, 2020 at 4:15 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> Since the flags can be configured in different ways depending on how the
> line is being requested - we need to call the notifier chain in different
> places separately.

Ooops.

> This comes late in the release cycle but I only recently got down to
> writing libgpiod support for this new ioctl(). When writing test cases
> I noticed this doesn't really work as expected.

This is why I am so grateful about the tests you are doing with
libgpiod! We actually find these problems quickly and not after
years. Thanks!

> This patch fixes the
> issue I identified this week. There may be more coming the following
> week though...

I will pull in your pull request once the next -rc is out as I had already
sent my first pull request, but do not hesitate to bug me about this.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpiolib: notify user-space about line status changes after flags are set
  2020-05-16  9:30 ` Linus Walleij
@ 2020-05-16 13:58   ` Manivannan Sadhasivam
  0 siblings, 0 replies; 3+ messages in thread
From: Manivannan Sadhasivam @ 2020-05-16 13:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Bartosz Golaszewski, Kent Gibson, Andy Shevchenko,
	open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski

On Sat, May 16, 2020 at 11:30:36AM +0200, Linus Walleij wrote:
> On Sat, May 9, 2020 at 4:15 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> 
> > Since the flags can be configured in different ways depending on how the
> > line is being requested - we need to call the notifier chain in different
> > places separately.
> 
> Ooops.
> 
> > This comes late in the release cycle but I only recently got down to
> > writing libgpiod support for this new ioctl(). When writing test cases
> > I noticed this doesn't really work as expected.
> 
> This is why I am so grateful about the tests you are doing with
> libgpiod! We actually find these problems quickly and not after
> years. Thanks!
> 

This forces me to add tests for chardev in MRAA ;) (Don't ask me about other
interfaces)

Thanks,
Mani

> > This patch fixes the
> > issue I identified this week. There may be more coming the following
> > week though...
> 
> I will pull in your pull request once the next -rc is out as I had already
> sent my first pull request, but do not hesitate to bug me about this.
> 
> Yours,
> Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-16 13:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09 14:15 [PATCH] gpiolib: notify user-space about line status changes after flags are set Bartosz Golaszewski
2020-05-16  9:30 ` Linus Walleij
2020-05-16 13:58   ` Manivannan Sadhasivam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).