libpayload: Shutdown reasonably if we can't init usb msc device
This lets the init of usb mass storage return if the device configuration is unusable. Also add some checks for proper shutdown so we don't free/remove an uninitialized device. Change-Id: I6daf9b38e632b6e381bcd5a7717f0f1a3150b64a Signed-off-by: Nico Huber <nico.huber@secunet.com> Reviewed-on: http://review.coreboot.org/1130 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
57cd1dd296
commit
445a3a04d8
|
@ -70,9 +70,11 @@ static const char *msc_protocol_strings[0x51] = {
|
||||||
static void
|
static void
|
||||||
usb_msc_destroy (usbdev_t *dev)
|
usb_msc_destroy (usbdev_t *dev)
|
||||||
{
|
{
|
||||||
if (usbdisk_remove)
|
if (dev->data) {
|
||||||
|
if (MSC_INST (dev)->usbdisk_created && usbdisk_remove)
|
||||||
usbdisk_remove (dev);
|
usbdisk_remove (dev);
|
||||||
free (dev->data);
|
free (dev->data);
|
||||||
|
}
|
||||||
dev->data = 0;
|
dev->data = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,6 +419,9 @@ usb_msc_init (usbdev_t *dev)
|
||||||
{
|
{
|
||||||
int i, timeout;
|
int i, timeout;
|
||||||
|
|
||||||
|
/* init .data before setting .destroy */
|
||||||
|
dev->data = NULL;
|
||||||
|
|
||||||
dev->destroy = usb_msc_destroy;
|
dev->destroy = usb_msc_destroy;
|
||||||
dev->poll = usb_msc_poll;
|
dev->poll = usb_msc_poll;
|
||||||
|
|
||||||
|
@ -451,6 +456,7 @@ usb_msc_init (usbdev_t *dev)
|
||||||
MSC_INST (dev)->protocol = interface->bInterfaceSubClass;
|
MSC_INST (dev)->protocol = interface->bInterfaceSubClass;
|
||||||
MSC_INST (dev)->bulk_in = 0;
|
MSC_INST (dev)->bulk_in = 0;
|
||||||
MSC_INST (dev)->bulk_out = 0;
|
MSC_INST (dev)->bulk_out = 0;
|
||||||
|
MSC_INST (dev)->usbdisk_created = 0;
|
||||||
|
|
||||||
for (i = 1; i <= dev->num_endp; i++) {
|
for (i = 1; i <= dev->num_endp; i++) {
|
||||||
if (dev->endpoints[i].endpoint == 0)
|
if (dev->endpoints[i].endpoint == 0)
|
||||||
|
@ -465,10 +471,14 @@ usb_msc_init (usbdev_t *dev)
|
||||||
MSC_INST (dev)->bulk_out = &dev->endpoints[i];
|
MSC_INST (dev)->bulk_out = &dev->endpoints[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MSC_INST (dev)->bulk_in == 0)
|
if (MSC_INST (dev)->bulk_in == 0) {
|
||||||
fatal ("couldn't find bulk-in endpoint");
|
printf("couldn't find bulk-in endpoint");
|
||||||
if (MSC_INST (dev)->bulk_out == 0)
|
return;
|
||||||
fatal ("couldn't find bulk-out endpoint");
|
}
|
||||||
|
if (MSC_INST (dev)->bulk_out == 0) {
|
||||||
|
printf("couldn't find bulk-out endpoint");
|
||||||
|
return;
|
||||||
|
}
|
||||||
debug (" using endpoint %x as in, %x as out\n",
|
debug (" using endpoint %x as in, %x as out\n",
|
||||||
MSC_INST (dev)->bulk_in->endpoint,
|
MSC_INST (dev)->bulk_in->endpoint,
|
||||||
MSC_INST (dev)->bulk_out->endpoint);
|
MSC_INST (dev)->bulk_out->endpoint);
|
||||||
|
@ -514,6 +524,8 @@ usb_msc_init (usbdev_t *dev)
|
||||||
}
|
}
|
||||||
debug ("\n");
|
debug ("\n");
|
||||||
|
|
||||||
if ((read_capacity (dev) == MSC_COMMAND_OK) && usbdisk_create)
|
if ((read_capacity (dev) == MSC_COMMAND_OK) && usbdisk_create) {
|
||||||
usbdisk_create (dev);
|
usbdisk_create (dev);
|
||||||
|
MSC_INST (dev)->usbdisk_created = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ typedef struct {
|
||||||
unsigned int protocol;
|
unsigned int protocol;
|
||||||
endpoint_t *bulk_in;
|
endpoint_t *bulk_in;
|
||||||
endpoint_t *bulk_out;
|
endpoint_t *bulk_out;
|
||||||
|
int usbdisk_created;
|
||||||
} usbmsc_inst_t;
|
} usbmsc_inst_t;
|
||||||
|
|
||||||
#define MSC_INST(dev) ((usbmsc_inst_t*)(dev)->data)
|
#define MSC_INST(dev) ((usbmsc_inst_t*)(dev)->data)
|
||||||
|
|
Loading…
Reference in New Issue