* [PATCH] gpiolib: cdev: fix uninitialised kfifo
@ 2024-05-10 6:53 Kent Gibson
2024-05-10 14:06 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Kent Gibson @ 2024-05-10 6:53 UTC (permalink / raw)
To: linux-kernel, linux-gpio, brgl, linus.walleij; +Cc: Kent Gibson
If a line is requested with debounce, and that results in debouncing
in software, and the line is subsequently reconfigured to enable edge
detection then the allocation of the kfifo to contain edge events is
overlooked. This results in events being written to and read from an
unitialised kfifo. Read events are returned to userspace.
Initialise the kfifo in the case where the software debounce is
already active.
Fixes: 65cff7046406 ("gpiolib: cdev: support setting debounce")
Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
drivers/gpio/gpiolib-cdev.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index d09c7d728365..57c92395219e 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1193,6 +1193,8 @@ static int edge_detector_update(struct line *line,
struct gpio_v2_line_config *lc,
unsigned int line_idx, u64 edflags)
{
+ u64 eflags;
+ int ret;
u64 active_edflags = READ_ONCE(line->edflags);
unsigned int debounce_period_us =
gpio_v2_line_config_debounce_period(lc, line_idx);
@@ -1204,6 +1206,18 @@ static int edge_detector_update(struct line *line,
/* sw debounced and still will be...*/
if (debounce_period_us && READ_ONCE(line->sw_debounced)) {
line_set_debounce_period(line, debounce_period_us);
+ /*
+ * ensure event fifo is initialised if edge detection
+ * is now enabled.
+ */
+ eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS;
+ if (eflags && !kfifo_initialized(&line->req->events)) {
+ ret = kfifo_alloc(&line->req->events,
+ line->req->event_buffer_size,
+ GFP_KERNEL);
+ if (ret)
+ return ret;
+ }
return 0;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: cdev: fix uninitialised kfifo
2024-05-10 6:53 [PATCH] gpiolib: cdev: fix uninitialised kfifo Kent Gibson
@ 2024-05-10 14:06 ` Bartosz Golaszewski
2024-05-14 3:36 ` Kent Gibson
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-05-10 14:06 UTC (permalink / raw)
To: linux-kernel, linux-gpio, brgl, linus.walleij, Kent Gibson
Cc: Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On Fri, 10 May 2024 14:53:42 +0800, Kent Gibson wrote:
> If a line is requested with debounce, and that results in debouncing
> in software, and the line is subsequently reconfigured to enable edge
> detection then the allocation of the kfifo to contain edge events is
> overlooked. This results in events being written to and read from an
> unitialised kfifo. Read events are returned to userspace.
>
> Initialise the kfifo in the case where the software debounce is
> already active.
>
> [...]
Applied, thanks!
[1/1] gpiolib: cdev: fix uninitialised kfifo
commit: 3c1625fe5a2e0d68cd7b68156f02c1b5de09a161
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: cdev: fix uninitialised kfifo
2024-05-10 14:06 ` Bartosz Golaszewski
@ 2024-05-14 3:36 ` Kent Gibson
2024-05-14 6:56 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Kent Gibson @ 2024-05-14 3:36 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: linux-kernel, linux-gpio, linus.walleij, Bartosz Golaszewski
On Fri, May 10, 2024 at 04:06:16PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
>
> On Fri, 10 May 2024 14:53:42 +0800, Kent Gibson wrote:
> > If a line is requested with debounce, and that results in debouncing
> > in software, and the line is subsequently reconfigured to enable edge
> > detection then the allocation of the kfifo to contain edge events is
> > overlooked. This results in events being written to and read from an
> > unitialised kfifo. Read events are returned to userspace.
> >
> > Initialise the kfifo in the case where the software debounce is
> > already active.
> >
> > [...]
>
> Applied, thanks!
>
> [1/1] gpiolib: cdev: fix uninitialised kfifo
> commit: 3c1625fe5a2e0d68cd7b68156f02c1b5de09a161
>
I've got a patch series to tidy this up and catch any similar errors
earlier going forward.
It is of course based on this patch, but that isn't in gpio/for-next yet.
How should I proceed?
Cheers,
Kent.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: cdev: fix uninitialised kfifo
2024-05-14 3:36 ` Kent Gibson
@ 2024-05-14 6:56 ` Bartosz Golaszewski
2024-05-14 12:15 ` Kent Gibson
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-05-14 6:56 UTC (permalink / raw)
To: Kent Gibson; +Cc: Bartosz Golaszewski, linux-kernel, linux-gpio, linus.walleij
On Tue, 14 May 2024 at 05:37, Kent Gibson <warthog618@gmail.com> wrote:
>
> On Fri, May 10, 2024 at 04:06:16PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> >
> > On Fri, 10 May 2024 14:53:42 +0800, Kent Gibson wrote:
> > > If a line is requested with debounce, and that results in debouncing
> > > in software, and the line is subsequently reconfigured to enable edge
> > > detection then the allocation of the kfifo to contain edge events is
> > > overlooked. This results in events being written to and read from an
> > > unitialised kfifo. Read events are returned to userspace.
> > >
> > > Initialise the kfifo in the case where the software debounce is
> > > already active.
> > >
> > > [...]
> >
> > Applied, thanks!
> >
> > [1/1] gpiolib: cdev: fix uninitialised kfifo
> > commit: 3c1625fe5a2e0d68cd7b68156f02c1b5de09a161
> >
>
> I've got a patch series to tidy this up and catch any similar errors
> earlier going forward.
> It is of course based on this patch, but that isn't in gpio/for-next yet.
> How should I proceed?
>
> Cheers,
> Kent.
Pull in current master into gpio/for-next, apply your series, make
sure it works and then wait until v6.10-rc1 is tagged because I won't
be picking up anything during merge window.
Bart
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: cdev: fix uninitialised kfifo
2024-05-14 6:56 ` Bartosz Golaszewski
@ 2024-05-14 12:15 ` Kent Gibson
0 siblings, 0 replies; 5+ messages in thread
From: Kent Gibson @ 2024-05-14 12:15 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Bartosz Golaszewski, linux-kernel, linux-gpio, linus.walleij
On Tue, May 14, 2024 at 08:56:13AM +0200, Bartosz Golaszewski wrote:
> On Tue, 14 May 2024 at 05:37, Kent Gibson <warthog618@gmail.com> wrote:
> >
> > On Fri, May 10, 2024 at 04:06:16PM +0200, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > >
> > >
> > > On Fri, 10 May 2024 14:53:42 +0800, Kent Gibson wrote:
> > > > If a line is requested with debounce, and that results in debouncing
> > > > in software, and the line is subsequently reconfigured to enable edge
> > > > detection then the allocation of the kfifo to contain edge events is
> > > > overlooked. This results in events being written to and read from an
> > > > unitialised kfifo. Read events are returned to userspace.
> > > >
> > > > Initialise the kfifo in the case where the software debounce is
> > > > already active.
> > > >
> > > > [...]
> > >
> > > Applied, thanks!
> > >
> > > [1/1] gpiolib: cdev: fix uninitialised kfifo
> > > commit: 3c1625fe5a2e0d68cd7b68156f02c1b5de09a161
> > >
> >
> > I've got a patch series to tidy this up and catch any similar errors
> > earlier going forward.
> > It is of course based on this patch, but that isn't in gpio/for-next yet.
> > How should I proceed?
> >
> > Cheers,
> > Kent.
>
> Pull in current master into gpio/for-next, apply your series, make
> sure it works and then wait until v6.10-rc1 is tagged because I won't
> be picking up anything during merge window.
>
Will do.
Thanks,
Kent.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-14 12:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-10 6:53 [PATCH] gpiolib: cdev: fix uninitialised kfifo Kent Gibson
2024-05-10 14:06 ` Bartosz Golaszewski
2024-05-14 3:36 ` Kent Gibson
2024-05-14 6:56 ` Bartosz Golaszewski
2024-05-14 12:15 ` Kent Gibson
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).