The hub is always supposed to support reset and its persist is enabled.
So hub doesn't need attribute avoid_reset_quirk. The patch is to take
attribute avoid_reset_quirk out of usb device's attribute group and
add or remove it in the usb_create/remove_sysfs_dev_files() if the device
is not a usb hub.

Signed-off-by: Lan Tianyu <tianyu....@intel.com>
---
 drivers/usb/core/sysfs.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index d6c49d9..20b0add 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -220,6 +220,30 @@ set_avoid_reset_quirk(struct device *dev, struct 
device_attribute *attr,
 static DEVICE_ATTR(avoid_reset_quirk, S_IRUGO | S_IWUSR,
                show_avoid_reset_quirk, set_avoid_reset_quirk);
 
+static int add_avoid_reset_quirk_attributes(struct device *dev)
+{
+       int rc = 0;
+
+       if (is_usb_device(dev)) {
+               struct usb_device *udev = to_usb_device(dev);
+
+               /* Hubs don't need avoid_reset_quirk attribute. */
+               if (udev->descriptor.bDeviceClass != USB_CLASS_HUB)
+                       rc = sysfs_add_file_to_group(&dev->kobj,
+                                       &dev_attr_avoid_reset_quirk.attr,
+                                       NULL);
+       }
+       return rc;
+}
+
+static void remove_avoid_reset_quirk_attributes(struct device *dev)
+{
+       sysfs_remove_file_from_group(&dev->kobj,
+                       &dev_attr_avoid_reset_quirk.attr,
+                       NULL);
+}
+
+
 static ssize_t
 show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -654,7 +678,6 @@ static struct attribute *dev_attrs[] = {
        &dev_attr_version.attr,
        &dev_attr_maxchild.attr,
        &dev_attr_quirks.attr,
-       &dev_attr_avoid_reset_quirk.attr,
        &dev_attr_authorized.attr,
        &dev_attr_remove.attr,
        &dev_attr_removable.attr,
@@ -768,6 +791,10 @@ int usb_create_sysfs_dev_files(struct usb_device *udev)
        retval = add_power_attributes(dev);
        if (retval)
                goto error;
+
+       retval = add_avoid_reset_quirk_attributes(dev);
+       if (retval)
+               goto error;
        return retval;
 error:
        usb_remove_sysfs_dev_files(udev);
@@ -778,6 +805,7 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev)
 {
        struct device *dev = &udev->dev;
 
+       remove_avoid_reset_quirk_attributes(dev);
        remove_power_attributes(dev);
        remove_persist_attributes(dev);
        device_remove_bin_file(dev, &dev_bin_attr_descriptors);
-- 
1.7.6.rc2.8.g28eb

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to