All references to mod_data object from outside of fsg_common_init() function have been removed. Signed-off-by: Michal Nazarewicz <m.nazarewicz@xxxxxxxxxxx> --- drivers/usb/gadget/f_mass_storage.c | 87 +++++++++++++++++++---------------- 1 files changed, 48 insertions(+), 39 deletions(-) diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index c6c6384..b9420a7 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -324,6 +324,12 @@ struct fsg_common { struct fsg_lun *luns; struct fsg_lun *curlun; + unsigned int can_stall:1; + + /* Vendor (8 chars), product (16 chars), release (4 + * hexadecimal digits) and NUL byte */ + char inquiry_string[8 + 16 + 4 + 1]; + struct kref ref; }; @@ -356,6 +362,7 @@ struct fsg_dev { unsigned int phase_error : 1; unsigned int short_packet_received : 1; unsigned int bad_lun_okay : 1; + unsigned int can_stall : 1; unsigned long atomic_bitflags; #define REGISTERED 0 @@ -1042,13 +1049,10 @@ static int do_verify(struct fsg_dev *fsg) static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh) { + struct fsg_lun *curlun = fsg->common->curlun; u8 *buf = (u8 *) bh->buf; - static char vendor_id[] = "Linux "; - static char product_disk_id[] = "File-Stor Gadget"; - static char product_cdrom_id[] = "File-CD Gadget "; - - if (!fsg->common->curlun) { // Unsupported LUNs are okay + if (!curlun) { /* Unsupported LUNs are okay */ fsg->bad_lun_okay = 1; memset(buf, 0, 36); buf[0] = 0x7f; // Unsupported, no device-type @@ -1056,18 +1060,16 @@ static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh) return 36; } - memset(buf, 0, 8); - buf[0] = (mod_data.cdrom ? TYPE_CDROM : TYPE_DISK); - if (mod_data.removable) - buf[1] = 0x80; + buf[0] = curlun->cdrom ? TYPE_CDROM : TYPE_DISK; + buf[1] = curlun->removable ? 0x80 : 0; buf[2] = 2; // ANSI SCSI level 2 buf[3] = 2; // SCSI-2 INQUIRY data format buf[4] = 31; // Additional length - // No special options - sprintf(buf + 8, "%-8s%-16s%04x", vendor_id, - (mod_data.cdrom ? product_cdrom_id : - product_disk_id), - mod_data.release); + buf[5] = 0; // No special options + buf[6] = 0; + buf[7] = 0; + memcpy(buf + 8, fsg->common->inquiry_string, + sizeof fsg->common->inquiry_string); return 36; } @@ -1280,7 +1282,9 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh) static int do_start_stop(struct fsg_dev *fsg) { - if (!mod_data.removable) { + if (!fsg->common->curlun) { + return -EINVAL; + } else if (!fsg->common->curlun->removable) { fsg->common->curlun->sense_data = SS_INVALID_COMMAND; return -EINVAL; } @@ -1293,8 +1297,10 @@ static int do_prevent_allow(struct fsg_dev *fsg) struct fsg_lun *curlun = fsg->common->curlun; int prevent; - if (!mod_data.removable) { - curlun->sense_data = SS_INVALID_COMMAND; + if (!fsg->common->curlun) { + return -EINVAL; + } else if (!fsg->common->curlun->removable) { + fsg->common->curlun->sense_data = SS_INVALID_COMMAND; return -EINVAL; } @@ -1482,7 +1488,7 @@ static int finish_reply(struct fsg_dev *fsg) * try to send or receive any data. So stall both bulk pipes * if we can and wait for a reset. */ case DATA_DIR_UNKNOWN: - if (mod_data.can_stall) { + if (fsg->can_stall) { fsg_set_halt(fsg, fsg->bulk_out); rc = halt_bulk_in_endpoint(fsg); } @@ -1503,7 +1509,7 @@ static int finish_reply(struct fsg_dev *fsg) /* For Bulk-only, if we're allowed to stall then send the * short packet and halt the bulk-in endpoint. If we can't * stall, pad out the remaining data with 0's. */ - } else if (mod_data.can_stall) { + } else if (fsg->can_stall) { bh->inreq->zero = 1; start_transfer(fsg, fsg->bulk_in, bh->inreq, &bh->inreq_busy, &bh->state); @@ -1533,7 +1539,7 @@ static int finish_reply(struct fsg_dev *fsg) * STALL. Not realizing the endpoint was halted, it wouldn't * clear the halt -- leading to problems later on. */ #if 0 - else if (mod_data.can_stall) { + else if (fsg->can_stall) { fsg_set_halt(fsg, fsg->bulk_out); raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT); rc = -EINTR; @@ -1843,7 +1849,7 @@ static int do_scsi_command(struct fsg_dev *fsg) break; case SC_READ_HEADER: - if (!mod_data.cdrom) + if (!fsg->common->curlun || !fsg->common->curlun->cdrom) goto unknown_cmnd; fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->common->cmnd[7]); if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, @@ -1853,7 +1859,7 @@ static int do_scsi_command(struct fsg_dev *fsg) break; case SC_READ_TOC: - if (!mod_data.cdrom) + if (!fsg->common->curlun || !fsg->common->curlun->cdrom) goto unknown_cmnd; fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->common->cmnd[7]); if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, @@ -2020,7 +2026,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) /* We can do anything we want here, so let's stall the * bulk pipes if we are allowed to. */ - if (mod_data.can_stall) { + if (fsg->can_stall) { fsg_set_halt(fsg, fsg->bulk_out); halt_bulk_in_endpoint(fsg); } @@ -2558,33 +2564,35 @@ static struct fsg_common *fsg_common_init(struct usb_composite_dev *cdev) bh->next = common->buffhds; - /* Release */ - if (mod_data.release == 0xffff) { // Parameter wasn't set - int gcnum; - + /* Prepare inquiryString */ + if (mod_data.release != 0xffff) { + i = mod_data.release; + } else if (mod_data.release == 0xffff) { /* The sa1100 controller is not supported */ - if (gadget_is_sa1100(gadget)) - gcnum = -1; - else - gcnum = usb_gadget_controller_number(gadget); - if (gcnum >= 0) - mod_data.release = 0x0300 + gcnum; - else { - WARNING(common, "controller '%s' not recognized\n", - gadget->name); + i = gadget_is_sa1100(gadget) + ? -1 + : usb_gadget_controller_number(gadget); + if (i >= 0) { + i = 0x0300 + i; + } else { WARNING(common, "controller '%s' not recognized\n", gadget->name); - mod_data.release = 0x0399; + i = 0x0399; } } + snprintf(common->inquiry_string, sizeof common->inquiry_string, + "Linux %-16s%04x", + /* Assume product name dependent on the first LUN */ + common->luns->cdrom ? "File-Stor Gadget" : "File-CD Gadget ", + i); /* Some peripheral controllers are known not to be able to * halt bulk endpoints correctly. If one of them is present, * disable stalls. */ - if (gadget_is_sh(fsg->gadget) || gadget_is_at91(fsg->gadget)) - mod_data.can_stall = 0; + common->can_stall = mod_data.can_stall && + !(gadget_is_sh(fsg->gadget) || gadget_is_at91(fsg->gadget)); kref_init(&common->ref); @@ -2789,6 +2797,7 @@ static int fsg_add(struct usb_composite_dev *cdev, * from this function. So instead of incrementing counter now * and decrement in error recovery we increment it only when * call to usb_add_function() was successful. */ + fsg->can_stall = common->can_stall; rc = usb_add_function(c, &fsg->function); -- 1.6.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html