diff options
author | Hans de Goede <hdegoede@redhat.com> | 2018-05-27 15:04:52 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2018-05-30 02:47:42 -0400 |
commit | e9ca08074ddcdcc3abacbfca888dba3a110e4453 (patch) | |
tree | 8f7a3c087c647e3600d5b62bc98b15786e60e0bd | |
parent | 412fe29ffcf9a1ba9f125e72ee3da957cd6a0064 (diff) |
Bluetooth: hci_serdev: Move serdev_device_close/open into common hci_serdev code
Make hci_uart_register_device() and hci_uart_unregister_device() call
serdev_device_close()/open() themselves instead of relying on the various
hci_uart drivers to do this for them.
Besides reducing code complexity, this also ensures correct error checking
of serdev_device_open(), which was missing in a few drivers.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r-- | drivers/bluetooth/hci_bcm.c | 10 | ||||
-rw-r--r-- | drivers/bluetooth/hci_ll.c | 3 | ||||
-rw-r--r-- | drivers/bluetooth/hci_nokia.c | 3 | ||||
-rw-r--r-- | drivers/bluetooth/hci_serdev.c | 9 |
4 files changed, 9 insertions, 16 deletions
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index f06f0f1132fb..ddbd8c6a0ceb 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c | |||
@@ -380,10 +380,6 @@ static int bcm_open(struct hci_uart *hu) | |||
380 | mutex_lock(&bcm_device_lock); | 380 | mutex_lock(&bcm_device_lock); |
381 | 381 | ||
382 | if (hu->serdev) { | 382 | if (hu->serdev) { |
383 | err = serdev_device_open(hu->serdev); | ||
384 | if (err) | ||
385 | goto err_free; | ||
386 | |||
387 | bcm->dev = serdev_device_get_drvdata(hu->serdev); | 383 | bcm->dev = serdev_device_get_drvdata(hu->serdev); |
388 | goto out; | 384 | goto out; |
389 | } | 385 | } |
@@ -420,13 +416,10 @@ out: | |||
420 | return 0; | 416 | return 0; |
421 | 417 | ||
422 | err_unset_hu: | 418 | err_unset_hu: |
423 | if (hu->serdev) | ||
424 | serdev_device_close(hu->serdev); | ||
425 | #ifdef CONFIG_PM | 419 | #ifdef CONFIG_PM |
426 | else | 420 | if (!hu->serdev) |
427 | bcm->dev->hu = NULL; | 421 | bcm->dev->hu = NULL; |
428 | #endif | 422 | #endif |
429 | err_free: | ||
430 | mutex_unlock(&bcm_device_lock); | 423 | mutex_unlock(&bcm_device_lock); |
431 | hu->priv = NULL; | 424 | hu->priv = NULL; |
432 | kfree(bcm); | 425 | kfree(bcm); |
@@ -445,7 +438,6 @@ static int bcm_close(struct hci_uart *hu) | |||
445 | mutex_lock(&bcm_device_lock); | 438 | mutex_lock(&bcm_device_lock); |
446 | 439 | ||
447 | if (hu->serdev) { | 440 | if (hu->serdev) { |
448 | serdev_device_close(hu->serdev); | ||
449 | bdev = serdev_device_get_drvdata(hu->serdev); | 441 | bdev = serdev_device_get_drvdata(hu->serdev); |
450 | } else if (bcm_device_exists(bcm->dev)) { | 442 | } else if (bcm_device_exists(bcm->dev)) { |
451 | bdev = bcm->dev; | 443 | bdev = bcm->dev; |
diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c index 27e414b4e3a2..3e767f245ed5 100644 --- a/drivers/bluetooth/hci_ll.c +++ b/drivers/bluetooth/hci_ll.c | |||
@@ -141,7 +141,6 @@ static int ll_open(struct hci_uart *hu) | |||
141 | 141 | ||
142 | if (hu->serdev) { | 142 | if (hu->serdev) { |
143 | struct ll_device *lldev = serdev_device_get_drvdata(hu->serdev); | 143 | struct ll_device *lldev = serdev_device_get_drvdata(hu->serdev); |
144 | serdev_device_open(hu->serdev); | ||
145 | if (!IS_ERR(lldev->ext_clk)) | 144 | if (!IS_ERR(lldev->ext_clk)) |
146 | clk_prepare_enable(lldev->ext_clk); | 145 | clk_prepare_enable(lldev->ext_clk); |
147 | } | 146 | } |
@@ -179,8 +178,6 @@ static int ll_close(struct hci_uart *hu) | |||
179 | gpiod_set_value_cansleep(lldev->enable_gpio, 0); | 178 | gpiod_set_value_cansleep(lldev->enable_gpio, 0); |
180 | 179 | ||
181 | clk_disable_unprepare(lldev->ext_clk); | 180 | clk_disable_unprepare(lldev->ext_clk); |
182 | |||
183 | serdev_device_close(hu->serdev); | ||
184 | } | 181 | } |
185 | 182 | ||
186 | hu->priv = NULL; | 183 | hu->priv = NULL; |
diff --git a/drivers/bluetooth/hci_nokia.c b/drivers/bluetooth/hci_nokia.c index 3539fd03f47e..14d159e2042d 100644 --- a/drivers/bluetooth/hci_nokia.c +++ b/drivers/bluetooth/hci_nokia.c | |||
@@ -477,8 +477,6 @@ static int nokia_open(struct hci_uart *hu) | |||
477 | 477 | ||
478 | dev_dbg(dev, "protocol open"); | 478 | dev_dbg(dev, "protocol open"); |
479 | 479 | ||
480 | serdev_device_open(hu->serdev); | ||
481 | |||
482 | pm_runtime_enable(dev); | 480 | pm_runtime_enable(dev); |
483 | 481 | ||
484 | return 0; | 482 | return 0; |
@@ -513,7 +511,6 @@ static int nokia_close(struct hci_uart *hu) | |||
513 | gpiod_set_value(btdev->wakeup_bt, 0); | 511 | gpiod_set_value(btdev->wakeup_bt, 0); |
514 | 512 | ||
515 | pm_runtime_disable(&btdev->serdev->dev); | 513 | pm_runtime_disable(&btdev->serdev->dev); |
516 | serdev_device_close(btdev->serdev); | ||
517 | 514 | ||
518 | return 0; | 515 | return 0; |
519 | } | 516 | } |
diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index 6a713f13f71c..7a3d6d636192 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c | |||
@@ -284,10 +284,14 @@ int hci_uart_register_device(struct hci_uart *hu, | |||
284 | 284 | ||
285 | serdev_device_set_client_ops(hu->serdev, &hci_serdev_client_ops); | 285 | serdev_device_set_client_ops(hu->serdev, &hci_serdev_client_ops); |
286 | 286 | ||
287 | err = p->open(hu); | 287 | err = serdev_device_open(hu->serdev); |
288 | if (err) | 288 | if (err) |
289 | return err; | 289 | return err; |
290 | 290 | ||
291 | err = p->open(hu); | ||
292 | if (err) | ||
293 | goto err_open; | ||
294 | |||
291 | hu->proto = p; | 295 | hu->proto = p; |
292 | set_bit(HCI_UART_PROTO_READY, &hu->flags); | 296 | set_bit(HCI_UART_PROTO_READY, &hu->flags); |
293 | 297 | ||
@@ -353,6 +357,8 @@ err_register: | |||
353 | err_alloc: | 357 | err_alloc: |
354 | clear_bit(HCI_UART_PROTO_READY, &hu->flags); | 358 | clear_bit(HCI_UART_PROTO_READY, &hu->flags); |
355 | p->close(hu); | 359 | p->close(hu); |
360 | err_open: | ||
361 | serdev_device_close(hu->serdev); | ||
356 | return err; | 362 | return err; |
357 | } | 363 | } |
358 | EXPORT_SYMBOL_GPL(hci_uart_register_device); | 364 | EXPORT_SYMBOL_GPL(hci_uart_register_device); |
@@ -367,5 +373,6 @@ void hci_uart_unregister_device(struct hci_uart *hu) | |||
367 | cancel_work_sync(&hu->write_work); | 373 | cancel_work_sync(&hu->write_work); |
368 | 374 | ||
369 | hu->proto->close(hu); | 375 | hu->proto->close(hu); |
376 | serdev_device_close(hu->serdev); | ||
370 | } | 377 | } |
371 | EXPORT_SYMBOL_GPL(hci_uart_unregister_device); | 378 | EXPORT_SYMBOL_GPL(hci_uart_unregister_device); |