usb_storage : scan all interfaces to find a storage device
PATCH v2 1/1 usb_storage : scan all interfaces to find a storage device
From: Franck Jullien <[email protected]>
Mass storage is not necessary present on interface 0. This patch allow usb_stor_scan to look in every available interface.
---
v2: create a new function to improve indentation
common/usb_storage.c | 45 ++++++++++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 17 deletions(-)
common/usb_storage.c +28 -17
@@ -208,6 +208,30 @@ static unsigned int usb_get_max_lun(struct us_data *us)return (len >0 ) ? *result :0 ; } +static int usb_storage_register (struct usb_device *dev,unsigned char iface) +{ +int lun, max_lun, start = usb_max_devs; +int nb_dev =0 ; + +if (usb_storage_probe (dev, iface, &usb_stor[usb_max_devs])) { +/* OK, it's a storage device. Iterate over its LUNs +* and populate `usb_dev_desc'. +*/ + max_lun =usb_get_max_lun (&usb_stor[usb_max_devs]); +for (lun =0 ; + lun <= max_lun && usb_max_devs <USB_MAX_STOR_DEV ; + lun++) { + usb_dev_desc[usb_max_devs].lun = lun; +if (usb_stor_get_info (dev, &usb_stor[start], + &usb_dev_desc[usb_max_devs]) ==1 ) { + nb_dev++; + } + } + } + +return nb_dev; +} +/******************************************************************************* * scan the usb and reports device info * to the user if mode = 1
@@ -215,7 +239,7 @@ static unsigned int usb_get_max_lun(struct us_data *us)*/ int usb_stor_scan (int mode) { -unsigned char i; +unsigned char i, iface;struct usb_device *dev;if (mode ==1 )
@@ -241,23 +265,10 @@ int usb_stor_scan(int mode)if (dev ==NULL )break ;/* no more devices available */ -if (usb_storage_probe (dev,0 , &usb_stor[usb_max_devs])) { -/* OK, it's a storage device. Iterate over its LUNs -* and populate `usb_dev_desc'. -*/ -int lun, max_lun, start = usb_max_devs; - - max_lun =usb_get_max_lun (&usb_stor[usb_max_devs]); -for (lun =0 ; - lun <= max_lun && usb_max_devs <USB_MAX_STOR_DEV ; - lun++) { - usb_dev_desc[usb_max_devs].lun = lun; -if (usb_stor_get_info (dev, &usb_stor[start], - &usb_dev_desc[usb_max_devs]) ==1 ) { - usb_max_devs++; - } - } +for (iface =0 ; iface < dev->config.no_of_if; iface++) { + usb_max_devs +=usb_storage_register (dev, iface); } +/* if storage device */ if (usb_max_devs ==USB_MAX_STOR_DEV ) { printf("max USB Storage Device reached: %d stopping\n",
Signature · 1 line
1.7.1
PATCH v2 1/1 usb_storage : scan all interfaces to find a storage device
Quoted 9 lines · franck.jullien at gmail.com
From: Franck Jullien <[email protected]>
Mass storage is not necessary present on interface 0. This patch allow
usb_stor_scanto look in every available interface.Signed-off-by Franck Jullien <[email protected]>---
v2: create a new function to improve indentation
Hi!
Quoted 8 lines
common/usb_storage.c | 45 ++++++++++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 17 deletions(-)common/usb_storage.c +0
-0
common/usb_storage.c static unsigned int usb_get_max_lun(struct us_data · line 216
Quoted 9 lines
common/usb_storage.c +5
-0@@ -208,6 +208,30 @@ static unsigned int usb_get_max_lun(struct us_data *us) return (len > 0) ? *result : 0; } +static int usb_storage_register (struct usb_device *dev,unsigned char iface) +{ +int lun, max_lun, start = usb_max_devs; +int nb_dev =0 ; + +if (usb_storage_probe (dev, iface, &usb_stor[usb_max_devs])) {
In case you invert this condition here, you can even trim the indent further. Like this:
if (!usb..........)
return nb_dev;
/*
* OK, it's..........
.........
return nb_dev;
}
common/usb_storage.c static unsigned int usb_get_max_lun(struct us_data *us) · line 219
Quoted 3 lines
common/usb_storage.c +3
-0+/* OK, it's a storage device. Iterate over its LUNs +* and populate `usb_dev_desc'. +*/
Please fix the comment so that it matches the coding style for multiline comments, like this.
/*
* foo
* bar
*/
common/usb_storage.c static unsigned int usb_get_max_lun(struct us_data *us) · line 223
Quoted 4 lines
common/usb_storage.c +4
-0+ max_lun =usb_get_max_lun (&usb_stor[usb_max_devs]); +for (lun =0 ; + lun <= max_lun && usb_max_devs <USB_MAX_STOR_DEV ; + lun++) {
You should be able to put this for () on a single line once you invert the condition above :)
common/usb_storage.c static unsigned int usb_get_max_lun(struct us_data *us) · line 233
Quoted 10 lines
common/usb_storage.c +10
-0+ usb_dev_desc[usb_max_devs].lun = lun; +if (usb_stor_get_info (dev, &usb_stor[start], + &usb_dev_desc[usb_max_devs]) ==1 ) { + nb_dev++; + } + } + } + +return nb_dev; +}
Sorry for pushing you some more, I believe V3 will be the final one.
Thank you!