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

usb-gadget: 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
45b6a73f 870823e6

+119 -197
+114 -183
drivers/usb/gadget/configfs.c
··· 64 64 char qw_sign[OS_STRING_QW_SIGN_LEN]; 65 65 }; 66 66 67 + static inline struct gadget_info *to_gadget_info(struct config_item *item) 68 + { 69 + return container_of(to_config_group(item), struct gadget_info, group); 70 + } 71 + 67 72 struct config_usb_cfg { 68 73 struct config_group group; 69 74 struct config_group strings_group; ··· 78 73 struct list_head func_list; 79 74 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; 80 75 }; 76 + 77 + static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item) 78 + { 79 + return container_of(to_config_group(item), struct config_usb_cfg, 80 + group); 81 + } 81 82 82 83 struct gadget_strings { 83 84 struct usb_gadget_strings stringtab_dev; ··· 128 117 return 0; 129 118 } 130 119 131 - CONFIGFS_ATTR_STRUCT(gadget_info); 132 - CONFIGFS_ATTR_STRUCT(config_usb_cfg); 133 - 134 - #define GI_DEVICE_DESC_ITEM_ATTR(name) \ 135 - static struct gadget_info_attribute gadget_cdev_desc_##name = \ 136 - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ 137 - gadget_dev_desc_##name##_show, \ 138 - gadget_dev_desc_##name##_store) 139 - 140 120 #define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \ 141 - static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ 121 + static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ 142 122 char *page) \ 143 123 { \ 144 - return sprintf(page, "0x%02x\n", gi->cdev.desc.__name); \ 124 + return sprintf(page, "0x%02x\n", \ 125 + to_gadget_info(item)->cdev.desc.__name); \ 145 126 } 146 127 147 128 #define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \ 148 - static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ 129 + static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ 149 130 char *page) \ 150 131 { \ 151 - return sprintf(page, "0x%04x\n", le16_to_cpup(&gi->cdev.desc.__name)); \ 132 + return sprintf(page, "0x%04x\n", \ 133 + le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \ 152 134 } 153 135 154 136 155 137 #define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \ 156 - static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ 138 + static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ 157 139 const char *page, size_t len) \ 158 140 { \ 159 141 u8 val; \ ··· 154 150 ret = kstrtou8(page, 0, &val); \ 155 151 if (ret) \ 156 152 return ret; \ 157 - gi->cdev.desc._name = val; \ 153 + to_gadget_info(item)->cdev.desc._name = val; \ 158 154 return len; \ 159 155 } 160 156 161 157 #define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \ 162 - static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ 158 + static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ 163 159 const char *page, size_t len) \ 164 160 { \ 165 161 u16 val; \ ··· 167 163 ret = kstrtou16(page, 0, &val); \ 168 164 if (ret) \ 169 165 return ret; \ 170 - gi->cdev.desc._name = cpu_to_le16p(&val); \ 166 + to_gadget_info(item)->cdev.desc._name = cpu_to_le16p(&val); \ 171 167 return len; \ 172 168 } 173 169 ··· 197 193 return 0; 198 194 } 199 195 200 - static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi, 196 + static ssize_t gadget_dev_desc_bcdDevice_store(struct config_item *item, 201 197 const char *page, size_t len) 202 198 { 203 199 u16 bcdDevice; ··· 210 206 if (ret) 211 207 return ret; 212 208 213 - gi->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice); 209 + to_gadget_info(item)->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice); 214 210 return len; 215 211 } 216 212 217 - static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi, 213 + static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item, 218 214 const char *page, size_t len) 219 215 { 220 216 u16 bcdUSB; ··· 227 223 if (ret) 228 224 return ret; 229 225 230 - gi->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB); 226 + to_gadget_info(item)->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB); 231 227 return len; 232 228 } 233 229 234 - static ssize_t gadget_dev_desc_UDC_show(struct gadget_info *gi, char *page) 230 + static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page) 235 231 { 236 - return sprintf(page, "%s\n", gi->udc_name ?: ""); 232 + return sprintf(page, "%s\n", to_gadget_info(item)->udc_name ?: ""); 237 233 } 238 234 239 235 static int unregister_gadget(struct gadget_info *gi) ··· 251 247 return 0; 252 248 } 253 249 254 - static ssize_t gadget_dev_desc_UDC_store(struct gadget_info *gi, 250 + static ssize_t gadget_dev_desc_UDC_store(struct config_item *item, 255 251 const char *page, size_t len) 256 252 { 253 + struct gadget_info *gi = to_gadget_info(item); 257 254 char *name; 258 255 int ret; 259 256 ··· 288 283 return ret; 289 284 } 290 285 291 - GI_DEVICE_DESC_ITEM_ATTR(bDeviceClass); 292 - GI_DEVICE_DESC_ITEM_ATTR(bDeviceSubClass); 293 - GI_DEVICE_DESC_ITEM_ATTR(bDeviceProtocol); 294 - GI_DEVICE_DESC_ITEM_ATTR(bMaxPacketSize0); 295 - GI_DEVICE_DESC_ITEM_ATTR(idVendor); 296 - GI_DEVICE_DESC_ITEM_ATTR(idProduct); 297 - GI_DEVICE_DESC_ITEM_ATTR(bcdDevice); 298 - GI_DEVICE_DESC_ITEM_ATTR(bcdUSB); 299 - GI_DEVICE_DESC_ITEM_ATTR(UDC); 286 + CONFIGFS_ATTR(gadget_dev_desc_, bDeviceClass); 287 + CONFIGFS_ATTR(gadget_dev_desc_, bDeviceSubClass); 288 + CONFIGFS_ATTR(gadget_dev_desc_, bDeviceProtocol); 289 + CONFIGFS_ATTR(gadget_dev_desc_, bMaxPacketSize0); 290 + CONFIGFS_ATTR(gadget_dev_desc_, idVendor); 291 + CONFIGFS_ATTR(gadget_dev_desc_, idProduct); 292 + CONFIGFS_ATTR(gadget_dev_desc_, bcdDevice); 293 + CONFIGFS_ATTR(gadget_dev_desc_, bcdUSB); 294 + CONFIGFS_ATTR(gadget_dev_desc_, UDC); 300 295 301 296 static struct configfs_attribute *gadget_root_attrs[] = { 302 - &gadget_cdev_desc_bDeviceClass.attr, 303 - &gadget_cdev_desc_bDeviceSubClass.attr, 304 - &gadget_cdev_desc_bDeviceProtocol.attr, 305 - &gadget_cdev_desc_bMaxPacketSize0.attr, 306 - &gadget_cdev_desc_idVendor.attr, 307 - &gadget_cdev_desc_idProduct.attr, 308 - &gadget_cdev_desc_bcdDevice.attr, 309 - &gadget_cdev_desc_bcdUSB.attr, 310 - &gadget_cdev_desc_UDC.attr, 297 + &gadget_dev_desc_attr_bDeviceClass, 298 + &gadget_dev_desc_attr_bDeviceSubClass, 299 + &gadget_dev_desc_attr_bDeviceProtocol, 300 + &gadget_dev_desc_attr_bMaxPacketSize0, 301 + &gadget_dev_desc_attr_idVendor, 302 + &gadget_dev_desc_attr_idProduct, 303 + &gadget_dev_desc_attr_bcdDevice, 304 + &gadget_dev_desc_attr_bcdUSB, 305 + &gadget_dev_desc_attr_UDC, 311 306 NULL, 312 307 }; 313 - 314 - static inline struct gadget_info *to_gadget_info(struct config_item *item) 315 - { 316 - return container_of(to_config_group(item), struct gadget_info, group); 317 - } 318 308 319 309 static inline struct gadget_strings *to_gadget_strings(struct config_item *item) 320 310 { ··· 322 322 { 323 323 return container_of(to_config_group(item), struct gadget_config_name, 324 324 group); 325 - } 326 - 327 - static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item) 328 - { 329 - return container_of(to_config_group(item), struct config_usb_cfg, 330 - group); 331 325 } 332 326 333 327 static inline struct usb_function_instance *to_usb_function_instance( ··· 342 348 kfree(gi); 343 349 } 344 350 345 - CONFIGFS_ATTR_OPS(gadget_info); 346 - 347 351 static struct configfs_item_operations gadget_root_item_ops = { 348 352 .release = gadget_info_attr_release, 349 - .show_attribute = gadget_info_attr_show, 350 - .store_attribute = gadget_info_attr_store, 351 353 }; 352 354 353 355 static void gadget_config_attr_release(struct config_item *item) ··· 444 454 return 0; 445 455 } 446 456 447 - CONFIGFS_ATTR_OPS(config_usb_cfg); 448 - 449 457 static struct configfs_item_operations gadget_config_item_ops = { 450 458 .release = gadget_config_attr_release, 451 - .show_attribute = config_usb_cfg_attr_show, 452 - .store_attribute = config_usb_cfg_attr_store, 453 459 .allow_link = config_usb_cfg_link, 454 460 .drop_link = config_usb_cfg_unlink, 455 461 }; 456 462 457 463 458 - static ssize_t gadget_config_desc_MaxPower_show(struct config_usb_cfg *cfg, 464 + static ssize_t gadget_config_desc_MaxPower_show(struct config_item *item, 459 465 char *page) 460 466 { 461 - return sprintf(page, "%u\n", cfg->c.MaxPower); 467 + return sprintf(page, "%u\n", to_config_usb_cfg(item)->c.MaxPower); 462 468 } 463 469 464 - static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg, 470 + static ssize_t gadget_config_desc_MaxPower_store(struct config_item *item, 465 471 const char *page, size_t len) 466 472 { 467 473 u16 val; ··· 467 481 return ret; 468 482 if (DIV_ROUND_UP(val, 8) > 0xff) 469 483 return -ERANGE; 470 - cfg->c.MaxPower = val; 484 + to_config_usb_cfg(item)->c.MaxPower = val; 471 485 return len; 472 486 } 473 487 474 - static ssize_t gadget_config_desc_bmAttributes_show(struct config_usb_cfg *cfg, 488 + static ssize_t gadget_config_desc_bmAttributes_show(struct config_item *item, 475 489 char *page) 476 490 { 477 - return sprintf(page, "0x%02x\n", cfg->c.bmAttributes); 491 + return sprintf(page, "0x%02x\n", 492 + to_config_usb_cfg(item)->c.bmAttributes); 478 493 } 479 494 480 - static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg, 495 + static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item, 481 496 const char *page, size_t len) 482 497 { 483 498 u8 val; ··· 491 504 if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER | 492 505 USB_CONFIG_ATT_WAKEUP)) 493 506 return -EINVAL; 494 - cfg->c.bmAttributes = val; 507 + to_config_usb_cfg(item)->c.bmAttributes = val; 495 508 return len; 496 509 } 497 510 498 - #define CFG_CONFIG_DESC_ITEM_ATTR(name) \ 499 - static struct config_usb_cfg_attribute gadget_usb_cfg_##name = \ 500 - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ 501 - gadget_config_desc_##name##_show, \ 502 - gadget_config_desc_##name##_store) 503 - 504 - CFG_CONFIG_DESC_ITEM_ATTR(MaxPower); 505 - CFG_CONFIG_DESC_ITEM_ATTR(bmAttributes); 511 + CONFIGFS_ATTR(gadget_config_desc_, MaxPower); 512 + CONFIGFS_ATTR(gadget_config_desc_, bmAttributes); 506 513 507 514 static struct configfs_attribute *gadget_config_attrs[] = { 508 - &gadget_usb_cfg_MaxPower.attr, 509 - &gadget_usb_cfg_bmAttributes.attr, 515 + &gadget_config_desc_attr_MaxPower, 516 + &gadget_config_desc_attr_bmAttributes, 510 517 NULL, 511 518 }; 512 519 ··· 597 616 .ct_owner = THIS_MODULE, 598 617 }; 599 618 600 - CONFIGFS_ATTR_STRUCT(gadget_config_name); 601 619 GS_STRINGS_RW(gadget_config_name, configuration); 602 620 603 621 static struct configfs_attribute *gadget_config_name_langid_attrs[] = { 604 - &gadget_config_name_configuration.attr, 622 + &gadget_config_name_attr_configuration, 605 623 NULL, 606 624 }; 607 625 ··· 699 719 .ct_owner = THIS_MODULE, 700 720 }; 701 721 702 - CONFIGFS_ATTR_STRUCT(gadget_strings); 703 722 GS_STRINGS_RW(gadget_strings, manufacturer); 704 723 GS_STRINGS_RW(gadget_strings, product); 705 724 GS_STRINGS_RW(gadget_strings, serialnumber); 706 725 707 726 static struct configfs_attribute *gadget_strings_langid_attrs[] = { 708 - &gadget_strings_manufacturer.attr, 709 - &gadget_strings_product.attr, 710 - &gadget_strings_serialnumber.attr, 727 + &gadget_strings_attr_manufacturer, 728 + &gadget_strings_attr_product, 729 + &gadget_strings_attr_serialnumber, 711 730 NULL, 712 731 }; 713 732 ··· 730 751 return container_of(to_config_group(item), struct os_desc, group); 731 752 } 732 753 733 - CONFIGFS_ATTR_STRUCT(os_desc); 734 - CONFIGFS_ATTR_OPS(os_desc); 735 - 736 - static ssize_t os_desc_use_show(struct os_desc *os_desc, char *page) 754 + static inline struct gadget_info *os_desc_item_to_gadget_info( 755 + struct config_item *item) 737 756 { 738 - struct gadget_info *gi; 739 - 740 - gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 741 - 742 - return sprintf(page, "%d", gi->use_os_desc); 757 + return to_gadget_info(to_os_desc(item)->group.cg_item.ci_parent); 743 758 } 744 759 745 - static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page, 760 + static ssize_t os_desc_use_show(struct config_item *item, char *page) 761 + { 762 + return sprintf(page, "%d", 763 + os_desc_item_to_gadget_info(item)->use_os_desc); 764 + } 765 + 766 + static ssize_t os_desc_use_store(struct config_item *item, const char *page, 746 767 size_t len) 747 768 { 748 - struct gadget_info *gi; 769 + struct gadget_info *gi = os_desc_item_to_gadget_info(item); 749 770 int ret; 750 771 bool use; 751 - 752 - gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 753 772 754 773 mutex_lock(&gi->lock); 755 774 ret = strtobool(page, &use); ··· 760 783 return ret; 761 784 } 762 785 763 - static struct os_desc_attribute os_desc_use = 764 - __CONFIGFS_ATTR(use, S_IRUGO | S_IWUSR, 765 - os_desc_use_show, 766 - os_desc_use_store); 767 - 768 - static ssize_t os_desc_b_vendor_code_show(struct os_desc *os_desc, char *page) 786 + static ssize_t os_desc_b_vendor_code_show(struct config_item *item, char *page) 769 787 { 770 - struct gadget_info *gi; 771 - 772 - gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 773 - 774 - return sprintf(page, "%d", gi->b_vendor_code); 788 + return sprintf(page, "%d", 789 + os_desc_item_to_gadget_info(item)->b_vendor_code); 775 790 } 776 791 777 - static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc, 792 + static ssize_t os_desc_b_vendor_code_store(struct config_item *item, 778 793 const char *page, size_t len) 779 794 { 780 - struct gadget_info *gi; 795 + struct gadget_info *gi = os_desc_item_to_gadget_info(item); 781 796 int ret; 782 797 u8 b_vendor_code; 783 - 784 - gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 785 798 786 799 mutex_lock(&gi->lock); 787 800 ret = kstrtou8(page, 0, &b_vendor_code); ··· 784 817 return ret; 785 818 } 786 819 787 - static struct os_desc_attribute os_desc_b_vendor_code = 788 - __CONFIGFS_ATTR(b_vendor_code, S_IRUGO | S_IWUSR, 789 - os_desc_b_vendor_code_show, 790 - os_desc_b_vendor_code_store); 791 - 792 - static ssize_t os_desc_qw_sign_show(struct os_desc *os_desc, char *page) 820 + static ssize_t os_desc_qw_sign_show(struct config_item *item, char *page) 793 821 { 794 - struct gadget_info *gi; 795 - 796 - gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 822 + struct gadget_info *gi = os_desc_item_to_gadget_info(item); 797 823 798 824 memcpy(page, gi->qw_sign, OS_STRING_QW_SIGN_LEN); 799 - 800 825 return OS_STRING_QW_SIGN_LEN; 801 826 } 802 827 803 - static ssize_t os_desc_qw_sign_store(struct os_desc *os_desc, const char *page, 828 + static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page, 804 829 size_t len) 805 830 { 806 - struct gadget_info *gi; 831 + struct gadget_info *gi = os_desc_item_to_gadget_info(item); 807 832 int res, l; 808 833 809 - gi = to_gadget_info(os_desc->group.cg_item.ci_parent); 810 834 l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1); 811 835 if (page[l - 1] == '\n') 812 836 --l; ··· 813 855 return res; 814 856 } 815 857 816 - static struct os_desc_attribute os_desc_qw_sign = 817 - __CONFIGFS_ATTR(qw_sign, S_IRUGO | S_IWUSR, 818 - os_desc_qw_sign_show, 819 - os_desc_qw_sign_store); 858 + CONFIGFS_ATTR(os_desc_, use); 859 + CONFIGFS_ATTR(os_desc_, b_vendor_code); 860 + CONFIGFS_ATTR(os_desc_, qw_sign); 820 861 821 862 static struct configfs_attribute *os_desc_attrs[] = { 822 - &os_desc_use.attr, 823 - &os_desc_b_vendor_code.attr, 824 - &os_desc_qw_sign.attr, 863 + &os_desc_attr_use, 864 + &os_desc_attr_b_vendor_code, 865 + &os_desc_attr_qw_sign, 825 866 NULL, 826 867 }; 827 868 ··· 883 926 884 927 static struct configfs_item_operations os_desc_ops = { 885 928 .release = os_desc_attr_release, 886 - .show_attribute = os_desc_attr_show, 887 - .store_attribute = os_desc_attr_store, 888 929 .allow_link = os_desc_link, 889 930 .drop_link = os_desc_unlink, 890 931 }; ··· 893 938 .ct_owner = THIS_MODULE, 894 939 }; 895 940 896 - CONFIGFS_ATTR_STRUCT(usb_os_desc); 897 - CONFIGFS_ATTR_OPS(usb_os_desc); 898 - 899 - 900 941 static inline struct usb_os_desc_ext_prop 901 942 *to_usb_os_desc_ext_prop(struct config_item *item) 902 943 { 903 944 return container_of(item, struct usb_os_desc_ext_prop, item); 904 945 } 905 946 906 - CONFIGFS_ATTR_STRUCT(usb_os_desc_ext_prop); 907 - CONFIGFS_ATTR_OPS(usb_os_desc_ext_prop); 908 - 909 - static ssize_t ext_prop_type_show(struct usb_os_desc_ext_prop *ext_prop, 910 - char *page) 947 + static ssize_t ext_prop_type_show(struct config_item *item, char *page) 911 948 { 912 - return sprintf(page, "%d", ext_prop->type); 949 + return sprintf(page, "%d", to_usb_os_desc_ext_prop(item)->type); 913 950 } 914 951 915 - static ssize_t ext_prop_type_store(struct usb_os_desc_ext_prop *ext_prop, 952 + static ssize_t ext_prop_type_store(struct config_item *item, 916 953 const char *page, size_t len) 917 954 { 955 + struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); 918 956 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); 919 957 u8 type; 920 958 int ret; ··· 945 997 return ret; 946 998 } 947 999 948 - static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop, 949 - char *page) 1000 + static ssize_t ext_prop_data_show(struct config_item *item, char *page) 950 1001 { 1002 + struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); 951 1003 int len = ext_prop->data_len; 952 1004 953 1005 if (ext_prop->type == USB_EXT_PROP_UNICODE || ··· 959 1011 return len; 960 1012 } 961 1013 962 - static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop, 1014 + static ssize_t ext_prop_data_store(struct config_item *item, 963 1015 const char *page, size_t len) 964 1016 { 1017 + struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); 965 1018 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); 966 1019 char *new_data; 967 1020 size_t ret_len = len; ··· 993 1044 return ret_len; 994 1045 } 995 1046 996 - static struct usb_os_desc_ext_prop_attribute ext_prop_type = 997 - __CONFIGFS_ATTR(type, S_IRUGO | S_IWUSR, 998 - ext_prop_type_show, ext_prop_type_store); 999 - 1000 - static struct usb_os_desc_ext_prop_attribute ext_prop_data = 1001 - __CONFIGFS_ATTR(data, S_IRUGO | S_IWUSR, 1002 - ext_prop_data_show, ext_prop_data_store); 1047 + CONFIGFS_ATTR(ext_prop_, type); 1048 + CONFIGFS_ATTR(ext_prop_, data); 1003 1049 1004 1050 static struct configfs_attribute *ext_prop_attrs[] = { 1005 - &ext_prop_type.attr, 1006 - &ext_prop_data.attr, 1051 + &ext_prop_attr_type, 1052 + &ext_prop_attr_data, 1007 1053 NULL, 1008 1054 }; 1009 1055 ··· 1011 1067 1012 1068 static struct configfs_item_operations ext_prop_ops = { 1013 1069 .release = usb_os_desc_ext_prop_release, 1014 - .show_attribute = usb_os_desc_ext_prop_attr_show, 1015 - .store_attribute = usb_os_desc_ext_prop_attr_store, 1016 1070 }; 1017 1071 1018 1072 static struct config_item *ext_prop_make( ··· 1079 1137 .drop_item = &ext_prop_drop, 1080 1138 }; 1081 1139 1082 - static struct configfs_item_operations interf_item_ops = { 1083 - .show_attribute = usb_os_desc_attr_show, 1084 - .store_attribute = usb_os_desc_attr_store, 1085 - }; 1086 - 1087 - static ssize_t interf_grp_compatible_id_show(struct usb_os_desc *desc, 1140 + static ssize_t interf_grp_compatible_id_show(struct config_item *item, 1088 1141 char *page) 1089 1142 { 1090 - memcpy(page, desc->ext_compat_id, 8); 1143 + memcpy(page, to_usb_os_desc(item)->ext_compat_id, 8); 1091 1144 return 8; 1092 1145 } 1093 1146 1094 - static ssize_t interf_grp_compatible_id_store(struct usb_os_desc *desc, 1147 + static ssize_t interf_grp_compatible_id_store(struct config_item *item, 1095 1148 const char *page, size_t len) 1096 1149 { 1150 + struct usb_os_desc *desc = to_usb_os_desc(item); 1097 1151 int l; 1098 1152 1099 1153 l = min_t(int, 8, len); ··· 1105 1167 return len; 1106 1168 } 1107 1169 1108 - static struct usb_os_desc_attribute interf_grp_attr_compatible_id = 1109 - __CONFIGFS_ATTR(compatible_id, S_IRUGO | S_IWUSR, 1110 - interf_grp_compatible_id_show, 1111 - interf_grp_compatible_id_store); 1112 - 1113 - static ssize_t interf_grp_sub_compatible_id_show(struct usb_os_desc *desc, 1170 + static ssize_t interf_grp_sub_compatible_id_show(struct config_item *item, 1114 1171 char *page) 1115 1172 { 1116 - memcpy(page, desc->ext_compat_id + 8, 8); 1173 + memcpy(page, to_usb_os_desc(item)->ext_compat_id + 8, 8); 1117 1174 return 8; 1118 1175 } 1119 1176 1120 - static ssize_t interf_grp_sub_compatible_id_store(struct usb_os_desc *desc, 1177 + static ssize_t interf_grp_sub_compatible_id_store(struct config_item *item, 1121 1178 const char *page, size_t len) 1122 1179 { 1180 + struct usb_os_desc *desc = to_usb_os_desc(item); 1123 1181 int l; 1124 1182 1125 1183 l = min_t(int, 8, len); ··· 1131 1197 return len; 1132 1198 } 1133 1199 1134 - static struct usb_os_desc_attribute interf_grp_attr_sub_compatible_id = 1135 - __CONFIGFS_ATTR(sub_compatible_id, S_IRUGO | S_IWUSR, 1136 - interf_grp_sub_compatible_id_show, 1137 - interf_grp_sub_compatible_id_store); 1200 + CONFIGFS_ATTR(interf_grp_, compatible_id); 1201 + CONFIGFS_ATTR(interf_grp_, sub_compatible_id); 1138 1202 1139 1203 static struct configfs_attribute *interf_grp_attrs[] = { 1140 - &interf_grp_attr_compatible_id.attr, 1141 - &interf_grp_attr_sub_compatible_id.attr, 1204 + &interf_grp_attr_compatible_id, 1205 + &interf_grp_attr_sub_compatible_id, 1142 1206 NULL 1143 1207 }; 1144 1208 ··· 1174 1242 f_default_groups[0] = os_desc_group; 1175 1243 1176 1244 os_desc_group->default_groups = interface_groups; 1177 - interface_type->ct_item_ops = &interf_item_ops; 1178 1245 interface_type->ct_group_ops = &interf_grp_ops; 1179 1246 interface_type->ct_attrs = interf_grp_attrs; 1180 1247 interface_type->ct_owner = owner;
+5 -14
include/linux/usb/gadget_configfs.h
··· 7 7 struct usb_gadget_strings *stringtab_dev); 8 8 9 9 #define GS_STRINGS_W(__struct, __name) \ 10 - static ssize_t __struct##_##__name##_store(struct __struct *gs, \ 10 + static ssize_t __struct##_##__name##_store(struct config_item *item, \ 11 11 const char *page, size_t len) \ 12 12 { \ 13 + struct __struct *gs = to_##__struct(item); \ 13 14 int ret; \ 14 15 \ 15 16 ret = usb_string_copy(page, &gs->__name); \ ··· 20 19 } 21 20 22 21 #define GS_STRINGS_R(__struct, __name) \ 23 - static ssize_t __struct##_##__name##_show(struct __struct *gs, \ 24 - char *page) \ 22 + static ssize_t __struct##_##__name##_show(struct config_item *item, char *page) \ 25 23 { \ 24 + struct __struct *gs = to_##__struct(item); \ 26 25 return sprintf(page, "%s\n", gs->__name ?: ""); \ 27 26 } 28 - 29 - #define GS_STRING_ITEM_ATTR(struct_name, name) \ 30 - static struct struct_name##_attribute struct_name##_##name = \ 31 - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ 32 - struct_name##_##name##_show, \ 33 - struct_name##_##name##_store) 34 27 35 28 #define GS_STRINGS_RW(struct_name, _name) \ 36 29 GS_STRINGS_R(struct_name, _name) \ 37 30 GS_STRINGS_W(struct_name, _name) \ 38 - GS_STRING_ITEM_ATTR(struct_name, _name) 31 + CONFIGFS_ATTR(struct_name##_, _name) 39 32 40 33 #define USB_CONFIG_STRING_RW_OPS(struct_in) \ 41 - CONFIGFS_ATTR_OPS(struct_in); \ 42 - \ 43 34 static struct configfs_item_operations struct_in##_langid_item_ops = { \ 44 35 .release = struct_in##_attr_release, \ 45 - .show_attribute = struct_in##_attr_show, \ 46 - .store_attribute = struct_in##_attr_store, \ 47 36 }; \ 48 37 \ 49 38 static struct config_item_type struct_in##_langid_type = { \