[U-Boot] [PATCH v2 25/80] dm: usb: Simply device finding code in usb_storage
Simon Glass
sjg at chromium.org
Wed Mar 25 19:22:13 CET 2015
The for() loop is not needed since the value is immediately accessible.
Use this instead to simplify the code.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2: None
common/usb_storage.c | 30 +++++++++++-------------------
1 file changed, 11 insertions(+), 19 deletions(-)
diff --git a/common/usb_storage.c b/common/usb_storage.c
index 80ed14a..64d01ea 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -1005,7 +1005,7 @@ unsigned long usb_stor_read(int device, lbaint_t blknr,
unsigned short smallblks;
struct usb_device *dev;
struct us_data *ss;
- int retry, i;
+ int retry;
ccb *srb = &usb_ccb;
if (blkcnt == 0)
@@ -1013,14 +1013,11 @@ unsigned long usb_stor_read(int device, lbaint_t blknr,
device &= 0xff;
/* Setup device */
- debug("\nusb_read: dev %d \n", device);
- dev = NULL;
- for (i = 0; i < USB_MAX_DEVICE; i++) {
- dev = usb_get_dev_index(i);
- if (dev == NULL)
- return 0;
- if (dev->devnum == usb_dev_desc[device].target)
- break;
+ debug("\nusb_read: dev %d\n", device);
+ dev = usb_dev_desc[device].priv;
+ if (!dev) {
+ debug("%s: No device\n", __func__);
+ return 0;
}
ss = (struct us_data *)dev->privptr;
@@ -1078,7 +1075,7 @@ unsigned long usb_stor_write(int device, lbaint_t blknr,
unsigned short smallblks;
struct usb_device *dev;
struct us_data *ss;
- int retry, i;
+ int retry;
ccb *srb = &usb_ccb;
if (blkcnt == 0)
@@ -1086,15 +1083,10 @@ unsigned long usb_stor_write(int device, lbaint_t blknr,
device &= 0xff;
/* Setup device */
- debug("\nusb_write: dev %d \n", device);
- dev = NULL;
- for (i = 0; i < USB_MAX_DEVICE; i++) {
- dev = usb_get_dev_index(i);
- if (dev == NULL)
- return 0;
- if (dev->devnum == usb_dev_desc[device].target)
- break;
- }
+ debug("\nusb_write: dev %d\n", device);
+ dev = usb_dev_desc[device].priv;
+ if (!dev)
+ return 0;
ss = (struct us_data *)dev->privptr;
usb_disable_asynch(1); /* asynch transfer not allowed */
--
2.2.0.rc0.207.ga3a616c
More information about the U-Boot
mailing list