Bluetooth: btrtl: Add null check in setup
diff mbox series

Message ID 20201222184753.1.I9438ef1f79fa1132e74c67b489123291080b9a8c@changeid
State New, archived
Headers show
Series
  • Bluetooth: btrtl: Add null check in setup
Related show

Commit Message

Abhishek Pandit-Subedi Dec. 23, 2020, 2:48 a.m. UTC
btrtl_dev->ic_info is only available from the controller on cold boot
(the lmp subversion matches the device model and this is used to look up
the ic_info). On warm boots (firmware already loaded),
btrtl_dev->ic_info is null.

Fixes: 05672a2c14a4 (Bluetooth: btrtl: Enable central-peripheral role)
Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
---

 drivers/bluetooth/btrtl.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Marcel Holtmann Dec. 23, 2020, 6:22 a.m. UTC | #1
Hi Abhishek,

> btrtl_dev->ic_info is only available from the controller on cold boot
> (the lmp subversion matches the device model and this is used to look up
> the ic_info). On warm boots (firmware already loaded),
> btrtl_dev->ic_info is null.
> 
> Fixes: 05672a2c14a4 (Bluetooth: btrtl: Enable central-peripheral role)
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> ---
> 
> drivers/bluetooth/btrtl.c | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
> index 1abf6a4d672734f..978f3c773856b05 100644
> --- a/drivers/bluetooth/btrtl.c
> +++ b/drivers/bluetooth/btrtl.c
> @@ -719,16 +719,19 @@ int btrtl_setup_realtek(struct hci_dev *hdev)
> 	 */
> 	set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
> 
> -	/* Enable central-peripheral role (able to create new connections with
> -	 * an existing connection in slave role).
> -	 */
> -	switch (btrtl_dev->ic_info->lmp_subver) {
> -	case RTL_ROM_LMP_8822B:
> -		set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
> -		break;
> -	default:
> -		rtl_dev_dbg(hdev, "Central-peripheral role not enabled.");
> -		break;
> +	if (btrtl_dev->ic_info) {
> +		/* Enable central-peripheral role (able to create new
> +		 * connections with an existing connection in slave role).
> +		 */
> +		switch (btrtl_dev->ic_info->lmp_subver) {
> +		case RTL_ROM_LMP_8822B:
> +			set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
> +			break;
> +		default:
> +			rtl_dev_dbg(hdev,
> +				    "Central-peripheral role not enabled.");
> +			break;
> +		}
> 	}


	if (!btrtl_dev->ic_info)
		goto done;

> 
> 	btrtl_free(btrtl_dev);

Regards

Marcel

Patch
diff mbox series

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index 1abf6a4d672734f..978f3c773856b05 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -719,16 +719,19 @@  int btrtl_setup_realtek(struct hci_dev *hdev)
 	 */
 	set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
 
-	/* Enable central-peripheral role (able to create new connections with
-	 * an existing connection in slave role).
-	 */
-	switch (btrtl_dev->ic_info->lmp_subver) {
-	case RTL_ROM_LMP_8822B:
-		set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
-		break;
-	default:
-		rtl_dev_dbg(hdev, "Central-peripheral role not enabled.");
-		break;
+	if (btrtl_dev->ic_info) {
+		/* Enable central-peripheral role (able to create new
+		 * connections with an existing connection in slave role).
+		 */
+		switch (btrtl_dev->ic_info->lmp_subver) {
+		case RTL_ROM_LMP_8822B:
+			set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
+			break;
+		default:
+			rtl_dev_dbg(hdev,
+				    "Central-peripheral role not enabled.");
+			break;
+		}
 	}
 
 	btrtl_free(btrtl_dev);