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