diff options
| author | Christoph Hellwig <hch@lst.de> | 2015-04-08 14:01:35 -0400 |
|---|---|---|
| committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2015-04-14 15:28:41 -0400 |
| commit | 9ac8928e6a3e1ed02e632e45aa766129fe6b1802 (patch) | |
| tree | ea516680cc5f811df862966bb43cfbe3e34dfb26 /drivers/usb/gadget | |
| parent | 2c336e3a2e1728d9b3116422655832184dc7046c (diff) | |
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 <bart.vanassche@sandisk.com>.
(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 <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/usb/gadget')
| -rw-r--r-- | drivers/usb/gadget/legacy/tcm_usb_gadget.c | 57 |
1 files changed, 9 insertions, 48 deletions
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c index 3a494168661e..7ea2a44cb228 100644 --- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c +++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c | |||
| @@ -29,7 +29,7 @@ | |||
| 29 | 29 | ||
| 30 | USB_GADGET_COMPOSITE_OPTIONS(); | 30 | USB_GADGET_COMPOSITE_OPTIONS(); |
| 31 | 31 | ||
| 32 | static struct target_fabric_configfs *usbg_fabric_configfs; | 32 | static const struct target_core_fabric_ops usbg_ops; |
| 33 | 33 | ||
| 34 | static inline struct f_uas *to_f_uas(struct usb_function *f) | 34 | static inline struct f_uas *to_f_uas(struct usb_function *f) |
| 35 | { | 35 | { |
| @@ -1572,8 +1572,7 @@ static struct se_portal_group *usbg_make_tpg( | |||
| 1572 | tpg->tport = tport; | 1572 | tpg->tport = tport; |
| 1573 | tpg->tport_tpgt = tpgt; | 1573 | tpg->tport_tpgt = tpgt; |
| 1574 | 1574 | ||
| 1575 | ret = core_tpg_register(&usbg_fabric_configfs->tf_ops, wwn, | 1575 | ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg, tpg, |
| 1576 | &tpg->se_tpg, tpg, | ||
| 1577 | TRANSPORT_TPG_TYPE_NORMAL); | 1576 | TRANSPORT_TPG_TYPE_NORMAL); |
| 1578 | if (ret < 0) { | 1577 | if (ret < 0) { |
| 1579 | destroy_workqueue(tpg->workqueue); | 1578 | destroy_workqueue(tpg->workqueue); |
| @@ -1865,7 +1864,9 @@ static int usbg_check_stop_free(struct se_cmd *se_cmd) | |||
| 1865 | return 1; | 1864 | return 1; |
| 1866 | } | 1865 | } |
| 1867 | 1866 | ||
| 1868 | static struct target_core_fabric_ops usbg_ops = { | 1867 | static const struct target_core_fabric_ops usbg_ops = { |
| 1868 | .module = THIS_MODULE, | ||
| 1869 | .name = "usb_gadget", | ||
| 1869 | .get_fabric_name = usbg_get_fabric_name, | 1870 | .get_fabric_name = usbg_get_fabric_name, |
| 1870 | .get_fabric_proto_ident = usbg_get_fabric_proto_ident, | 1871 | .get_fabric_proto_ident = usbg_get_fabric_proto_ident, |
| 1871 | .tpg_get_wwn = usbg_get_fabric_wwn, | 1872 | .tpg_get_wwn = usbg_get_fabric_wwn, |
| @@ -1907,46 +1908,9 @@ static struct target_core_fabric_ops usbg_ops = { | |||
| 1907 | .fabric_drop_np = NULL, | 1908 | .fabric_drop_np = NULL, |
| 1908 | .fabric_make_nodeacl = usbg_make_nodeacl, | 1909 | .fabric_make_nodeacl = usbg_make_nodeacl, |
| 1909 | .fabric_drop_nodeacl = usbg_drop_nodeacl, | 1910 | .fabric_drop_nodeacl = usbg_drop_nodeacl, |
| 1910 | }; | ||
| 1911 | |||
| 1912 | static int usbg_register_configfs(void) | ||
| 1913 | { | ||
| 1914 | struct target_fabric_configfs *fabric; | ||
| 1915 | int ret; | ||
| 1916 | |||
| 1917 | fabric = target_fabric_configfs_init(THIS_MODULE, "usb_gadget"); | ||
| 1918 | if (IS_ERR(fabric)) { | ||
| 1919 | printk(KERN_ERR "target_fabric_configfs_init() failed\n"); | ||
| 1920 | return PTR_ERR(fabric); | ||
| 1921 | } | ||
| 1922 | |||
| 1923 | fabric->tf_ops = usbg_ops; | ||
| 1924 | fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = usbg_wwn_attrs; | ||
| 1925 | fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = usbg_base_attrs; | ||
| 1926 | fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; | ||
| 1927 | fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; | ||
| 1928 | fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; | ||
| 1929 | fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL; | ||
| 1930 | fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL; | ||
| 1931 | fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL; | ||
| 1932 | fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL; | ||
| 1933 | ret = target_fabric_configfs_register(fabric); | ||
| 1934 | if (ret < 0) { | ||
| 1935 | printk(KERN_ERR "target_fabric_configfs_register() failed" | ||
| 1936 | " for usb-gadget\n"); | ||
| 1937 | return ret; | ||
| 1938 | } | ||
| 1939 | usbg_fabric_configfs = fabric; | ||
| 1940 | return 0; | ||
| 1941 | }; | ||
| 1942 | 1911 | ||
| 1943 | static void usbg_deregister_configfs(void) | 1912 | .tfc_wwn_attrs = usbg_wwn_attrs, |
| 1944 | { | 1913 | .tfc_tpg_base_attrs = usbg_base_attrs, |
| 1945 | if (!(usbg_fabric_configfs)) | ||
| 1946 | return; | ||
| 1947 | |||
| 1948 | target_fabric_configfs_deregister(usbg_fabric_configfs); | ||
| 1949 | usbg_fabric_configfs = NULL; | ||
| 1950 | }; | 1914 | }; |
| 1951 | 1915 | ||
| 1952 | /* Start gadget.c code */ | 1916 | /* Start gadget.c code */ |
| @@ -2455,16 +2419,13 @@ static void usbg_detach(struct usbg_tpg *tpg) | |||
| 2455 | 2419 | ||
| 2456 | static int __init usb_target_gadget_init(void) | 2420 | static int __init usb_target_gadget_init(void) |
| 2457 | { | 2421 | { |
| 2458 | int ret; | 2422 | return target_register_template(&usbg_ops); |
| 2459 | |||
| 2460 | ret = usbg_register_configfs(); | ||
| 2461 | return ret; | ||
| 2462 | } | 2423 | } |
| 2463 | module_init(usb_target_gadget_init); | 2424 | module_init(usb_target_gadget_init); |
| 2464 | 2425 | ||
| 2465 | static void __exit usb_target_gadget_exit(void) | 2426 | static void __exit usb_target_gadget_exit(void) |
| 2466 | { | 2427 | { |
| 2467 | usbg_deregister_configfs(); | 2428 | target_unregister_template(&usbg_ops); |
| 2468 | } | 2429 | } |
| 2469 | module_exit(usb_target_gadget_exit); | 2430 | module_exit(usb_target_gadget_exit); |
| 2470 | 2431 | ||
