• Alan Stern's avatar
    [PATCH] USB: Improve handling of altsettings · e8a19690
    Alan Stern authored
    On Sat, 21 Feb 2004, Greg KH wrote:
    
    > > One thing that would be good, whether this change gets made or not, is to
    > > remove all assumptions from drivers about the order in which interfaces
    > > are stored (use usb_ifnum_to_if()) and the order in which altsettings are
    > > stored (replace intf.act_altsetting with a pointer and create
    > > usb_altnum_to_alt() analogous to usb_ifnum_to_if()).  There are plenty of
    > > drivers that will need to be fixed up.
    >
    > I'd be glad to take patches to fix up any drivers that still have this
    > problem right now.
    
    Here's a start.  This patch begins the conversion process by adding
    usbcore support for cur_altsetting and deprecating act_altsetting.
    
    So long as we assumed that altsetting numbers range from 0 to
    num_altsetting-1 and that the number matches its index in the altsetting
    array, there was no harm in using act_altsetting.  But without that
    assumption act_altsetting is merely an invitation to errors.  Although the
    kerneldoc says that act_altsetting is the _index_ of the active
    altsetting, it's all too easy to confuse it with the _number_ of the
    active altsetting.  Using cur_altsetting instead (a pointer rather than a
    number) will prevent that confusion.
    
    Until all the drivers have been converted to use cur_altsetting, the core
    will have to maintain act_altsetting in parallel with it.  Eventually we
    will be able to remove act_altsetting, but fixing all the drivers will
    take a while.
    
    Included in this patch:
    
    	Add cur_altsetting to struct usb_interface and deprecate
    	act_altsetting.
    
    	Add comments and kerneldoc explaining the changes.  Also remove
    	the comments in front of struct usb_host_config (they seem to
    	have been left behind when usb_ch9.h was split out) and add
    	kerneldoc for that structure.
    
    	Add usb_altnum_to_altsetting() to help look up altsettings based
    	on their number.
    
    	Convert the usb_set_interface(), usb_set_configuration(), and
    	usb_reset_configuration() routines to support cur_altsetting
    	and act_altsetting in parallel.  Convert a few others to use
    	cur_altsetting rather than act_altsetting.
    
    	Rename a few local variables to make their meaning a little
    	clearer.  It would be nice to change struct usb_host_interface
    	to something like usb_host_altsetting, but that's a patch for
    	another time.
    e8a19690
usb.c 46 KB