mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 10:41:38 -04:00
target: simplify the target template registration API
Instead of calling target_fabric_configfs_init() + target_fabric_configfs_register() / target_fabric_configfs_deregister() target_fabric_configfs_free() from every target driver, rewrite the API so that we have simple register/unregister functions that operate on a const operations vector. This patch also fixes a memory leak in several target drivers. Several target drivers namely called target_fabric_configfs_deregister() without calling target_fabric_configfs_free(). A large part of this patch is based on earlier changes from Bart Van Assche <[email protected]>. (v2: Add a new TF_CIT_SETUP_DRV macro so that the core configfs code can declare attributes as either core only or for drivers) Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
This commit is contained in:
parent
2c336e3a2e
commit
9ac8928e6a
25 changed files with 356 additions and 927 deletions
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
USB_GADGET_COMPOSITE_OPTIONS();
|
||||
|
||||
static struct target_fabric_configfs *usbg_fabric_configfs;
|
||||
static const struct target_core_fabric_ops usbg_ops;
|
||||
|
||||
static inline struct f_uas *to_f_uas(struct usb_function *f)
|
||||
{
|
||||
|
|
@ -1572,8 +1572,7 @@ static struct se_portal_group *usbg_make_tpg(
|
|||
tpg->tport = tport;
|
||||
tpg->tport_tpgt = tpgt;
|
||||
|
||||
ret = core_tpg_register(&usbg_fabric_configfs->tf_ops, wwn,
|
||||
&tpg->se_tpg, tpg,
|
||||
ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg, tpg,
|
||||
TRANSPORT_TPG_TYPE_NORMAL);
|
||||
if (ret < 0) {
|
||||
destroy_workqueue(tpg->workqueue);
|
||||
|
|
@ -1865,7 +1864,9 @@ static int usbg_check_stop_free(struct se_cmd *se_cmd)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static struct target_core_fabric_ops usbg_ops = {
|
||||
static const struct target_core_fabric_ops usbg_ops = {
|
||||
.module = THIS_MODULE,
|
||||
.name = "usb_gadget",
|
||||
.get_fabric_name = usbg_get_fabric_name,
|
||||
.get_fabric_proto_ident = usbg_get_fabric_proto_ident,
|
||||
.tpg_get_wwn = usbg_get_fabric_wwn,
|
||||
|
|
@ -1907,46 +1908,9 @@ static struct target_core_fabric_ops usbg_ops = {
|
|||
.fabric_drop_np = NULL,
|
||||
.fabric_make_nodeacl = usbg_make_nodeacl,
|
||||
.fabric_drop_nodeacl = usbg_drop_nodeacl,
|
||||
};
|
||||
|
||||
static int usbg_register_configfs(void)
|
||||
{
|
||||
struct target_fabric_configfs *fabric;
|
||||
int ret;
|
||||
|
||||
fabric = target_fabric_configfs_init(THIS_MODULE, "usb_gadget");
|
||||
if (IS_ERR(fabric)) {
|
||||
printk(KERN_ERR "target_fabric_configfs_init() failed\n");
|
||||
return PTR_ERR(fabric);
|
||||
}
|
||||
|
||||
fabric->tf_ops = usbg_ops;
|
||||
fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = usbg_wwn_attrs;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = usbg_base_attrs;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
|
||||
fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
|
||||
ret = target_fabric_configfs_register(fabric);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "target_fabric_configfs_register() failed"
|
||||
" for usb-gadget\n");
|
||||
return ret;
|
||||
}
|
||||
usbg_fabric_configfs = fabric;
|
||||
return 0;
|
||||
};
|
||||
|
||||
static void usbg_deregister_configfs(void)
|
||||
{
|
||||
if (!(usbg_fabric_configfs))
|
||||
return;
|
||||
|
||||
target_fabric_configfs_deregister(usbg_fabric_configfs);
|
||||
usbg_fabric_configfs = NULL;
|
||||
.tfc_wwn_attrs = usbg_wwn_attrs,
|
||||
.tfc_tpg_base_attrs = usbg_base_attrs,
|
||||
};
|
||||
|
||||
/* Start gadget.c code */
|
||||
|
|
@ -2455,16 +2419,13 @@ static void usbg_detach(struct usbg_tpg *tpg)
|
|||
|
||||
static int __init usb_target_gadget_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = usbg_register_configfs();
|
||||
return ret;
|
||||
return target_register_template(&usbg_ops);
|
||||
}
|
||||
module_init(usb_target_gadget_init);
|
||||
|
||||
static void __exit usb_target_gadget_exit(void)
|
||||
{
|
||||
usbg_deregister_configfs();
|
||||
target_unregister_template(&usbg_ops);
|
||||
}
|
||||
module_exit(usb_target_gadget_exit);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue