Skip to content

Commit caa2792

Browse files
Kuen-Han Tsaigregkh
authored andcommitted
usb: gadget: f_subset: Fix unbalanced refcnt in geth_free
geth_alloc() increments the reference count, but geth_free() fails to decrement it. This prevents the configuration of attributes via configfs after unlinking the function. Decrement the reference count in geth_free() to ensure proper cleanup. Fixes: 02832e5 ("usb: gadget: f_subset: add configfs support") Cc: stable@vger.kernel.org Signed-off-by: Kuen-Han Tsai <khtsai@google.com> Link: https://patch.msgid.link/20260320-usb-net-lifecycle-v1-1-4886b578161b@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 269c264 commit caa2792

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/usb/gadget/function/f_subset.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Copyright (C) 2008 Nokia Corporation
77
*/
88

9+
#include <linux/cleanup.h>
910
#include <linux/slab.h>
1011
#include <linux/kernel.h>
1112
#include <linux/module.h>
@@ -449,8 +450,13 @@ static struct usb_function_instance *geth_alloc_inst(void)
449450
static void geth_free(struct usb_function *f)
450451
{
451452
struct f_gether *eth;
453+
struct f_gether_opts *opts;
454+
455+
opts = container_of(f->fi, struct f_gether_opts, func_inst);
452456

453457
eth = func_to_geth(f);
458+
scoped_guard(mutex, &opts->lock)
459+
opts->refcnt--;
454460
kfree(eth);
455461
}
456462

0 commit comments

Comments
 (0)