aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2005-04-05 11:56:54 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-27 17:43:40 -0400
commit76f4af8efc72b6091d230cbe718cedca06d2d79e (patch)
tree84bb24757b11f24dd6e7c4bed926bd92ee59d5f5 /drivers
parent020f46a39eb7b99a575b9f4d105fce2b142acdf1 (diff)
[PATCH] USB: g_file_storage: Consolidate min()s
This patch simplifies the g_file_storage driver by consolidating a bunch of min() calculations at a single spot. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/file_storage.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a9be85103d23..507a24924177 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -1312,7 +1312,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1312 } 1312 }
1313 VDBG(fsg, "get max LUN\n"); 1313 VDBG(fsg, "get max LUN\n");
1314 *(u8 *) req->buf = fsg->nluns - 1; 1314 *(u8 *) req->buf = fsg->nluns - 1;
1315 value = min(w_length, (u16) 1); 1315 value = 1;
1316 break; 1316 break;
1317 } 1317 }
1318 } 1318 }
@@ -1360,7 +1360,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1360 int value = -EOPNOTSUPP; 1360 int value = -EOPNOTSUPP;
1361 u16 w_index = ctrl->wIndex; 1361 u16 w_index = ctrl->wIndex;
1362 u16 w_value = ctrl->wValue; 1362 u16 w_value = ctrl->wValue;
1363 u16 w_length = ctrl->wLength;
1364 1363
1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer, 1364 /* Usually this just stores reply data in the pre-allocated ep0 buffer,
1366 * but config change events will also reconfigure hardware. */ 1365 * but config change events will also reconfigure hardware. */
@@ -1374,7 +1373,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1374 1373
1375 case USB_DT_DEVICE: 1374 case USB_DT_DEVICE:
1376 VDBG(fsg, "get device descriptor\n"); 1375 VDBG(fsg, "get device descriptor\n");
1377 value = min(w_length, (u16) sizeof device_desc); 1376 value = sizeof device_desc;
1378 memcpy(req->buf, &device_desc, value); 1377 memcpy(req->buf, &device_desc, value);
1379 break; 1378 break;
1380#ifdef CONFIG_USB_GADGET_DUALSPEED 1379#ifdef CONFIG_USB_GADGET_DUALSPEED
@@ -1382,7 +1381,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1382 VDBG(fsg, "get device qualifier\n"); 1381 VDBG(fsg, "get device qualifier\n");
1383 if (!fsg->gadget->is_dualspeed) 1382 if (!fsg->gadget->is_dualspeed)
1384 break; 1383 break;
1385 value = min(w_length, (u16) sizeof dev_qualifier); 1384 value = sizeof dev_qualifier;
1386 memcpy(req->buf, &dev_qualifier, value); 1385 memcpy(req->buf, &dev_qualifier, value);
1387 break; 1386 break;
1388 1387
@@ -1401,8 +1400,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1401 req->buf, 1400 req->buf,
1402 w_value >> 8, 1401 w_value >> 8,
1403 w_value & 0xff); 1402 w_value & 0xff);
1404 if (value >= 0)
1405 value = min(w_length, (u16) value);
1406 break; 1403 break;
1407 1404
1408 case USB_DT_STRING: 1405 case USB_DT_STRING:
@@ -1411,8 +1408,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1411 /* wIndex == language code */ 1408 /* wIndex == language code */
1412 value = usb_gadget_get_string(&stringtab, 1409 value = usb_gadget_get_string(&stringtab,
1413 w_value & 0xff, req->buf); 1410 w_value & 0xff, req->buf);
1414 if (value >= 0)
1415 value = min(w_length, (u16) value);
1416 break; 1411 break;
1417 } 1412 }
1418 break; 1413 break;
@@ -1438,7 +1433,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1438 break; 1433 break;
1439 VDBG(fsg, "get configuration\n"); 1434 VDBG(fsg, "get configuration\n");
1440 *(u8 *) req->buf = fsg->config; 1435 *(u8 *) req->buf = fsg->config;
1441 value = min(w_length, (u16) 1); 1436 value = 1;
1442 break; 1437 break;
1443 1438
1444 case USB_REQ_SET_INTERFACE: 1439 case USB_REQ_SET_INTERFACE:
@@ -1466,14 +1461,14 @@ static int standard_setup_req(struct fsg_dev *fsg,
1466 } 1461 }
1467 VDBG(fsg, "get interface\n"); 1462 VDBG(fsg, "get interface\n");
1468 *(u8 *) req->buf = 0; 1463 *(u8 *) req->buf = 0;
1469 value = min(w_length, (u16) 1); 1464 value = 1;
1470 break; 1465 break;
1471 1466
1472 default: 1467 default:
1473 VDBG(fsg, 1468 VDBG(fsg,
1474 "unknown control req %02x.%02x v%04x i%04x l%u\n", 1469 "unknown control req %02x.%02x v%04x i%04x l%u\n",
1475 ctrl->bRequestType, ctrl->bRequest, 1470 ctrl->bRequestType, ctrl->bRequest,
1476 w_value, w_index, w_length); 1471 w_value, w_index, ctrl->wLength);
1477 } 1472 }
1478 1473
1479 return value; 1474 return value;
@@ -1485,6 +1480,7 @@ static int fsg_setup(struct usb_gadget *gadget,
1485{ 1480{
1486 struct fsg_dev *fsg = get_gadget_data(gadget); 1481 struct fsg_dev *fsg = get_gadget_data(gadget);
1487 int rc; 1482 int rc;
1483 int w_length = ctrl->wLength;
1488 1484
1489 ++fsg->ep0_req_tag; // Record arrival of a new request 1485 ++fsg->ep0_req_tag; // Record arrival of a new request
1490 fsg->ep0req->context = NULL; 1486 fsg->ep0req->context = NULL;
@@ -1498,8 +1494,9 @@ static int fsg_setup(struct usb_gadget *gadget,
1498 1494
1499 /* Respond with data/status or defer until later? */ 1495 /* Respond with data/status or defer until later? */
1500 if (rc >= 0 && rc != DELAYED_STATUS) { 1496 if (rc >= 0 && rc != DELAYED_STATUS) {
1497 rc = min(rc, w_length);
1501 fsg->ep0req->length = rc; 1498 fsg->ep0req->length = rc;
1502 fsg->ep0req->zero = (rc < ctrl->wLength && 1499 fsg->ep0req->zero = (rc < w_length &&
1503 (rc % gadget->ep0->maxpacket) == 0); 1500 (rc % gadget->ep0->maxpacket) == 0);
1504 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ? 1501 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
1505 "ep0-in" : "ep0-out"); 1502 "ep0-in" : "ep0-out");