All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_fs: Init reset_work at alloc to avoid kill_sb WARN
@ 2026-07-25 12:08 Ondřej Jirman
  2026-11-20 10:21 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Ondřej Jirman @ 2026-07-25 12:08 UTC (permalink / raw)
  To: linux-usb
  Cc: linux-kernel, Ondrej Jirman, Greg Kroah-Hartman, Al Viro, Sam Day,
	Michael Bommarito, fanggeng, Mateusz Guzik, Kees Cook

From: Ondrej Jirman <megi@xff.cz>

ffs_data is zero-allocated and reset_work is only INIT_WORK'd on the
FFS_DEACTIVATED path in set_alt/disable, which the normal flow never
takes. ffs_fs_kill_sb() then cancel_work_sync()s it unconditionally,
tripping the WARN_ON(!work->func) in __flush_work() with a NULL func.

Initialize reset_work once in ffs_data_new() and drop the redundant
lazy INIT_WORK calls.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/usb/gadget/function/f_fs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 75912ce6ab55..a7b08180277f 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -54,6 +54,9 @@ MODULE_IMPORT_NS("DMA_BUF");
 /* Reference counter handling */
 static void ffs_data_get(struct ffs_data *ffs);
 static void ffs_data_put(struct ffs_data *ffs);
+
+static void ffs_reset_work(struct work_struct *work);
+
 /* Creates new ffs_data object. */
 static struct ffs_data *__must_check ffs_data_new(const char *dev_name)
 	__attribute__((malloc));
@@ -2222,6 +2225,8 @@ static struct ffs_data *ffs_data_new(const char *dev_name)
 	init_waitqueue_head(&ffs->wait);
 	init_completion(&ffs->ep0req_completion);
 
+	INIT_WORK(&ffs->reset_work, ffs_reset_work);
+
 	/* XXX REVISIT need to update it in some places, or do we? */
 	ffs->ev.can_stall = 1;
 
@@ -3775,7 +3780,6 @@ static int ffs_func_set_alt(struct usb_function *f,
 	if (ffs->state == FFS_DEACTIVATED) {
 		ffs->state = FFS_CLOSING;
 		spin_unlock_irqrestore(&ffs->eps_lock, flags);
-		INIT_WORK(&ffs->reset_work, ffs_reset_work);
 		schedule_work(&ffs->reset_work);
 		return -ENODEV;
 	}
@@ -3806,7 +3810,6 @@ static void ffs_func_disable(struct usb_function *f)
 	if (ffs->state == FFS_DEACTIVATED) {
 		ffs->state = FFS_CLOSING;
 		spin_unlock_irqrestore(&ffs->eps_lock, flags);
-		INIT_WORK(&ffs->reset_work, ffs_reset_work);
 		schedule_work(&ffs->reset_work);
 		return;
 	}
-- 
2.54.0


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

* Re: [PATCH] usb: gadget: f_fs: Init reset_work at alloc to avoid kill_sb WARN
  2026-07-25 12:08 [PATCH] usb: gadget: f_fs: Init reset_work at alloc to avoid kill_sb WARN Ondřej Jirman
@ 2026-11-20 10:21 ` Greg Kroah-Hartman
  2026-11-20 18:06   ` Ondřej Jirman
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-20 10:21 UTC (permalink / raw)
  To: Ondřej Jirman
  Cc: linux-usb, linux-kernel, Al Viro, Sam Day, Michael Bommarito,
	fanggeng, Mateusz Guzik, Kees Cook

On Sat, Jul 25, 2026 at 02:08:34PM +0200, Ondřej Jirman wrote:
> From: Ondrej Jirman <megi@xff.cz>
> 
> ffs_data is zero-allocated and reset_work is only INIT_WORK'd on the
> FFS_DEACTIVATED path in set_alt/disable, which the normal flow never
> takes. ffs_fs_kill_sb() then cancel_work_sync()s it unconditionally,
> tripping the WARN_ON(!work->func) in __flush_work() with a NULL func.

How does that happen?  What triggers it?

> 
> Initialize reset_work once in ffs_data_new() and drop the redundant
> lazy INIT_WORK calls.
> 
> Signed-off-by: Ondrej Jirman <megi@xff.cz>

No fixes tag?  No cc: stable?

What found this issue?  How was it tested?

thanks,

greg k-h

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

* Re: [PATCH] usb: gadget: f_fs: Init reset_work at alloc to avoid kill_sb WARN
  2026-11-20 10:21 ` Greg Kroah-Hartman
@ 2026-11-20 18:06   ` Ondřej Jirman
  0 siblings, 0 replies; 3+ messages in thread
From: Ondřej Jirman @ 2026-11-20 18:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Al Viro, Sam Day, Michael Bommarito,
	fanggeng, Mateusz Guzik, Kees Cook

On Fri, Nov 20, 2026 at 11:21:57AM +0100, Greg Kroah-Hartman wrote:
> On Sat, Jul 25, 2026 at 02:08:34PM +0200, Ondřej Jirman wrote:
> > From: Ondrej Jirman <megi@xff.cz>
> > 
> > ffs_data is zero-allocated and reset_work is only INIT_WORK'd on the
> > FFS_DEACTIVATED path in set_alt/disable, which the normal flow never
> > takes. ffs_fs_kill_sb() then cancel_work_sync()s it unconditionally,
> > tripping the WARN_ON(!work->func) in __flush_work() with a NULL func.
> 
> How does that happen?  What triggers it?

Well it's a few months. :) IIRC it's triggered by using multiple f_fs
gadget instances at once. What I was working on at the time is having
adbd and secure card gadget impelemnted and running at the same time.

Too late to find any traces and more detailed information now.

Anyway, looking at what's left after rebase of this patch on top of 7.3, someone
else must have fixed the same issue already. This is how this commit looks like
now:


commit 947aaf37e3f4b9af8a694297cc08c71edbbca2b5
Author: Ondrej Jirman <megi@xff.cz>
Date:   Sun Jul 19 14:57:16 2026 +0200

    usb: gadget: f_fs: Init reset_work at alloc to avoid kill_sb WARN

    ffs_data is zero-allocated and reset_work is only INIT_WORK'd on the
    FFS_DEACTIVATED path in set_alt/disable, which the normal flow never
    takes. ffs_fs_kill_sb() then cancel_work_sync()s it unconditionally,
    tripping the WARN_ON(!work->func) in __flush_work() with a NULL func.

    Initialize reset_work once in ffs_data_new() and drop the redundant
    lazy INIT_WORK calls.

    Signed-off-by: Ondrej Jirman <megi@xff.cz>

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index c64a268e98a4..972f424ad252 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -54,6 +54,9 @@ MODULE_IMPORT_NS("DMA_BUF");
 /* Reference counter handling */
 static void ffs_data_get(struct ffs_data *ffs);
 static void ffs_data_put(struct ffs_data *ffs);
+
+static void ffs_reset_work(struct work_struct *work);
+
 /* Creates new ffs_data object. */
 static struct ffs_data *__must_check ffs_data_new(const char *dev_name)
        __attribute__((malloc));
@@ -2291,6 +2294,8 @@ static struct ffs_data *ffs_data_new(const char *dev_name)
        init_completion(&ffs->ep0req_completion);
        INIT_WORK(&ffs->reset_work, ffs_reset_work);

+       INIT_WORK(&ffs->reset_work, ffs_reset_work);
+
        /* XXX REVISIT need to update it in some places, or do we? */
        ffs->ev.can_stall = 1;


So I think you can ignore it.

Best regards,
	o.

> > 
> > Initialize reset_work once in ffs_data_new() and drop the redundant
> > lazy INIT_WORK calls.
> > 
> > Signed-off-by: Ondrej Jirman <megi@xff.cz>
> 
> No fixes tag?  No cc: stable?
> 
> What found this issue?  How was it tested?
> 
> thanks,
> 
> greg k-h

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

end of thread, other threads:[~2026-11-20 18:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25 12:08 [PATCH] usb: gadget: f_fs: Init reset_work at alloc to avoid kill_sb WARN Ondřej Jirman
2026-11-20 10:21 ` Greg Kroah-Hartman
2026-11-20 18:06   ` Ondřej Jirman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.