Merge "Bluetooth: Protect request_firmware with a semaphore for btusb"

This commit is contained in:
Linux Build Service Account 2015-04-28 06:30:08 -07:00 committed by Gerrit - the friendly Code Review server
commit 504174389b
3 changed files with 59 additions and 6 deletions

View File

@ -422,6 +422,9 @@ static int ath3k_set_normal_mode(struct usb_device *udev)
NULL, 0, USB_CTRL_SET_TIMEOUT);
}
DECLARE_RWSEM(btusb_pm_sem);
EXPORT_SYMBOL(btusb_pm_sem);
static int ath3k_load_patch(struct usb_device *udev,
struct ath3k_version *version)
{
@ -441,12 +444,10 @@ static int ath3k_load_patch(struct usb_device *udev,
if ((fw_state == ATH3K_PATCH_UPDATE) ||
(fw_state == ATH3K_PATCH_SYSCFG_UPDATE)) {
BT_INFO("%s: Patch already downloaded(fw_state: %d)", __func__,
fw_state);
BT_INFO("Patch already downloaded(fw_state: %d)", fw_state);
return 0;
} else
BT_DBG("%s: Downloading RamPatch(fw_state: %d)", __func__,
fw_state);
BT_DBG("Downloading RamPatch(fw_state: %d)", fw_state);
switch (version->rom_version) {
case ROME1_1_USB_CHIP_VERSION:
@ -478,11 +479,14 @@ static int ath3k_load_patch(struct usb_device *udev,
break;
}
down_read(&btusb_pm_sem);
ret = request_firmware(&firmware, filename, &udev->dev);
if (ret < 0) {
BT_ERR("Patch file not found %s", filename);
up_read(&btusb_pm_sem);
return ret;
}
up_read(&btusb_pm_sem);
if ((version->rom_version == ROME2_1_USB_CHIP_VERSION) ||
(version->rom_version == ROME3_0_USB_CHIP_VERSION) ||

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 2008-2009 Atheros Communications Inc.
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
* Copyright (c) 2014,2015 The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@ -25,3 +25,5 @@ struct ath3k_version {
int get_rome_version(struct usb_device *udev, struct ath3k_version *version);
int rome_download(struct usb_device *udev, struct ath3k_version *version);
extern struct rw_semaphore btusb_pm_sem;

View File

@ -23,6 +23,7 @@
#include <linux/module.h>
#include <linux/usb.h>
#include <linux/firmware.h>
#include <linux/suspend.h>
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h>
@ -1655,6 +1656,29 @@ done:
}
#endif
static unsigned long btusb_pm_flags;
#define BTUSB_PM_SUSPEND (1)
static int btusb_pm_notify(struct notifier_block *b,
unsigned long event, void *p)
{
switch (event) {
case PM_SUSPEND_PREPARE:
set_bit(BTUSB_PM_SUSPEND, &btusb_pm_flags);
down_write(&btusb_pm_sem);
break;
case PM_POST_SUSPEND:
up_write(&btusb_pm_sem);
clear_bit(BTUSB_PM_SUSPEND, &btusb_pm_flags);
break;
}
return NOTIFY_DONE;
}
static struct notifier_block btusb_pm_notifier = {
.notifier_call = btusb_pm_notify,
};
static struct usb_driver btusb_driver = {
.name = "btusb",
.probe = btusb_probe,
@ -1668,7 +1692,30 @@ static struct usb_driver btusb_driver = {
.disable_hub_initiated_lpm = 1,
};
module_usb_driver(btusb_driver);
static int __init btusb_driver_init(void)
{
int ret = 0;
ret = usb_register(&btusb_driver);
/* ignore return value */
register_pm_notifier(&btusb_pm_notifier);
return ret;
}
module_init(btusb_driver_init);
static void __exit btusb_driver_exit(void)
{
unregister_pm_notifier(&btusb_pm_notifier);
/*
* If unregister gets called before resume notification, we need to
* release the semaphore to avoid deadlock.
*/
if (test_bit(BTUSB_PM_SUSPEND, &btusb_pm_flags)) {
up_write(&btusb_pm_sem);
clear_bit(BTUSB_PM_SUSPEND, &btusb_pm_flags);
}
usb_deregister(&btusb_driver);
}
module_exit(btusb_driver_exit);
module_param(ignore_dga, bool, 0644);
MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");