[PATCH 3/3] usb: gadget: f_tcm: call attach/detach directly instead of through callbacks
From: Slawomir Stepien
Date: Thu Dec 03 2026 - 03:15:51 EST
struct f_tcm_opts carried tcm_register_callback and
tcm_unregister_callback so that the legacy g_target driver could
register and unregister its own composite driver when a TPG was
enabled or disabled. As u_tcm.h noted, they were meant to go away
together with that driver.
Only the configfs implementations are left, so fold them into
usbg_attach() and usbg_detach() and remove the pointers. Attaching
cannot fail any more, so make usbg_attach() return void.
Signed-off-by: Slawomir Stepien <sst@xxxxxxxxx>
---
drivers/usb/gadget/function/f_tcm.c | 41 ++++++-----------------------
drivers/usb/gadget/function/u_tcm.h | 10 -------
2 files changed, 8 insertions(+), 43 deletions(-)
diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
index 8f405f0a5cbd..bcd9a60589c5 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -1806,20 +1806,17 @@ static struct configfs_attribute *usbg_wwn_attrs[] = {
NULL,
};
-static int usbg_attach(struct usbg_tpg *);
+static void usbg_attach(struct usbg_tpg *);
static void usbg_detach(struct usbg_tpg *);
static int usbg_enable_tpg(struct se_portal_group *se_tpg, bool enable)
{
struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
- int ret = 0;
if (enable)
- ret = usbg_attach(tpg);
+ usbg_attach(tpg);
else
usbg_detach(tpg);
- if (ret)
- return ret;
tpg->gadget_connect = enable;
@@ -2616,20 +2613,20 @@ static void tcm_free_inst(struct usb_function_instance *f)
kfree(opts);
}
-static int tcm_register_callback(struct usb_function_instance *f)
+static void usbg_attach(struct usbg_tpg *tpg)
{
- struct f_tcm_opts *opts = container_of(f, struct f_tcm_opts, func_inst);
+ struct f_tcm_opts *opts = container_of(tpg->fi, struct f_tcm_opts,
+ func_inst);
mutex_lock(&opts->dep_lock);
opts->can_attach = true;
mutex_unlock(&opts->dep_lock);
-
- return 0;
}
-static void tcm_unregister_callback(struct usb_function_instance *f)
+static void usbg_detach(struct usbg_tpg *tpg)
{
- struct f_tcm_opts *opts = container_of(f, struct f_tcm_opts, func_inst);
+ struct f_tcm_opts *opts = container_of(tpg->fi, struct f_tcm_opts,
+ func_inst);
mutex_lock(&opts->dep_lock);
opts->can_attach = false;
@@ -2639,26 +2636,6 @@ static void tcm_unregister_callback(struct usb_function_instance *f)
unregister_gadget_item(opts->func_inst.group.cg_item.ci_parent->ci_parent);
}
-static int usbg_attach(struct usbg_tpg *tpg)
-{
- struct usb_function_instance *f = tpg->fi;
- struct f_tcm_opts *opts = container_of(f, struct f_tcm_opts, func_inst);
-
- if (opts->tcm_register_callback)
- return opts->tcm_register_callback(f);
-
- return 0;
-}
-
-static void usbg_detach(struct usbg_tpg *tpg)
-{
- struct usb_function_instance *f = tpg->fi;
- struct f_tcm_opts *opts = container_of(f, struct f_tcm_opts, func_inst);
-
- if (opts->tcm_unregister_callback)
- opts->tcm_unregister_callback(f);
-}
-
static int tcm_set_name(struct usb_function_instance *f, const char *name)
{
struct f_tcm_opts *opts = container_of(f, struct f_tcm_opts, func_inst);
@@ -2696,8 +2673,6 @@ static struct usb_function_instance *tcm_alloc_inst(void)
mutex_init(&opts->dep_lock);
opts->func_inst.set_inst_name = tcm_set_name;
opts->func_inst.free_func_inst = tcm_free_inst;
- opts->tcm_register_callback = tcm_register_callback;
- opts->tcm_unregister_callback = tcm_unregister_callback;
config_group_init_type_name(&opts->func_inst.group, "",
&tcm_func_type);
diff --git a/drivers/usb/gadget/function/u_tcm.h b/drivers/usb/gadget/function/u_tcm.h
index 93d3deb9a408..c882acba8d3d 100644
--- a/drivers/usb/gadget/function/u_tcm.h
+++ b/drivers/usb/gadget/function/u_tcm.h
@@ -32,16 +32,6 @@ struct f_tcm_opts {
struct mutex dep_lock;
bool ready;
bool can_attach;
-
- /*
- * Callbacks to be removed when legacy tcm gadget disappears.
- *
- * If you use the new function registration interface
- * programmatically, you MUST set these callbacks to
- * something sensible (e.g. probe/remove the composite).
- */
- int (*tcm_register_callback)(struct usb_function_instance *);
- void (*tcm_unregister_callback)(struct usb_function_instance *);
};
#endif /* U_TCM_H */
--
2.56.1