diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2007-11-06 11:43:42 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-11-28 16:58:35 -0500 |
commit | 7e61559f6199bb387037abfc7d10a893973561fc (patch) | |
tree | dd3e8f8cca77077bc4567a047cfe9ee74d100525 | |
parent | 5fdcd0396be443e36a4e2128f51818acca570ee7 (diff) |
USB: keep track of whether interface sysfs files exist
This patch (as1009) solves the problem of multiple registrations for
USB sysfs files in a more satisfying way than the existing code. It
simply adds a flag to keep track of whether or not the files have been
created; that way the files can be created or removed as needed.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
-rw-r--r-- | drivers/usb/core/message.c | 12 | ||||
-rw-r--r-- | drivers/usb/core/sysfs.c | 6 | ||||
-rw-r--r-- | include/linux/usb.h | 1 |
3 files changed, 9 insertions, 10 deletions
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 316a746e008..40fd39de5bf 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -1172,7 +1172,6 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1172 | struct usb_host_interface *alt; | 1172 | struct usb_host_interface *alt; |
1173 | int ret; | 1173 | int ret; |
1174 | int manual = 0; | 1174 | int manual = 0; |
1175 | int changed; | ||
1176 | 1175 | ||
1177 | if (dev->state == USB_STATE_SUSPENDED) | 1176 | if (dev->state == USB_STATE_SUSPENDED) |
1178 | return -EHOSTUNREACH; | 1177 | return -EHOSTUNREACH; |
@@ -1212,8 +1211,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1212 | */ | 1211 | */ |
1213 | 1212 | ||
1214 | /* prevent submissions using previous endpoint settings */ | 1213 | /* prevent submissions using previous endpoint settings */ |
1215 | changed = (iface->cur_altsetting != alt); | 1214 | if (iface->cur_altsetting != alt && device_is_registered(&iface->dev)) |
1216 | if (changed && device_is_registered(&iface->dev)) | ||
1217 | usb_remove_sysfs_intf_files(iface); | 1215 | usb_remove_sysfs_intf_files(iface); |
1218 | usb_disable_interface(dev, iface); | 1216 | usb_disable_interface(dev, iface); |
1219 | 1217 | ||
@@ -1250,7 +1248,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1250 | * (Likewise, EP0 never "halts" on well designed devices.) | 1248 | * (Likewise, EP0 never "halts" on well designed devices.) |
1251 | */ | 1249 | */ |
1252 | usb_enable_interface(dev, iface); | 1250 | usb_enable_interface(dev, iface); |
1253 | if (changed && device_is_registered(&iface->dev)) | 1251 | if (device_is_registered(&iface->dev)) |
1254 | usb_create_sysfs_intf_files(iface); | 1252 | usb_create_sysfs_intf_files(iface); |
1255 | 1253 | ||
1256 | return 0; | 1254 | return 0; |
@@ -1641,12 +1639,6 @@ free_interfaces: | |||
1641 | intf->dev.bus_id, ret); | 1639 | intf->dev.bus_id, ret); |
1642 | continue; | 1640 | continue; |
1643 | } | 1641 | } |
1644 | |||
1645 | /* The driver's probe method can call usb_set_interface(), | ||
1646 | * which would mean the interface's sysfs files are already | ||
1647 | * created. Just in case, we'll remove them first. | ||
1648 | */ | ||
1649 | usb_remove_sysfs_intf_files(intf); | ||
1650 | usb_create_sysfs_intf_files(intf); | 1642 | usb_create_sysfs_intf_files(intf); |
1651 | } | 1643 | } |
1652 | 1644 | ||
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index b04afd06e50..32bd130b1ee 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -735,6 +735,8 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf) | |||
735 | struct usb_host_interface *alt = intf->cur_altsetting; | 735 | struct usb_host_interface *alt = intf->cur_altsetting; |
736 | int retval; | 736 | int retval; |
737 | 737 | ||
738 | if (intf->sysfs_files_created) | ||
739 | return 0; | ||
738 | retval = sysfs_create_group(&dev->kobj, &intf_attr_grp); | 740 | retval = sysfs_create_group(&dev->kobj, &intf_attr_grp); |
739 | if (retval) | 741 | if (retval) |
740 | return retval; | 742 | return retval; |
@@ -746,6 +748,7 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf) | |||
746 | if (intf->intf_assoc) | 748 | if (intf->intf_assoc) |
747 | retval = sysfs_create_group(&dev->kobj, &intf_assoc_attr_grp); | 749 | retval = sysfs_create_group(&dev->kobj, &intf_assoc_attr_grp); |
748 | usb_create_intf_ep_files(intf, udev); | 750 | usb_create_intf_ep_files(intf, udev); |
751 | intf->sysfs_files_created = 1; | ||
749 | return 0; | 752 | return 0; |
750 | } | 753 | } |
751 | 754 | ||
@@ -753,8 +756,11 @@ void usb_remove_sysfs_intf_files(struct usb_interface *intf) | |||
753 | { | 756 | { |
754 | struct device *dev = &intf->dev; | 757 | struct device *dev = &intf->dev; |
755 | 758 | ||
759 | if (!intf->sysfs_files_created) | ||
760 | return; | ||
756 | usb_remove_intf_ep_files(intf); | 761 | usb_remove_intf_ep_files(intf); |
757 | device_remove_file(dev, &dev_attr_interface); | 762 | device_remove_file(dev, &dev_attr_interface); |
758 | sysfs_remove_group(&dev->kobj, &intf_attr_grp); | 763 | sysfs_remove_group(&dev->kobj, &intf_attr_grp); |
759 | sysfs_remove_group(&intf->dev.kobj, &intf_assoc_attr_grp); | 764 | sysfs_remove_group(&intf->dev.kobj, &intf_assoc_attr_grp); |
765 | intf->sysfs_files_created = 0; | ||
760 | } | 766 | } |
diff --git a/include/linux/usb.h b/include/linux/usb.h index c5c8f169d3c..416ee7617d9 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h | |||
@@ -157,6 +157,7 @@ struct usb_interface { | |||
157 | * bound to */ | 157 | * bound to */ |
158 | enum usb_interface_condition condition; /* state of binding */ | 158 | enum usb_interface_condition condition; /* state of binding */ |
159 | unsigned is_active:1; /* the interface is not suspended */ | 159 | unsigned is_active:1; /* the interface is not suspended */ |
160 | unsigned sysfs_files_created:1; /* the sysfs attributes exist */ | ||
160 | unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */ | 161 | unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */ |
161 | 162 | ||
162 | struct device dev; /* interface specific device info */ | 163 | struct device dev; /* interface specific device info */ |