Skip to content

Commit 917522a

Browse files
Frederic Danisholtmann
authored andcommitted
Bluetooth: hci_bcm: Fix crash on suspend
If bcm_suspend is called whithout device opened there is a crash as it tries to use bdev->hu which is NULL. Rename bcm_device_list_lock to bcm_device_lock as it does not only apply to bcm_device_list. Signed-off-by: Frederic Danis <frederic.danis@linux.intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 618353b commit 917522a

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

drivers/bluetooth/hci_bcm.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct bcm_data {
6666
};
6767

6868
/* List of BCM BT UART devices */
69-
static DEFINE_SPINLOCK(bcm_device_list_lock);
69+
static DEFINE_SPINLOCK(bcm_device_lock);
7070
static LIST_HEAD(bcm_device_list);
7171

7272
static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
@@ -118,7 +118,7 @@ static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
118118
return 0;
119119
}
120120

121-
/* bcm_device_exists should be protected by bcm_device_list_lock */
121+
/* bcm_device_exists should be protected by bcm_device_lock */
122122
static bool bcm_device_exists(struct bcm_device *device)
123123
{
124124
struct list_head *p;
@@ -164,7 +164,7 @@ static int bcm_open(struct hci_uart *hu)
164164

165165
hu->priv = bcm;
166166

167-
spin_lock(&bcm_device_list_lock);
167+
spin_lock(&bcm_device_lock);
168168
list_for_each(p, &bcm_device_list) {
169169
struct bcm_device *dev = list_entry(p, struct bcm_device, list);
170170

@@ -185,7 +185,7 @@ static int bcm_open(struct hci_uart *hu)
185185
if (bcm->dev)
186186
bcm_gpio_set_power(bcm->dev, true);
187187

188-
spin_unlock(&bcm_device_list_lock);
188+
spin_unlock(&bcm_device_lock);
189189

190190
return 0;
191191
}
@@ -197,14 +197,14 @@ static int bcm_close(struct hci_uart *hu)
197197
BT_DBG("hu %p", hu);
198198

199199
/* Protect bcm->dev against removal of the device or driver */
200-
spin_lock(&bcm_device_list_lock);
200+
spin_lock(&bcm_device_lock);
201201
if (bcm_device_exists(bcm->dev)) {
202202
bcm_gpio_set_power(bcm->dev, false);
203203
#ifdef CONFIG_PM_SLEEP
204204
bcm->dev->hu = NULL;
205205
#endif
206206
}
207-
spin_unlock(&bcm_device_list_lock);
207+
spin_unlock(&bcm_device_lock);
208208

209209
skb_queue_purge(&bcm->txq);
210210
kfree_skb(bcm->rx_skb);
@@ -338,6 +338,11 @@ static int bcm_suspend(struct device *dev)
338338

339339
BT_DBG("suspend (%p): is_suspended %d", bdev, bdev->is_suspended);
340340

341+
spin_lock(&bcm_device_lock);
342+
343+
if (!bdev->hu)
344+
goto unlock;
345+
341346
if (!bdev->is_suspended) {
342347
hci_uart_set_flow_control(bdev->hu, true);
343348

@@ -352,6 +357,9 @@ static int bcm_suspend(struct device *dev)
352357
mdelay(15);
353358
}
354359

360+
unlock:
361+
spin_unlock(&bcm_device_lock);
362+
355363
return 0;
356364
}
357365

@@ -362,6 +370,11 @@ static int bcm_resume(struct device *dev)
362370

363371
BT_DBG("resume (%p): is_suspended %d", bdev, bdev->is_suspended);
364372

373+
spin_lock(&bcm_device_lock);
374+
375+
if (!bdev->hu)
376+
goto unlock;
377+
365378
if (bdev->device_wakeup) {
366379
gpiod_set_value(bdev->device_wakeup, true);
367380
BT_DBG("resume, delaying 15 ms");
@@ -375,6 +388,9 @@ static int bcm_resume(struct device *dev)
375388
hci_uart_set_flow_control(bdev->hu, false);
376389
}
377390

391+
unlock:
392+
spin_unlock(&bcm_device_lock);
393+
378394
return 0;
379395
}
380396
#endif
@@ -488,9 +504,9 @@ static int bcm_probe(struct platform_device *pdev)
488504
dev_info(&pdev->dev, "%s device registered.\n", dev->name);
489505

490506
/* Place this instance on the device list */
491-
spin_lock(&bcm_device_list_lock);
507+
spin_lock(&bcm_device_lock);
492508
list_add_tail(&dev->list, &bcm_device_list);
493-
spin_unlock(&bcm_device_list_lock);
509+
spin_unlock(&bcm_device_lock);
494510

495511
bcm_gpio_set_power(dev, false);
496512

@@ -501,9 +517,9 @@ static int bcm_remove(struct platform_device *pdev)
501517
{
502518
struct bcm_device *dev = platform_get_drvdata(pdev);
503519

504-
spin_lock(&bcm_device_list_lock);
520+
spin_lock(&bcm_device_lock);
505521
list_del(&dev->list);
506-
spin_unlock(&bcm_device_list_lock);
522+
spin_unlock(&bcm_device_lock);
507523

508524
acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pdev->dev));
509525

0 commit comments

Comments
 (0)