linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: sysfs: add missing mutex_destroy()
@ 2025-05-16 10:40 Bartosz Golaszewski
  2025-05-16 11:42 ` Johan Hovold
  0 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-05-16 10:40 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Johan Hovold
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, stable

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

We initialize the data->mutex in gpiod_export() but lack the
corresponding mutex_destroy() in gpiod_unexport() causing a resource
leak with mutex debugging enabled. Add the call right before kfreeing
the GPIO data.

Fixes: 6ffcb7971486 ("gpio: sysfs: use per-gpio locking")
Cc: stable@vger.kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib-sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 4a3aa09dad9d..cd3381a4bc93 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -713,6 +713,7 @@ void gpiod_unexport(struct gpio_desc *desc)
 	}
 
 	put_device(dev);
+	mutex_destroy(&data->mutex);
 	kfree(data);
 }
 EXPORT_SYMBOL_GPL(gpiod_unexport);
-- 
2.45.2


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

* Re: [PATCH] gpio: sysfs: add missing mutex_destroy()
  2025-05-16 10:40 [PATCH] gpio: sysfs: add missing mutex_destroy() Bartosz Golaszewski
@ 2025-05-16 11:42 ` Johan Hovold
  2025-05-16 12:32   ` Bartosz Golaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2025-05-16 11:42 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski,
	stable

On Fri, May 16, 2025 at 12:40:23PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> We initialize the data->mutex in gpiod_export() but lack the
> corresponding mutex_destroy() in gpiod_unexport() causing a resource
> leak with mutex debugging enabled. Add the call right before kfreeing
> the GPIO data.

No, there's no resource leak and it's perfectly fine not to call
mutex_destroy().

You can't just make shit up and then pretend to fix it...

> Fixes: 6ffcb7971486 ("gpio: sysfs: use per-gpio locking")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Johan

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

* Re: [PATCH] gpio: sysfs: add missing mutex_destroy()
  2025-05-16 11:42 ` Johan Hovold
@ 2025-05-16 12:32   ` Bartosz Golaszewski
  2025-05-16 16:58     ` Johan Hovold
  0 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-05-16 12:32 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski,
	stable

On Fri, May 16, 2025 at 1:42 PM Johan Hovold <johan@kernel.org> wrote:
>
> On Fri, May 16, 2025 at 12:40:23PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > We initialize the data->mutex in gpiod_export() but lack the
> > corresponding mutex_destroy() in gpiod_unexport() causing a resource
> > leak with mutex debugging enabled. Add the call right before kfreeing
> > the GPIO data.
>
> No, there's no resource leak and it's perfectly fine not to call
> mutex_destroy().
>

No, there's no leak but with lock debugging it still warns if the
mutex is locked when it's being destroyed so the change still makes
sense with a modified commit message.

> You can't just make shit up and then pretend to fix it...
>

There's no need for this kind of comment. You made your point clear in
the first sentence.

Bartosz

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

* Re: [PATCH] gpio: sysfs: add missing mutex_destroy()
  2025-05-16 12:32   ` Bartosz Golaszewski
@ 2025-05-16 16:58     ` Johan Hovold
  2025-05-19 12:18       ` Bartosz Golaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2025-05-16 16:58 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski,
	stable

On Fri, May 16, 2025 at 02:32:54PM +0200, Bartosz Golaszewski wrote:
> On Fri, May 16, 2025 at 1:42 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Fri, May 16, 2025 at 12:40:23PM +0200, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > >
> > > We initialize the data->mutex in gpiod_export() but lack the
> > > corresponding mutex_destroy() in gpiod_unexport() causing a resource
> > > leak with mutex debugging enabled. Add the call right before kfreeing
> > > the GPIO data.
> >
> > No, there's no resource leak and it's perfectly fine not to call
> > mutex_destroy().
> 
> No, there's no leak but with lock debugging it still warns if the
> mutex is locked when it's being destroyed so the change still makes
> sense with a modified commit message.
> 
> > You can't just make shit up and then pretend to fix it...
> 
> There's no need for this kind of comment. You made your point clear in
> the first sentence.

Your claim that there's "a resource leak with mutex debugging enabled"
is is quite specific. Now I had to go check that no one had changed
something in ways they shouldn't have recently. But mutex_destroy()
still works as it always has, which you should have verified yourself
before sending a "fix" tagged for stable backport based on a hunch.

Johan

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

* Re: [PATCH] gpio: sysfs: add missing mutex_destroy()
  2025-05-16 16:58     ` Johan Hovold
@ 2025-05-19 12:18       ` Bartosz Golaszewski
  2025-05-19 12:42         ` Johan Hovold
  0 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-05-19 12:18 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski,
	stable

On Fri, May 16, 2025 at 6:58 PM Johan Hovold <johan@kernel.org> wrote:
>
> On Fri, May 16, 2025 at 02:32:54PM +0200, Bartosz Golaszewski wrote:
> > On Fri, May 16, 2025 at 1:42 PM Johan Hovold <johan@kernel.org> wrote:
> > >
> > > On Fri, May 16, 2025 at 12:40:23PM +0200, Bartosz Golaszewski wrote:
> > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > > >
> > > > We initialize the data->mutex in gpiod_export() but lack the
> > > > corresponding mutex_destroy() in gpiod_unexport() causing a resource
> > > > leak with mutex debugging enabled. Add the call right before kfreeing
> > > > the GPIO data.
> > >
> > > No, there's no resource leak and it's perfectly fine not to call
> > > mutex_destroy().
> >
> > No, there's no leak but with lock debugging it still warns if the
> > mutex is locked when it's being destroyed so the change still makes
> > sense with a modified commit message.
> >
> > > You can't just make shit up and then pretend to fix it...
> >
> > There's no need for this kind of comment. You made your point clear in
> > the first sentence.
>
> Your claim that there's "a resource leak with mutex debugging enabled"
> is is quite specific. Now I had to go check that no one had changed
> something in ways they shouldn't have recently. But mutex_destroy()
> still works as it always has, which you should have verified yourself
> before sending a "fix" tagged for stable backport based on a hunch.
>

Yes, I admitted that the commit message was wrong. And yes, it
sometimes happens that we get copied on crappy patches. However,
unlike what your comment suggests, I don't go around the kernel,
"making sh*t up" just to add a "Fixes: Johan's commit". I had this as
part of a bigger rework I have in progress[1] (discussed previously
here[2]) and figured that with the series growing in size, I'll at
least get the fix upstream before v6.16-rc1.

I should have given the patch more than 10 seconds of thought for sure
but your immediate hostility is uncalled for. Please try to assume
good faith a bit more.

Bartosz

[1] https://github.com/brgl/linux/tree/b4/gpio-sysfs-chip-export
[2] https://lore.kernel.org/all/CAMRc=McUCeZcU6co1aN54rTudo+JfPjjForu4iKQ5npwXk6GXA@mail.gmail.com/

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

* Re: [PATCH] gpio: sysfs: add missing mutex_destroy()
  2025-05-19 12:18       ` Bartosz Golaszewski
@ 2025-05-19 12:42         ` Johan Hovold
  2025-05-19 12:50           ` Bartosz Golaszewski
  0 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2025-05-19 12:42 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski,
	stable

On Mon, May 19, 2025 at 02:18:15PM +0200, Bartosz Golaszewski wrote:
> On Fri, May 16, 2025 at 6:58 PM Johan Hovold <johan@kernel.org> wrote:
> > On Fri, May 16, 2025 at 02:32:54PM +0200, Bartosz Golaszewski wrote:
> > > On Fri, May 16, 2025 at 1:42 PM Johan Hovold <johan@kernel.org> wrote:
> > > > On Fri, May 16, 2025 at 12:40:23PM +0200, Bartosz Golaszewski wrote:
> > > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > > > >
> > > > > We initialize the data->mutex in gpiod_export() but lack the
> > > > > corresponding mutex_destroy() in gpiod_unexport() causing a resource
> > > > > leak with mutex debugging enabled. Add the call right before kfreeing
> > > > > the GPIO data.
> > > >
> > > > No, there's no resource leak and it's perfectly fine not to call
> > > > mutex_destroy().
> > >
> > > No, there's no leak but with lock debugging it still warns if the
> > > mutex is locked when it's being destroyed so the change still makes
> > > sense with a modified commit message.
> > >
> > > > You can't just make shit up and then pretend to fix it...
> > >
> > > There's no need for this kind of comment. You made your point clear in
> > > the first sentence.
> >
> > Your claim that there's "a resource leak with mutex debugging enabled"
> > is is quite specific. Now I had to go check that no one had changed
> > something in ways they shouldn't have recently. But mutex_destroy()
> > still works as it always has, which you should have verified yourself
> > before sending a "fix" tagged for stable backport based on a hunch.
> 
> Yes, I admitted that the commit message was wrong. And yes, it
> sometimes happens that we get copied on crappy patches. However,
> unlike what your comment suggests, I don't go around the kernel,
> "making sh*t up" just to add a "Fixes: Johan's commit". I had this as
> part of a bigger rework I have in progress[1] (discussed previously
> here[2]) and figured that with the series growing in size, I'll at
> least get the fix upstream before v6.16-rc1.

But it is not a fix. It is based on a misunderstanding that you should
have caught yourself by just looking at the code before posting.

Sure, mutex_destroy() is an odd bird, but you still need to verify your
guesses before posting patches based on them. It's that lazy attitude
(and violation of the stable kernel policy) that I'm criticising.

Johan

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

* Re: [PATCH] gpio: sysfs: add missing mutex_destroy()
  2025-05-19 12:42         ` Johan Hovold
@ 2025-05-19 12:50           ` Bartosz Golaszewski
  0 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2025-05-19 12:50 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski,
	stable

On Mon, May 19, 2025 at 2:42 PM Johan Hovold <johan@kernel.org> wrote:
>
> On Mon, May 19, 2025 at 02:18:15PM +0200, Bartosz Golaszewski wrote:
> > On Fri, May 16, 2025 at 6:58 PM Johan Hovold <johan@kernel.org> wrote:
> > > On Fri, May 16, 2025 at 02:32:54PM +0200, Bartosz Golaszewski wrote:
> > > > On Fri, May 16, 2025 at 1:42 PM Johan Hovold <johan@kernel.org> wrote:
> > > > > On Fri, May 16, 2025 at 12:40:23PM +0200, Bartosz Golaszewski wrote:
> > > > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > > > > >
> > > > > > We initialize the data->mutex in gpiod_export() but lack the
> > > > > > corresponding mutex_destroy() in gpiod_unexport() causing a resource
> > > > > > leak with mutex debugging enabled. Add the call right before kfreeing
> > > > > > the GPIO data.
> > > > >
> > > > > No, there's no resource leak and it's perfectly fine not to call
> > > > > mutex_destroy().
> > > >
> > > > No, there's no leak but with lock debugging it still warns if the
> > > > mutex is locked when it's being destroyed so the change still makes
> > > > sense with a modified commit message.
> > > >
> > > > > You can't just make shit up and then pretend to fix it...
> > > >
> > > > There's no need for this kind of comment. You made your point clear in
> > > > the first sentence.
> > >
> > > Your claim that there's "a resource leak with mutex debugging enabled"
> > > is is quite specific. Now I had to go check that no one had changed
> > > something in ways they shouldn't have recently. But mutex_destroy()
> > > still works as it always has, which you should have verified yourself
> > > before sending a "fix" tagged for stable backport based on a hunch.
> >
> > Yes, I admitted that the commit message was wrong. And yes, it
> > sometimes happens that we get copied on crappy patches. However,
> > unlike what your comment suggests, I don't go around the kernel,
> > "making sh*t up" just to add a "Fixes: Johan's commit". I had this as
> > part of a bigger rework I have in progress[1] (discussed previously
> > here[2]) and figured that with the series growing in size, I'll at
> > least get the fix upstream before v6.16-rc1.
>
> But it is not a fix. It is based on a misunderstanding that you should
> have caught yourself by just looking at the code before posting.
>

Noted, I'll drop the Fixes: tag and submit it as part of the rest of the rework.

> Sure, mutex_destroy() is an odd bird, but you still need to verify your
> guesses before posting patches based on them. It's that lazy attitude
> (and violation of the stable kernel policy) that I'm criticising.
>

IMO what you just wrote here is a way better way of expressing your
criticism than what you led with.

Bartosz

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

end of thread, other threads:[~2025-05-19 12:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-16 10:40 [PATCH] gpio: sysfs: add missing mutex_destroy() Bartosz Golaszewski
2025-05-16 11:42 ` Johan Hovold
2025-05-16 12:32   ` Bartosz Golaszewski
2025-05-16 16:58     ` Johan Hovold
2025-05-19 12:18       ` Bartosz Golaszewski
2025-05-19 12:42         ` Johan Hovold
2025-05-19 12:50           ` Bartosz Golaszewski

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).