Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: common/usb.c

Issue 3054035: Cleanup newly allocated device nodes in case of configuration failure. (Closed) Base URL: git://git.chromium.org/u-boot.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * 2 *
3 * Most of this source has been derived from the Linux USB 3 * Most of this source has been derived from the Linux USB
4 * project: 4 * project:
5 * (C) Copyright Linus Torvalds 1999 5 * (C) Copyright Linus Torvalds 1999
6 * (C) Copyright Johannes Erdfelt 1999-2001 6 * (C) Copyright Johannes Erdfelt 1999-2001
7 * (C) Copyright Andreas Gal 1999 7 * (C) Copyright Andreas Gal 1999
8 * (C) Copyright Gregory P. Smith 1999 8 * (C) Copyright Gregory P. Smith 1999
9 * (C) Copyright Deti Fliegl 1999 (new USB architecture) 9 * (C) Copyright Deti Fliegl 1999 (new USB architecture)
10 * (C) Copyright Randy Dunlap 2000 10 * (C) Copyright Randy Dunlap 2000
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 /* default Address is 0, real addresses start with 1 */ 747 /* default Address is 0, real addresses start with 1 */
748 usb_dev[dev_index].devnum = dev_index + 1; 748 usb_dev[dev_index].devnum = dev_index + 1;
749 usb_dev[dev_index].maxchild = 0; 749 usb_dev[dev_index].maxchild = 0;
750 for (i = 0; i < USB_MAXCHILDREN; i++) 750 for (i = 0; i < USB_MAXCHILDREN; i++)
751 usb_dev[dev_index].children[i] = NULL; 751 usb_dev[dev_index].children[i] = NULL;
752 usb_dev[dev_index].parent = NULL; 752 usb_dev[dev_index].parent = NULL;
753 dev_index++; 753 dev_index++;
754 return &usb_dev[dev_index - 1]; 754 return &usb_dev[dev_index - 1];
755 } 755 }
756 756
757 /*
758 * Free the newly created device node.
759 * Called in error cases where configuring a newly attached
760 * device fails for some reason.
761 */
762 void usb_free_device(void)
763 {
764 dev_index--;
765 USB_PRINTF("Freeing device node: %d \n", dev_index);
766 memset(&usb_dev[dev_index], 0, sizeof(struct usb_device));
767 usb_dev[dev_index].devnum = -1;
768 }
757 769
758 /* 770 /*
759 * By the time we get here, the device has gotten a new device ID 771 * By the time we get here, the device has gotten a new device ID
760 * and is in the default state. We need to identify the thing and 772 * and is in the default state. We need to identify the thing and
761 * get the ball rolling.. 773 * get the ball rolling..
762 * 774 *
763 * Returns 0 for success, != 0 for error. 775 * Returns 0 for success, != 0 for error.
764 */ 776 */
765 int usb_new_device(struct usb_device *dev) 777 int usb_new_device(struct usb_device *dev)
766 { 778 {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 1165 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
1154 usb->speed = USB_SPEED_LOW; 1166 usb->speed = USB_SPEED_LOW;
1155 else 1167 else
1156 usb->speed = USB_SPEED_FULL; 1168 usb->speed = USB_SPEED_FULL;
1157 1169
1158 dev->children[port] = usb; 1170 dev->children[port] = usb;
1159 usb->parent = dev; 1171 usb->parent = dev;
1160 /* Run it through the hoops (find a driver, etc) */ 1172 /* Run it through the hoops (find a driver, etc) */
1161 if (usb_new_device(usb)) { 1173 if (usb_new_device(usb)) {
1162 /* Woops, disable the port */ 1174 /* Woops, disable the port */
1175 usb_free_device();
1176 dev->children[port] = NULL;
1163 USB_HUB_PRINTF("hub: disabling port %d\n", port + 1); 1177 USB_HUB_PRINTF("hub: disabling port %d\n", port + 1);
1164 usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE); 1178 usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
1165 } 1179 }
1166 } 1180 }
1167 1181
1168 1182
1169 int usb_hub_configure(struct usb_device *dev) 1183 int usb_hub_configure(struct usb_device *dev)
1170 { 1184 {
1171 unsigned char buffer[USB_BUFSIZ], *bitmap; 1185 unsigned char buffer[USB_BUFSIZ], *bitmap;
1172 struct usb_hub_descriptor *descriptor; 1186 struct usb_hub_descriptor *descriptor;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 /* If it's not an interrupt endpoint, we'd better punt! */ 1384 /* If it's not an interrupt endpoint, we'd better punt! */
1371 if ((ep->bmAttributes & 3) != 3) 1385 if ((ep->bmAttributes & 3) != 3)
1372 return 0; 1386 return 0;
1373 /* We found a hub */ 1387 /* We found a hub */
1374 USB_HUB_PRINTF("USB hub found\n"); 1388 USB_HUB_PRINTF("USB hub found\n");
1375 ret = usb_hub_configure(dev); 1389 ret = usb_hub_configure(dev);
1376 return ret; 1390 return ret;
1377 } 1391 }
1378 1392
1379 /* EOF */ 1393 /* EOF */
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698