Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb-gadget/ether: use per-attribute show and store methods

To simplify the configfs interface and remove boilerplate code that also
causes binary bloat.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Acked-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Christoph Hellwig and committed by
Nicholas Bellinger
f9a63da3 ea6bd6b1

+38 -46
+4 -4
drivers/usb/gadget/function/f_ecm.c
··· 855 855 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ecm); 856 856 857 857 static struct configfs_attribute *ecm_attrs[] = { 858 - &f_ecm_opts_dev_addr.attr, 859 - &f_ecm_opts_host_addr.attr, 860 - &f_ecm_opts_qmult.attr, 861 - &f_ecm_opts_ifname.attr, 858 + &ecm_opts_attr_dev_addr, 859 + &ecm_opts_attr_host_addr, 860 + &ecm_opts_attr_qmult, 861 + &ecm_opts_attr_ifname, 862 862 NULL, 863 863 }; 864 864
+4 -4
drivers/usb/gadget/function/f_eem.c
··· 555 555 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(eem); 556 556 557 557 static struct configfs_attribute *eem_attrs[] = { 558 - &f_eem_opts_dev_addr.attr, 559 - &f_eem_opts_host_addr.attr, 560 - &f_eem_opts_qmult.attr, 561 - &f_eem_opts_ifname.attr, 558 + &eem_opts_attr_dev_addr, 559 + &eem_opts_attr_host_addr, 560 + &eem_opts_attr_qmult, 561 + &eem_opts_attr_ifname, 562 562 NULL, 563 563 }; 564 564
+4 -4
drivers/usb/gadget/function/f_ncm.c
··· 1503 1503 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm); 1504 1504 1505 1505 static struct configfs_attribute *ncm_attrs[] = { 1506 - &f_ncm_opts_dev_addr.attr, 1507 - &f_ncm_opts_host_addr.attr, 1508 - &f_ncm_opts_qmult.attr, 1509 - &f_ncm_opts_ifname.attr, 1506 + &ncm_opts_attr_dev_addr, 1507 + &ncm_opts_attr_host_addr, 1508 + &ncm_opts_attr_qmult, 1509 + &ncm_opts_attr_ifname, 1510 1510 NULL, 1511 1511 }; 1512 1512
+4 -4
drivers/usb/gadget/function/f_rndis.c
··· 878 878 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis); 879 879 880 880 static struct configfs_attribute *rndis_attrs[] = { 881 - &f_rndis_opts_dev_addr.attr, 882 - &f_rndis_opts_host_addr.attr, 883 - &f_rndis_opts_qmult.attr, 884 - &f_rndis_opts_ifname.attr, 881 + &rndis_opts_attr_dev_addr, 882 + &rndis_opts_attr_host_addr, 883 + &rndis_opts_attr_qmult, 884 + &rndis_opts_attr_ifname, 885 885 NULL, 886 886 }; 887 887
+4 -4
drivers/usb/gadget/function/f_subset.c
··· 413 413 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(gether); 414 414 415 415 static struct configfs_attribute *gether_attrs[] = { 416 - &f_gether_opts_dev_addr.attr, 417 - &f_gether_opts_host_addr.attr, 418 - &f_gether_opts_qmult.attr, 419 - &f_gether_opts_ifname.attr, 416 + &gether_opts_attr_dev_addr, 417 + &gether_opts_attr_host_addr, 418 + &gether_opts_attr_qmult, 419 + &gether_opts_attr_ifname, 420 420 NULL, 421 421 }; 422 422
+18 -26
drivers/usb/gadget/function/u_ether_configfs.h
··· 17 17 #define __U_ETHER_CONFIGFS_H 18 18 19 19 #define USB_ETHERNET_CONFIGFS_ITEM(_f_) \ 20 - CONFIGFS_ATTR_STRUCT(f_##_f_##_opts); \ 21 - CONFIGFS_ATTR_OPS(f_##_f_##_opts); \ 22 - \ 23 20 static void _f_##_attr_release(struct config_item *item) \ 24 21 { \ 25 22 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ ··· 26 29 \ 27 30 static struct configfs_item_operations _f_##_item_ops = { \ 28 31 .release = _f_##_attr_release, \ 29 - .show_attribute = f_##_f_##_opts_attr_show, \ 30 - .store_attribute = f_##_f_##_opts_attr_store, \ 31 32 } 32 33 33 34 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(_f_) \ 34 - static ssize_t _f_##_opts_dev_addr_show(struct f_##_f_##_opts *opts, \ 35 + static ssize_t _f_##_opts_dev_addr_show(struct config_item *item, \ 35 36 char *page) \ 36 37 { \ 38 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 37 39 int result; \ 38 40 \ 39 41 mutex_lock(&opts->lock); \ ··· 42 46 return result; \ 43 47 } \ 44 48 \ 45 - static ssize_t _f_##_opts_dev_addr_store(struct f_##_f_##_opts *opts, \ 49 + static ssize_t _f_##_opts_dev_addr_store(struct config_item *item, \ 46 50 const char *page, size_t len)\ 47 51 { \ 52 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 48 53 int ret; \ 49 54 \ 50 55 mutex_lock(&opts->lock); \ ··· 61 64 return ret; \ 62 65 } \ 63 66 \ 64 - static struct f_##_f_##_opts_attribute f_##_f_##_opts_dev_addr = \ 65 - __CONFIGFS_ATTR(dev_addr, S_IRUGO | S_IWUSR, \ 66 - _f_##_opts_dev_addr_show, \ 67 - _f_##_opts_dev_addr_store) 67 + CONFIGFS_ATTR(_f_##_opts_, dev_addr) 68 68 69 69 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(_f_) \ 70 - static ssize_t _f_##_opts_host_addr_show(struct f_##_f_##_opts *opts, \ 70 + static ssize_t _f_##_opts_host_addr_show(struct config_item *item, \ 71 71 char *page) \ 72 72 { \ 73 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 73 74 int result; \ 74 75 \ 75 76 mutex_lock(&opts->lock); \ ··· 77 82 return result; \ 78 83 } \ 79 84 \ 80 - static ssize_t _f_##_opts_host_addr_store(struct f_##_f_##_opts *opts, \ 85 + static ssize_t _f_##_opts_host_addr_store(struct config_item *item, \ 81 86 const char *page, size_t len)\ 82 87 { \ 88 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 83 89 int ret; \ 84 90 \ 85 91 mutex_lock(&opts->lock); \ ··· 96 100 return ret; \ 97 101 } \ 98 102 \ 99 - static struct f_##_f_##_opts_attribute f_##_f_##_opts_host_addr = \ 100 - __CONFIGFS_ATTR(host_addr, S_IRUGO | S_IWUSR, \ 101 - _f_##_opts_host_addr_show, \ 102 - _f_##_opts_host_addr_store) 103 + CONFIGFS_ATTR(_f_##_opts_, host_addr) 103 104 104 105 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(_f_) \ 105 - static ssize_t _f_##_opts_qmult_show(struct f_##_f_##_opts *opts, \ 106 + static ssize_t _f_##_opts_qmult_show(struct config_item *item, \ 106 107 char *page) \ 107 108 { \ 109 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 108 110 unsigned qmult; \ 109 111 \ 110 112 mutex_lock(&opts->lock); \ ··· 111 117 return sprintf(page, "%d", qmult); \ 112 118 } \ 113 119 \ 114 - static ssize_t _f_##_opts_qmult_store(struct f_##_f_##_opts *opts, \ 120 + static ssize_t _f_##_opts_qmult_store(struct config_item *item, \ 115 121 const char *page, size_t len)\ 116 122 { \ 123 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 117 124 u8 val; \ 118 125 int ret; \ 119 126 \ ··· 135 140 return ret; \ 136 141 } \ 137 142 \ 138 - static struct f_##_f_##_opts_attribute f_##_f_##_opts_qmult = \ 139 - __CONFIGFS_ATTR(qmult, S_IRUGO | S_IWUSR, \ 140 - _f_##_opts_qmult_show, \ 141 - _f_##_opts_qmult_store) 143 + CONFIGFS_ATTR(_f_##_opts_, qmult) 142 144 143 145 #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(_f_) \ 144 - static ssize_t _f_##_opts_ifname_show(struct f_##_f_##_opts *opts, \ 146 + static ssize_t _f_##_opts_ifname_show(struct config_item *item, \ 145 147 char *page) \ 146 148 { \ 149 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 147 150 int ret; \ 148 151 \ 149 152 mutex_lock(&opts->lock); \ ··· 151 158 return ret; \ 152 159 } \ 153 160 \ 154 - static struct f_##_f_##_opts_attribute f_##_f_##_opts_ifname = \ 155 - __CONFIGFS_ATTR_RO(ifname, _f_##_opts_ifname_show) 161 + CONFIGFS_ATTR_RO(_f_##_opts_, ifname) 156 162 157 163 #endif /* __U_ETHER_CONFIGFS_H */