From 7fe4e995ccc36f56acc51ee3a1c392ac23d2a122 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Mon, 7 Feb 2011 11:51:07 -0500 Subject: [PATCH 1/8] USB: gadget: f_mtp: Fix problems transferring files from device to host Exit from send_file_work immediately when a cancel request is received. Only busy status if there is a cancel pending that has not been repoorted to userspace. This avoids a race condition that can occur when mtp_read resets the state to STATE_BUSY before we report status OK back to the host. Signed-off-by: Mike Lockwood --- drivers/usb/gadget/f_mtp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/f_mtp.c b/drivers/usb/gadget/f_mtp.c index e07224fd9f89..d560fbcf4f58 100644 --- a/drivers/usb/gadget/f_mtp.c +++ b/drivers/usb/gadget/f_mtp.c @@ -662,6 +662,10 @@ static void send_file_work(struct work_struct *data) { ret = wait_event_interruptible(dev->write_wq, (req = req_get(dev, &dev->tx_idle)) || dev->state != STATE_BUSY); + if (dev->state == STATE_CANCELED) { + r = -ECANCELED; + break; + } if (!req) { r = ret; break; @@ -1098,14 +1102,13 @@ static int mtp_function_setup(struct usb_function *f, /* device status is "busy" until we report * the cancelation to userspace */ - if (dev->state == STATE_BUSY - || dev->state == STATE_CANCELED) + if (dev->state == STATE_CANCELED) status->wCode = __cpu_to_le16(MTP_RESPONSE_DEVICE_BUSY); else status->wCode = __cpu_to_le16(MTP_RESPONSE_OK); - spin_unlock_irqrestore(&dev->lock, flags); + spin_unlock_irqrestore(&dev->lock, flags); value = sizeof(*status); } } @@ -1185,7 +1188,7 @@ static void mtp_function_disable(struct usb_function *f) static int mtp_bind_config(struct usb_configuration *c) { struct mtp_dev *dev; - int ret; + int ret = 0; printk(KERN_INFO "mtp_bind_config\n"); From 99648ea95eaa167e3cb7bc37403fdc7d5da0e56c Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Wed, 9 Feb 2011 09:38:26 -0500 Subject: [PATCH 2/8] USB: gadget: android: Support switching vendor ID when configuration changes Based on the list of enabled USB functions, we can now switch the vendor ID as well as the product ID. Signed-off-by: Mike Lockwood --- drivers/usb/gadget/android.c | 32 +++++++++++++++++++++------ include/linux/usb/android_composite.h | 7 +++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c index 213e8a2d7825..8e6cafc851cb 100644 --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c @@ -65,6 +65,7 @@ struct android_dev { int num_functions; char **functions; + int vendor_id; int product_id; int version; }; @@ -255,6 +256,22 @@ static int product_matches_functions(struct android_usb_product *p) return 1; } +static int get_vendor_id(struct android_dev *dev) +{ + struct android_usb_product *p = dev->products; + int count = dev->num_products; + int i; + + if (p) { + for (i = 0; i < count; i++, p++) { + if (p->vendor_id && product_matches_functions(p)) + return p->vendor_id; + } + } + /* use default vendor ID */ + return dev->vendor_id; +} + static int get_product_id(struct android_dev *dev) { struct android_usb_product *p = dev->products; @@ -275,7 +292,7 @@ static int android_bind(struct usb_composite_dev *cdev) { struct android_dev *dev = _android_dev; struct usb_gadget *gadget = cdev->gadget; - int gcnum, id, product_id, ret; + int gcnum, id, ret; printk(KERN_INFO "android_bind\n"); @@ -325,8 +342,8 @@ static int android_bind(struct usb_composite_dev *cdev) usb_gadget_set_selfpowered(gadget); dev->cdev = cdev; - product_id = get_product_id(dev); - device_desc.idProduct = __constant_cpu_to_le16(product_id); + device_desc.idVendor = __constant_cpu_to_le16(get_vendor_id(dev)); + device_desc.idProduct = __constant_cpu_to_le16(get_product_id(dev)); cdev->desc.idProduct = device_desc.idProduct; return 0; @@ -396,7 +413,6 @@ void android_enable_function(struct usb_function *f, int enable) { struct android_dev *dev = _android_dev; int disable = !enable; - int product_id; if (!!f->disabled != disable) { usb_function_set_enabled(f, !disable); @@ -418,8 +434,8 @@ void android_enable_function(struct usb_function *f, int enable) update_dev_desc(dev); - product_id = get_product_id(dev); - device_desc.idProduct = __constant_cpu_to_le16(product_id); + device_desc.idVendor = __constant_cpu_to_le16(get_vendor_id(dev)); + device_desc.idProduct = __constant_cpu_to_le16(get_product_id(dev)); if (dev->cdev) dev->cdev->desc.idProduct = device_desc.idProduct; usb_composite_force_reset(dev->cdev); @@ -438,9 +454,11 @@ static int android_probe(struct platform_device *pdev) dev->num_products = pdata->num_products; dev->functions = pdata->functions; dev->num_functions = pdata->num_functions; - if (pdata->vendor_id) + if (pdata->vendor_id) { + dev->vendor_id = pdata->vendor_id; device_desc.idVendor = __constant_cpu_to_le16(pdata->vendor_id); + } if (pdata->product_id) { dev->product_id = pdata->product_id; device_desc.idProduct = diff --git a/include/linux/usb/android_composite.h b/include/linux/usb/android_composite.h index 62e72e3bd2b6..7f9000711f4e 100644 --- a/include/linux/usb/android_composite.h +++ b/include/linux/usb/android_composite.h @@ -27,7 +27,12 @@ struct android_usb_function { }; struct android_usb_product { - /* Default product ID. */ + /* Vendor ID for this set of functions. + * Default vendor_id in platform data will be used if this is zero. + */ + __u16 vendor_id; + + /* Product ID for this set of functions. */ __u16 product_id; /* List of function names associated with this product. From f35c505ce33f5cb97dca9532c510740a666161e4 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Thu, 10 Feb 2011 11:54:53 -0500 Subject: [PATCH 3/8] USB: gadget: f_mtp: Don't block in mtp_send_event We used to wait for the previous interrupt packet to complete before sending the next packet. But unfortunately the previous packet will not complete until USB is disconnected if the host is not listening on the interrupt endpoint (which is the case with libmtp on Linux and Mac). To avoid hanging indefinitely in this case, we now simply return -EBUSY if the previous interrupt packet has not completed yet. Signed-off-by: Mike Lockwood --- drivers/usb/gadget/f_mtp.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/usb/gadget/f_mtp.c b/drivers/usb/gadget/f_mtp.c index d560fbcf4f58..8128b203e76f 100644 --- a/drivers/usb/gadget/f_mtp.c +++ b/drivers/usb/gadget/f_mtp.c @@ -92,7 +92,6 @@ struct mtp_dev { wait_queue_head_t read_wq; wait_queue_head_t write_wq; - wait_queue_head_t intr_wq; struct usb_request *rx_req[RX_REQ_MAX]; struct usb_request *intr_req; int rx_done; @@ -373,12 +372,11 @@ static void mtp_complete_intr(struct usb_ep *ep, struct usb_request *req) { struct mtp_dev *dev = _mtp_dev; - DBG(dev->cdev, "mtp_complete_intr status: %d actual: %d\n", req->status, req->actual); + DBG(dev->cdev, "mtp_complete_intr status: %d actual: %d\n", + req->status, req->actual); dev->intr_busy = 0; if (req->status != 0) dev->state = STATE_ERROR; - - wake_up(&dev->intr_wq); } static int __init create_bulk_endpoints(struct mtp_dev *dev, @@ -798,13 +796,15 @@ static int mtp_send_event(struct mtp_dev *dev, struct mtp_event *event) if (length < 0 || length > INTR_BUFFER_SIZE) return -EINVAL; - - /* wait for a request to complete */ - ret = wait_event_interruptible(dev->intr_wq, !dev->intr_busy || dev->state == STATE_OFFLINE); - if (ret < 0) - return ret; if (dev->state == STATE_OFFLINE) return -ENODEV; + /* unfortunately an interrupt request might hang indefinitely if the host + * is not listening on the interrupt endpoint, so instead of waiting, + * we just fail if the endpoint is busy. + */ + if (dev->intr_busy) + return -EBUSY; + req = dev->intr_req; if (copy_from_user(req->buf, (void __user *)event->data, length)) return -EFAULT; @@ -1016,7 +1016,6 @@ mtp_function_unbind(struct usb_configuration *c, struct usb_function *f) mtp_request_free(dev->intr_req, dev->ep_intr); dev->state = STATE_OFFLINE; spin_unlock_irq(&dev->lock); - wake_up(&dev->intr_wq); misc_deregister(&mtp_device); kfree(_mtp_dev); @@ -1180,7 +1179,6 @@ static void mtp_function_disable(struct usb_function *f) /* readers may be blocked waiting for us to go online */ wake_up(&dev->read_wq); - wake_up(&dev->intr_wq); VDBG(cdev, "%s disabled\n", dev->function.name); } @@ -1208,7 +1206,6 @@ static int mtp_bind_config(struct usb_configuration *c) spin_lock_init(&dev->lock); init_waitqueue_head(&dev->read_wq); init_waitqueue_head(&dev->write_wq); - init_waitqueue_head(&dev->intr_wq); atomic_set(&dev->open_excl, 0); atomic_set(&dev->ioctl_excl, 0); INIT_LIST_HEAD(&dev->tx_idle); From 8ef8637eef2d56187d947e0db762c02988c0c5f6 Mon Sep 17 00:00:00 2001 From: Benoit Goby Date: Mon, 7 Feb 2011 13:55:26 -0800 Subject: [PATCH 4/8] PM: Increase dpm suspend timeout usbhid devices have a 10s timeout waiting for the out queue to clear. Increased the watchdog to 12s. Change-Id: I96368fca6dff98e4eba8aedb09c23be964c8f4b4 Signed-off-by: Benoit Goby --- drivers/base/power/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 4ff491f49ee4..1ba3de8015b5 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -881,7 +881,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) data.dev = dev; data.tsk = get_current(); init_timer_on_stack(&timer); - timer.expires = jiffies + HZ * 3; + timer.expires = jiffies + HZ * 12; timer.function = dpm_drv_timeout; timer.data = (unsigned long)&data; add_timer(&timer); From a14be8e976554dc59c06d6d769a368601dff12af Mon Sep 17 00:00:00 2001 From: Dmitry Shmidt Date: Fri, 11 Feb 2011 16:54:39 -0800 Subject: [PATCH 5/8] net: wireless: bcm4329: Add sdlock to firmware loading Signed-off-by: Dmitry Shmidt --- drivers/net/wireless/bcm4329/dhd_linux.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/bcm4329/dhd_linux.c b/drivers/net/wireless/bcm4329/dhd_linux.c index c7ef3edd908f..dc0ec1602cd0 100644 --- a/drivers/net/wireless/bcm4329/dhd_linux.c +++ b/drivers/net/wireless/bcm4329/dhd_linux.c @@ -2185,12 +2185,15 @@ dhd_bus_start(dhd_pub_t *dhdp) DHD_TRACE(("%s: \n", __FUNCTION__)); + dhd_os_sdlock(dhdp); + /* try to download image and nvram to the dongle */ if (dhd->pub.busstate == DHD_BUS_DOWN) { if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh, fw_path, nv_path))) { DHD_ERROR(("%s: dhdsdio_probe_download failed. firmware = %s nvram = %s\n", __FUNCTION__, fw_path, nv_path)); + dhd_os_sdunlock(dhdp); return -1; } } @@ -2200,8 +2203,9 @@ dhd_bus_start(dhd_pub_t *dhdp) dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms); /* Bring up the bus */ - if ((ret = dhd_bus_init(&dhd->pub, TRUE)) != 0) { + if ((ret = dhd_bus_init(&dhd->pub, FALSE)) != 0) { DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret)); + dhd_os_sdunlock(dhdp); return ret; } #if defined(OOB_INTR_ONLY) @@ -2210,6 +2214,7 @@ dhd_bus_start(dhd_pub_t *dhdp) dhd->wd_timer_valid = FALSE; del_timer_sync(&dhd->timer); DHD_ERROR(("%s Host failed to resgister for OOB\n", __FUNCTION__)); + dhd_os_sdunlock(dhdp); return -ENODEV; } @@ -2222,9 +2227,12 @@ dhd_bus_start(dhd_pub_t *dhdp) dhd->wd_timer_valid = FALSE; del_timer_sync(&dhd->timer); DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__)); + dhd_os_sdunlock(dhdp); return -ENODEV; } + dhd_os_sdunlock(dhdp); + #ifdef EMBEDDED_PLATFORM bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf)); dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf)); From fc4d5028cab51af9c25a0b9afaadfe1383e0b2eb Mon Sep 17 00:00:00 2001 From: Andrei Warkentin Date: Fri, 11 Feb 2011 17:01:28 -0800 Subject: [PATCH 6/8] net: wireless: bcm4329: Fix memleak in dev->p Signed-off-by: Dmitry Shmidt --- drivers/net/wireless/bcm4329/bcmsdh_linux.c | 12 +++++++----- drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c | 10 +++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/bcm4329/bcmsdh_linux.c b/drivers/net/wireless/bcm4329/bcmsdh_linux.c index 3b7da4263fd8..1e33555b0531 100644 --- a/drivers/net/wireless/bcm4329/bcmsdh_linux.c +++ b/drivers/net/wireless/bcm4329/bcmsdh_linux.c @@ -301,7 +301,7 @@ int bcmsdh_remove(struct device *dev) MFREE(osh, sdhc, sizeof(bcmsdh_hc_t)); osl_detach(osh); -#if !defined(BCMLXSDMMC) +#if !defined(BCMLXSDMMC) || defined(OOB_INTR_ONLY) dev_set_drvdata(dev, NULL); #endif /* !defined(BCMLXSDMMC) */ @@ -647,10 +647,12 @@ void bcmsdh_unregister_oob_intr(void) { SDLX_MSG(("%s: Enter\n", __FUNCTION__)); - set_irq_wake(sdhcinfo->oob_irq, 0); - disable_irq(sdhcinfo->oob_irq); /* just in case.. */ - free_irq(sdhcinfo->oob_irq, NULL); - sdhcinfo->oob_irq_registered = FALSE; + if (sdhcinfo->oob_irq_registered) { + set_irq_wake(sdhcinfo->oob_irq, 0); + disable_irq(sdhcinfo->oob_irq); /* just in case.. */ + free_irq(sdhcinfo->oob_irq, NULL); + sdhcinfo->oob_irq_registered = FALSE; + } } #endif /* defined(OOB_INTR_ONLY) */ /* Module parameters specific to each host-controller driver */ diff --git a/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c b/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c index 8992a4267f9f..5a1a46c93571 100644 --- a/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c +++ b/drivers/net/wireless/bcm4329/bcmsdh_sdmmc_linux.c @@ -82,7 +82,6 @@ PBCMSDH_SDMMC_INSTANCE gInstance; extern int bcmsdh_probe(struct device *dev); extern int bcmsdh_remove(struct device *dev); -struct device sdmmc_dev; static int bcmsdh_sdmmc_probe(struct sdio_func *func, const struct sdio_device_id *id) @@ -102,7 +101,7 @@ static int bcmsdh_sdmmc_probe(struct sdio_func *func, if(func->device == 0x4) { /* 4318 */ gInstance->func[2] = NULL; sd_trace(("NIC found, calling bcmsdh_probe...\n")); - ret = bcmsdh_probe(&sdmmc_dev); + ret = bcmsdh_probe(&func->dev); } } @@ -110,7 +109,7 @@ static int bcmsdh_sdmmc_probe(struct sdio_func *func, if (func->num == 2) { sd_trace(("F2 found, calling bcmsdh_probe...\n")); - ret = bcmsdh_probe(&sdmmc_dev); + ret = bcmsdh_probe(&func->dev); } return ret; @@ -126,7 +125,7 @@ static void bcmsdh_sdmmc_remove(struct sdio_func *func) if (func->num == 2) { sd_trace(("F2 found, calling bcmsdh_remove...\n")); - bcmsdh_remove(&sdmmc_dev); + bcmsdh_remove(&func->dev); } } @@ -250,10 +249,8 @@ int sdio_function_init(void) if (!gInstance) return -ENOMEM; - bzero(&sdmmc_dev, sizeof(sdmmc_dev)); error = sdio_register_driver(&bcmsdh_sdmmc_driver); - return error; } @@ -265,7 +262,6 @@ void sdio_function_cleanup(void) { sd_trace(("%s Enter\n", __FUNCTION__)); - sdio_unregister_driver(&bcmsdh_sdmmc_driver); if (gInstance) From 4c0d9cf8d550d5a2b4318f950127fdc086e5b023 Mon Sep 17 00:00:00 2001 From: Mike Corrigan Date: Fri, 11 Feb 2011 17:05:54 -0800 Subject: [PATCH 7/8] net: wireless: bcm4329: Fix mem leak in wl_iw_handle_scanresults_ies Signed-off-by: Dmitry Shmidt --- drivers/net/wireless/bcm4329/wl_iw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/bcm4329/wl_iw.c b/drivers/net/wireless/bcm4329/wl_iw.c index 8460804c945a..00222196f6e4 100644 --- a/drivers/net/wireless/bcm4329/wl_iw.c +++ b/drivers/net/wireless/bcm4329/wl_iw.c @@ -3686,6 +3686,7 @@ wl_iw_handle_scanresults_ies(char **event_p, char *end, wpa_snprintf_hex(buf + 10, 2+1, &(ie->len), 1); wpa_snprintf_hex(buf + 12, 2*ie->len+1, ie->data, ie->len); event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, buf); + kfree(buf); #endif break; } From 1cd64ef5c1becb1c70c432bdcae98fdb686a8173 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Sat, 12 Feb 2011 13:21:32 -0800 Subject: [PATCH 8/8] Revert "mmc: subtract boot sectors from disk size for eMMC 4.3+ devices" This reverts commit f0b0e4bec1e89014f3dcef4da8bcf95428cc771c. The reverted commit incorrectly calculates the size of eMMC devices in some (all?) cases. This revert may cause problems in cases where the bootloader was bug-compatible and puts a GPT partition at the incorrect end of the eMMC device. Change-Id: Ib006acf9e517b3b8f7570220c28e19c91e7b5f25 Signed-off-by: Colin Cross --- drivers/mmc/core/mmc.c | 7 +------ include/linux/mmc/mmc.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 45055c46d954..6909a54c39be 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -253,13 +253,8 @@ static int mmc_read_ext_csd(struct mmc_card *card) ext_csd[EXT_CSD_SEC_CNT + 3] << 24; /* Cards with density > 2GiB are sector addressed */ - if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) { - unsigned boot_sectors; - /* size is in 256K chunks, i.e. 512 sectors each */ - boot_sectors = ext_csd[EXT_CSD_BOOT_SIZE_MULTI] * 512; - card->ext_csd.sectors -= boot_sectors; + if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) mmc_card_set_blockaddr(card); - } } switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 1041cf5220f6..dd11ae51fb68 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -266,7 +266,6 @@ struct _mmc_csd { #define EXT_CSD_SEC_ERASE_MULT 230 /* RO */ #define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */ #define EXT_CSD_TRIM_MULT 232 /* RO */ -#define EXT_CSD_BOOT_SIZE_MULTI 226 /* RO */ /* * EXT_CSD field definitions