USB: remove traces of urb->status from usbcore
[linux-2.6] / drivers / usb / core / sysfs.c
1 /*
2  * drivers/usb/core/sysfs.c
3  *
4  * (C) Copyright 2002 David Brownell
5  * (C) Copyright 2002,2004 Greg Kroah-Hartman
6  * (C) Copyright 2002,2004 IBM Corp.
7  *
8  * All of the sysfs file attributes for usb devices and interfaces.
9  *
10  */
11
12
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/usb.h>
16 #include "usb.h"
17
18 /* Active configuration fields */
19 #define usb_actconfig_show(field, multiplier, format_string)            \
20 static ssize_t  show_##field(struct device *dev,                        \
21                 struct device_attribute *attr, char *buf)               \
22 {                                                                       \
23         struct usb_device *udev;                                        \
24         struct usb_host_config *actconfig;                              \
25                                                                         \
26         udev = to_usb_device(dev);                                      \
27         actconfig = udev->actconfig;                                    \
28         if (actconfig)                                                  \
29                 return sprintf(buf, format_string,                      \
30                                 actconfig->desc.field * multiplier);    \
31         else                                                            \
32                 return 0;                                               \
33 }                                                                       \
34
35 #define usb_actconfig_attr(field, multiplier, format_string)            \
36 usb_actconfig_show(field, multiplier, format_string)                    \
37 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
38
39 usb_actconfig_attr(bNumInterfaces, 1, "%2d\n")
40 usb_actconfig_attr(bmAttributes, 1, "%2x\n")
41 usb_actconfig_attr(bMaxPower, 2, "%3dmA\n")
42
43 static ssize_t show_configuration_string(struct device *dev,
44                 struct device_attribute *attr, char *buf)
45 {
46         struct usb_device *udev;
47         struct usb_host_config *actconfig;
48
49         udev = to_usb_device(dev);
50         actconfig = udev->actconfig;
51         if ((!actconfig) || (!actconfig->string))
52                 return 0;
53         return sprintf(buf, "%s\n", actconfig->string);
54 }
55 static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL);
56
57 /* configuration value is always present, and r/w */
58 usb_actconfig_show(bConfigurationValue, 1, "%u\n");
59
60 static ssize_t
61 set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
62                 const char *buf, size_t count)
63 {
64         struct usb_device       *udev = to_usb_device(dev);
65         int                     config, value;
66
67         if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
68                 return -EINVAL;
69         usb_lock_device(udev);
70         value = usb_set_configuration(udev, config);
71         usb_unlock_device(udev);
72         return (value < 0) ? value : count;
73 }
74
75 static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR, 
76                 show_bConfigurationValue, set_bConfigurationValue);
77
78 /* String fields */
79 #define usb_string_attr(name)                                           \
80 static ssize_t  show_##name(struct device *dev,                         \
81                 struct device_attribute *attr, char *buf)               \
82 {                                                                       \
83         struct usb_device *udev;                                        \
84                                                                         \
85         udev = to_usb_device(dev);                                      \
86         return sprintf(buf, "%s\n", udev->name);                        \
87 }                                                                       \
88 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
89
90 usb_string_attr(product);
91 usb_string_attr(manufacturer);
92 usb_string_attr(serial);
93
94 static ssize_t
95 show_speed(struct device *dev, struct device_attribute *attr, char *buf)
96 {
97         struct usb_device *udev;
98         char *speed;
99
100         udev = to_usb_device(dev);
101
102         switch (udev->speed) {
103         case USB_SPEED_LOW:
104                 speed = "1.5";
105                 break;
106         case USB_SPEED_UNKNOWN:
107         case USB_SPEED_FULL:
108                 speed = "12";
109                 break;
110         case USB_SPEED_HIGH:
111                 speed = "480";
112                 break;
113         default:
114                 speed = "unknown";
115         }
116         return sprintf(buf, "%s\n", speed);
117 }
118 static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL);
119
120 static ssize_t
121 show_busnum(struct device *dev, struct device_attribute *attr, char *buf)
122 {
123         struct usb_device *udev;
124
125         udev = to_usb_device(dev);
126         return sprintf(buf, "%d\n", udev->bus->busnum);
127 }
128 static DEVICE_ATTR(busnum, S_IRUGO, show_busnum, NULL);
129
130 static ssize_t
131 show_devnum(struct device *dev, struct device_attribute *attr, char *buf)
132 {
133         struct usb_device *udev;
134
135         udev = to_usb_device(dev);
136         return sprintf(buf, "%d\n", udev->devnum);
137 }
138 static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL);
139
140 static ssize_t
141 show_version(struct device *dev, struct device_attribute *attr, char *buf)
142 {
143         struct usb_device *udev;
144         u16 bcdUSB;
145
146         udev = to_usb_device(dev);
147         bcdUSB = le16_to_cpu(udev->descriptor.bcdUSB);
148         return sprintf(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff);
149 }
150 static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
151
152 static ssize_t
153 show_maxchild(struct device *dev, struct device_attribute *attr, char *buf)
154 {
155         struct usb_device *udev;
156
157         udev = to_usb_device(dev);
158         return sprintf(buf, "%d\n", udev->maxchild);
159 }
160 static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
161
162 static ssize_t
163 show_quirks(struct device *dev, struct device_attribute *attr, char *buf)
164 {
165         struct usb_device *udev;
166
167         udev = to_usb_device(dev);
168         return sprintf(buf, "0x%x\n", udev->quirks);
169 }
170 static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL);
171
172
173 #if defined(CONFIG_USB_PERSIST) || defined(CONFIG_USB_SUSPEND)
174 static const char power_group[] = "power";
175 #endif
176
177 #ifdef  CONFIG_USB_PERSIST
178
179 static ssize_t
180 show_persist(struct device *dev, struct device_attribute *attr, char *buf)
181 {
182         struct usb_device *udev = to_usb_device(dev);
183
184         return sprintf(buf, "%d\n", udev->persist_enabled);
185 }
186
187 static ssize_t
188 set_persist(struct device *dev, struct device_attribute *attr,
189                 const char *buf, size_t count)
190 {
191         struct usb_device *udev = to_usb_device(dev);
192         int value;
193
194         /* Hubs are always enabled for USB_PERSIST */
195         if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
196                 return -EPERM;
197
198         if (sscanf(buf, "%d", &value) != 1)
199                 return -EINVAL;
200         usb_pm_lock(udev);
201         udev->persist_enabled = !!value;
202         usb_pm_unlock(udev);
203         return count;
204 }
205
206 static DEVICE_ATTR(persist, S_IRUGO | S_IWUSR, show_persist, set_persist);
207
208 static int add_persist_attributes(struct device *dev)
209 {
210         int rc = 0;
211
212         if (is_usb_device(dev)) {
213                 struct usb_device *udev = to_usb_device(dev);
214
215                 /* Hubs are automatically enabled for USB_PERSIST */
216                 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
217                         udev->persist_enabled = 1;
218                 rc = sysfs_add_file_to_group(&dev->kobj,
219                                 &dev_attr_persist.attr,
220                                 power_group);
221         }
222         return rc;
223 }
224
225 static void remove_persist_attributes(struct device *dev)
226 {
227         sysfs_remove_file_from_group(&dev->kobj,
228                         &dev_attr_persist.attr,
229                         power_group);
230 }
231
232 #else
233
234 #define add_persist_attributes(dev)     0
235 #define remove_persist_attributes(dev)  do {} while (0)
236
237 #endif  /* CONFIG_USB_PERSIST */
238
239 #ifdef  CONFIG_USB_SUSPEND
240
241 static ssize_t
242 show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
243 {
244         struct usb_device *udev = to_usb_device(dev);
245
246         return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ);
247 }
248
249 static ssize_t
250 set_autosuspend(struct device *dev, struct device_attribute *attr,
251                 const char *buf, size_t count)
252 {
253         struct usb_device *udev = to_usb_device(dev);
254         int value;
255
256         if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ ||
257                         value <= - INT_MAX/HZ)
258                 return -EINVAL;
259         value *= HZ;
260
261         udev->autosuspend_delay = value;
262         if (value >= 0)
263                 usb_try_autosuspend_device(udev);
264         else {
265                 if (usb_autoresume_device(udev) == 0)
266                         usb_autosuspend_device(udev);
267         }
268         return count;
269 }
270
271 static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
272                 show_autosuspend, set_autosuspend);
273
274 static const char on_string[] = "on";
275 static const char auto_string[] = "auto";
276 static const char suspend_string[] = "suspend";
277
278 static ssize_t
279 show_level(struct device *dev, struct device_attribute *attr, char *buf)
280 {
281         struct usb_device *udev = to_usb_device(dev);
282         const char *p = auto_string;
283
284         if (udev->state == USB_STATE_SUSPENDED) {
285                 if (udev->autoresume_disabled)
286                         p = suspend_string;
287         } else {
288                 if (udev->autosuspend_disabled)
289                         p = on_string;
290         }
291         return sprintf(buf, "%s\n", p);
292 }
293
294 static ssize_t
295 set_level(struct device *dev, struct device_attribute *attr,
296                 const char *buf, size_t count)
297 {
298         struct usb_device *udev = to_usb_device(dev);
299         int len = count;
300         char *cp;
301         int rc = 0;
302         int old_autosuspend_disabled, old_autoresume_disabled;
303
304         cp = memchr(buf, '\n', count);
305         if (cp)
306                 len = cp - buf;
307
308         usb_lock_device(udev);
309         old_autosuspend_disabled = udev->autosuspend_disabled;
310         old_autoresume_disabled = udev->autoresume_disabled;
311
312         /* Setting the flags without calling usb_pm_lock is a subject to
313          * races, but who cares...
314          */
315         if (len == sizeof on_string - 1 &&
316                         strncmp(buf, on_string, len) == 0) {
317                 udev->autosuspend_disabled = 1;
318                 udev->autoresume_disabled = 0;
319                 rc = usb_external_resume_device(udev);
320
321         } else if (len == sizeof auto_string - 1 &&
322                         strncmp(buf, auto_string, len) == 0) {
323                 udev->autosuspend_disabled = 0;
324                 udev->autoresume_disabled = 0;
325                 rc = usb_external_resume_device(udev);
326
327         } else if (len == sizeof suspend_string - 1 &&
328                         strncmp(buf, suspend_string, len) == 0) {
329                 udev->autosuspend_disabled = 0;
330                 udev->autoresume_disabled = 1;
331                 rc = usb_external_suspend_device(udev, PMSG_SUSPEND);
332
333         } else
334                 rc = -EINVAL;
335
336         if (rc) {
337                 udev->autosuspend_disabled = old_autosuspend_disabled;
338                 udev->autoresume_disabled = old_autoresume_disabled;
339         }
340         usb_unlock_device(udev);
341         return (rc < 0 ? rc : count);
342 }
343
344 static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level);
345
346 static int add_power_attributes(struct device *dev)
347 {
348         int rc = 0;
349
350         if (is_usb_device(dev)) {
351                 rc = sysfs_add_file_to_group(&dev->kobj,
352                                 &dev_attr_autosuspend.attr,
353                                 power_group);
354                 if (rc == 0)
355                         rc = sysfs_add_file_to_group(&dev->kobj,
356                                         &dev_attr_level.attr,
357                                         power_group);
358         }
359         return rc;
360 }
361
362 static void remove_power_attributes(struct device *dev)
363 {
364         sysfs_remove_file_from_group(&dev->kobj,
365                         &dev_attr_level.attr,
366                         power_group);
367         sysfs_remove_file_from_group(&dev->kobj,
368                         &dev_attr_autosuspend.attr,
369                         power_group);
370 }
371
372 #else
373
374 #define add_power_attributes(dev)       0
375 #define remove_power_attributes(dev)    do {} while (0)
376
377 #endif  /* CONFIG_USB_SUSPEND */
378
379
380 /* Descriptor fields */
381 #define usb_descriptor_attr_le16(field, format_string)                  \
382 static ssize_t                                                          \
383 show_##field(struct device *dev, struct device_attribute *attr, \
384                 char *buf)                                              \
385 {                                                                       \
386         struct usb_device *udev;                                        \
387                                                                         \
388         udev = to_usb_device(dev);                                      \
389         return sprintf(buf, format_string,                              \
390                         le16_to_cpu(udev->descriptor.field));           \
391 }                                                                       \
392 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
393
394 usb_descriptor_attr_le16(idVendor, "%04x\n")
395 usb_descriptor_attr_le16(idProduct, "%04x\n")
396 usb_descriptor_attr_le16(bcdDevice, "%04x\n")
397
398 #define usb_descriptor_attr(field, format_string)                       \
399 static ssize_t                                                          \
400 show_##field(struct device *dev, struct device_attribute *attr, \
401                 char *buf)                                              \
402 {                                                                       \
403         struct usb_device *udev;                                        \
404                                                                         \
405         udev = to_usb_device(dev);                                      \
406         return sprintf(buf, format_string, udev->descriptor.field);     \
407 }                                                                       \
408 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
409
410 usb_descriptor_attr(bDeviceClass, "%02x\n")
411 usb_descriptor_attr(bDeviceSubClass, "%02x\n")
412 usb_descriptor_attr(bDeviceProtocol, "%02x\n")
413 usb_descriptor_attr(bNumConfigurations, "%d\n")
414 usb_descriptor_attr(bMaxPacketSize0, "%d\n")
415
416
417
418 /* show if the device is authorized (1) or not (0) */
419 static ssize_t usb_dev_authorized_show(struct device *dev,
420                                        struct device_attribute *attr,
421                                        char *buf)
422 {
423         struct usb_device *usb_dev = to_usb_device(dev);
424         return snprintf(buf, PAGE_SIZE, "%u\n", usb_dev->authorized);
425 }
426
427
428 /*
429  * Authorize a device to be used in the system
430  *
431  * Writing a 0 deauthorizes the device, writing a 1 authorizes it.
432  */
433 static ssize_t usb_dev_authorized_store(struct device *dev,
434                                         struct device_attribute *attr,
435                                         const char *buf, size_t size)
436 {
437         ssize_t result;
438         struct usb_device *usb_dev = to_usb_device(dev);
439         unsigned val;
440         result = sscanf(buf, "%u\n", &val);
441         if (result != 1)
442                 result = -EINVAL;
443         else if (val == 0)
444                 result = usb_deauthorize_device(usb_dev);
445         else
446                 result = usb_authorize_device(usb_dev);
447         return result < 0? result : size;
448 }
449
450 static DEVICE_ATTR(authorized, 0644,
451             usb_dev_authorized_show, usb_dev_authorized_store);
452
453
454 static struct attribute *dev_attrs[] = {
455         /* current configuration's attributes */
456         &dev_attr_configuration.attr,
457         &dev_attr_bNumInterfaces.attr,
458         &dev_attr_bConfigurationValue.attr,
459         &dev_attr_bmAttributes.attr,
460         &dev_attr_bMaxPower.attr,
461         /* device attributes */
462         &dev_attr_idVendor.attr,
463         &dev_attr_idProduct.attr,
464         &dev_attr_bcdDevice.attr,
465         &dev_attr_bDeviceClass.attr,
466         &dev_attr_bDeviceSubClass.attr,
467         &dev_attr_bDeviceProtocol.attr,
468         &dev_attr_bNumConfigurations.attr,
469         &dev_attr_bMaxPacketSize0.attr,
470         &dev_attr_speed.attr,
471         &dev_attr_busnum.attr,
472         &dev_attr_devnum.attr,
473         &dev_attr_version.attr,
474         &dev_attr_maxchild.attr,
475         &dev_attr_quirks.attr,
476         &dev_attr_authorized.attr,
477         NULL,
478 };
479 static struct attribute_group dev_attr_grp = {
480         .attrs = dev_attrs,
481 };
482
483 /* Binary descriptors */
484
485 static ssize_t
486 read_descriptors(struct kobject *kobj, struct bin_attribute *attr,
487                 char *buf, loff_t off, size_t count)
488 {
489         struct usb_device *udev = to_usb_device(
490                         container_of(kobj, struct device, kobj));
491         size_t nleft = count;
492         size_t srclen, n;
493
494         usb_lock_device(udev);
495
496         /* The binary attribute begins with the device descriptor */
497         srclen = sizeof(struct usb_device_descriptor);
498         if (off < srclen) {
499                 n = min_t(size_t, nleft, srclen - off);
500                 memcpy(buf, off + (char *) &udev->descriptor, n);
501                 nleft -= n;
502                 buf += n;
503                 off = 0;
504         } else {
505                 off -= srclen;
506         }
507
508         /* Then follows the raw descriptor entry for the current
509          * configuration (config plus subsidiary descriptors).
510          */
511         if (udev->actconfig) {
512                 int cfgno = udev->actconfig - udev->config;
513
514                 srclen = __le16_to_cpu(udev->actconfig->desc.wTotalLength);
515                 if (off < srclen) {
516                         n = min_t(size_t, nleft, srclen - off);
517                         memcpy(buf, off + udev->rawdescriptors[cfgno], n);
518                         nleft -= n;
519                 }
520         }
521         usb_unlock_device(udev);
522         return count - nleft;
523 }
524
525 static struct bin_attribute dev_bin_attr_descriptors = {
526         .attr = {.name = "descriptors", .mode = 0444},
527         .read = read_descriptors,
528         .size = 18 + 65535,     /* dev descr + max-size raw descriptor */
529 };
530
531 int usb_create_sysfs_dev_files(struct usb_device *udev)
532 {
533         struct device *dev = &udev->dev;
534         int retval;
535
536         retval = sysfs_create_group(&dev->kobj, &dev_attr_grp);
537         if (retval)
538                 return retval;
539
540         retval = device_create_bin_file(dev, &dev_bin_attr_descriptors);
541         if (retval)
542                 goto error;
543
544         retval = add_persist_attributes(dev);
545         if (retval)
546                 goto error;
547
548         retval = add_power_attributes(dev);
549         if (retval)
550                 goto error;
551
552         if (udev->manufacturer) {
553                 retval = device_create_file(dev, &dev_attr_manufacturer);
554                 if (retval)
555                         goto error;
556         }
557         if (udev->product) {
558                 retval = device_create_file(dev, &dev_attr_product);
559                 if (retval)
560                         goto error;
561         }
562         if (udev->serial) {
563                 retval = device_create_file(dev, &dev_attr_serial);
564                 if (retval)
565                         goto error;
566         }
567         retval = usb_create_ep_files(dev, &udev->ep0, udev);
568         if (retval)
569                 goto error;
570         return 0;
571 error:
572         usb_remove_sysfs_dev_files(udev);
573         return retval;
574 }
575
576 void usb_remove_sysfs_dev_files(struct usb_device *udev)
577 {
578         struct device *dev = &udev->dev;
579
580         usb_remove_ep_files(&udev->ep0);
581         device_remove_file(dev, &dev_attr_manufacturer);
582         device_remove_file(dev, &dev_attr_product);
583         device_remove_file(dev, &dev_attr_serial);
584         remove_power_attributes(dev);
585         remove_persist_attributes(dev);
586         device_remove_bin_file(dev, &dev_bin_attr_descriptors);
587         sysfs_remove_group(&dev->kobj, &dev_attr_grp);
588 }
589
590 /* Interface Accociation Descriptor fields */
591 #define usb_intf_assoc_attr(field, format_string)                       \
592 static ssize_t                                                          \
593 show_iad_##field (struct device *dev, struct device_attribute *attr,    \
594                 char *buf)                                              \
595 {                                                                       \
596         struct usb_interface *intf = to_usb_interface (dev);            \
597                                                                         \
598         return sprintf (buf, format_string,                             \
599                         intf->intf_assoc->field);               \
600 }                                                                       \
601 static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL);
602
603 usb_intf_assoc_attr (bFirstInterface, "%02x\n")
604 usb_intf_assoc_attr (bInterfaceCount, "%02d\n")
605 usb_intf_assoc_attr (bFunctionClass, "%02x\n")
606 usb_intf_assoc_attr (bFunctionSubClass, "%02x\n")
607 usb_intf_assoc_attr (bFunctionProtocol, "%02x\n")
608
609 /* Interface fields */
610 #define usb_intf_attr(field, format_string)                             \
611 static ssize_t                                                          \
612 show_##field(struct device *dev, struct device_attribute *attr, \
613                 char *buf)                                              \
614 {                                                                       \
615         struct usb_interface *intf = to_usb_interface(dev);             \
616                                                                         \
617         return sprintf(buf, format_string,                              \
618                         intf->cur_altsetting->desc.field);              \
619 }                                                                       \
620 static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
621
622 usb_intf_attr(bInterfaceNumber, "%02x\n")
623 usb_intf_attr(bAlternateSetting, "%2d\n")
624 usb_intf_attr(bNumEndpoints, "%02x\n")
625 usb_intf_attr(bInterfaceClass, "%02x\n")
626 usb_intf_attr(bInterfaceSubClass, "%02x\n")
627 usb_intf_attr(bInterfaceProtocol, "%02x\n")
628
629 static ssize_t show_interface_string(struct device *dev,
630                 struct device_attribute *attr, char *buf)
631 {
632         struct usb_interface *intf;
633         struct usb_device *udev;
634         int len;
635
636         intf = to_usb_interface(dev);
637         udev = interface_to_usbdev(intf);
638         len = snprintf(buf, 256, "%s", intf->cur_altsetting->string);
639         if (len < 0)
640                 return 0;
641         buf[len] = '\n';
642         buf[len+1] = 0;
643         return len+1;
644 }
645 static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL);
646
647 static ssize_t show_modalias(struct device *dev,
648                 struct device_attribute *attr, char *buf)
649 {
650         struct usb_interface *intf;
651         struct usb_device *udev;
652         struct usb_host_interface *alt;
653
654         intf = to_usb_interface(dev);
655         udev = interface_to_usbdev(intf);
656         alt = intf->cur_altsetting;
657
658         return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
659                         "ic%02Xisc%02Xip%02X\n",
660                         le16_to_cpu(udev->descriptor.idVendor),
661                         le16_to_cpu(udev->descriptor.idProduct),
662                         le16_to_cpu(udev->descriptor.bcdDevice),
663                         udev->descriptor.bDeviceClass,
664                         udev->descriptor.bDeviceSubClass,
665                         udev->descriptor.bDeviceProtocol,
666                         alt->desc.bInterfaceClass,
667                         alt->desc.bInterfaceSubClass,
668                         alt->desc.bInterfaceProtocol);
669 }
670 static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
671
672 static struct attribute *intf_assoc_attrs[] = {
673         &dev_attr_iad_bFirstInterface.attr,
674         &dev_attr_iad_bInterfaceCount.attr,
675         &dev_attr_iad_bFunctionClass.attr,
676         &dev_attr_iad_bFunctionSubClass.attr,
677         &dev_attr_iad_bFunctionProtocol.attr,
678         NULL,
679 };
680 static struct attribute_group intf_assoc_attr_grp = {
681         .attrs = intf_assoc_attrs,
682 };
683
684 static struct attribute *intf_attrs[] = {
685         &dev_attr_bInterfaceNumber.attr,
686         &dev_attr_bAlternateSetting.attr,
687         &dev_attr_bNumEndpoints.attr,
688         &dev_attr_bInterfaceClass.attr,
689         &dev_attr_bInterfaceSubClass.attr,
690         &dev_attr_bInterfaceProtocol.attr,
691         &dev_attr_modalias.attr,
692         NULL,
693 };
694 static struct attribute_group intf_attr_grp = {
695         .attrs = intf_attrs,
696 };
697
698 static inline void usb_create_intf_ep_files(struct usb_interface *intf,
699                 struct usb_device *udev)
700 {
701         struct usb_host_interface *iface_desc;
702         int i;
703
704         iface_desc = intf->cur_altsetting;
705         for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
706                 usb_create_ep_files(&intf->dev, &iface_desc->endpoint[i],
707                                 udev);
708 }
709
710 static inline void usb_remove_intf_ep_files(struct usb_interface *intf)
711 {
712         struct usb_host_interface *iface_desc;
713         int i;
714
715         iface_desc = intf->cur_altsetting;
716         for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
717                 usb_remove_ep_files(&iface_desc->endpoint[i]);
718 }
719
720 int usb_create_sysfs_intf_files(struct usb_interface *intf)
721 {
722         struct device *dev = &intf->dev;
723         struct usb_device *udev = interface_to_usbdev(intf);
724         struct usb_host_interface *alt = intf->cur_altsetting;
725         int retval;
726
727         retval = sysfs_create_group(&dev->kobj, &intf_attr_grp);
728         if (retval)
729                 return retval;
730
731         if (alt->string == NULL)
732                 alt->string = usb_cache_string(udev, alt->desc.iInterface);
733         if (alt->string)
734                 retval = device_create_file(dev, &dev_attr_interface);
735         if (intf->intf_assoc)
736                 retval = sysfs_create_group(&dev->kobj, &intf_assoc_attr_grp);
737         usb_create_intf_ep_files(intf, udev);
738         return 0;
739 }
740
741 void usb_remove_sysfs_intf_files(struct usb_interface *intf)
742 {
743         struct device *dev = &intf->dev;
744
745         usb_remove_intf_ep_files(intf);
746         device_remove_file(dev, &dev_attr_interface);
747         sysfs_remove_group(&dev->kobj, &intf_attr_grp);
748         sysfs_remove_group(&intf->dev.kobj, &intf_assoc_attr_grp);
749 }