Skip to content

Commit

Permalink
USB: fix authorization and claimed port logic
Browse files Browse the repository at this point in the history
    It looks like I've run into some inconsistency in the USB stack behavior.

    The USB stack maintains, among others, two states for the attach
USB device: authorized and owned. Authorization state is accessible to
the user space code through correspondent sysfs files, the ownership
can be set by claiming the hub's port with ioctl call. Both state may
be set before the device is attached, by access the hub settings. When
the new device is attached, both authorization and ownership prevent
the kernel USB stack from setting the newly attached device
configuration, but when the device is authorized, the ownership state
is ignored. It looks like ignoring the ownership state on
authorization make the stack behavior inconsistent; it also prevents
the user space code from completely overriding configuration
selection, important for implementing workarounds for bugs in the
device configuration selection.

   The following patch makes the stack behavior more consistent, by
moving ownership test into usb_choose_configuration - the later
function is used both by generic_probe and usb_authorize_device

Signed-off-by: Joseph Hindin <hindin@gmail.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Hindin Joseph authored and Greg Kroah-Hartman committed Nov 16, 2012
1 parent 9d94e16 commit c13b86a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/usb/core/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ int usb_choose_configuration(struct usb_device *udev)
int insufficient_power = 0;
struct usb_host_config *c, *best;

if (usb_device_is_owned(udev))
return 0;

best = NULL;
c = udev->config;
num_configs = udev->descriptor.bNumConfigurations;
Expand Down Expand Up @@ -160,9 +163,7 @@ static int generic_probe(struct usb_device *udev)
/* Choose and set the configuration. This registers the interfaces
* with the driver core and lets interface drivers bind to them.
*/
if (usb_device_is_owned(udev))
; /* Don't configure if the device is owned */
else if (udev->authorized == 0)
if (udev->authorized == 0)
dev_err(&udev->dev, "Device is not authorized for usage\n");
else {
c = usb_choose_configuration(udev);
Expand Down

0 comments on commit c13b86a

Please sign in to comment.