From 669c9af0275dbd619b9028147cc991a824dac232 Mon Sep 17 00:00:00 2001 From: Mahesh Kumar Sharma Date: Wed, 27 Jan 2021 10:12:14 -0800 Subject: [PATCH] Bluetooth: Add conditional check before requesting gpio Add a condition check before calling gpio_request in order to avoid non-fatal panic. Change-Id: Id77b99b0a7c119efb75e50c85ec185895dd8c031 Signed-off-by: Mahesh Kumar Sharma --- drivers/bluetooth/btpower.c | 39 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/bluetooth/btpower.c b/drivers/bluetooth/btpower.c index 49e74583aa8b..d44379321481 100644 --- a/drivers/bluetooth/btpower.c +++ b/drivers/bluetooth/btpower.c @@ -398,25 +398,30 @@ static int bt_configure_gpios(int on) bt_power_src_status[BT_RESET_GPIO] = gpio_get_value(bt_reset_gpio); } - rc = gpio_request(xo_reset_gpio, "xo_reset_gpio_n"); - if (rc) { - pr_err("%s: unable to request gpio %d (%d)\n", + + pr_info("xo_reset_gpio(%d)\n", xo_reset_gpio); + + if (xo_reset_gpio > 0) { + rc = gpio_request(xo_reset_gpio, "xo_reset_gpio_n"); + if (rc) { + pr_err("%s: unable to request gpio %d (%d)\n", __func__, xo_reset_gpio, rc); - } else { - pr_info("%s: gpio_request for xo_reset_gpio succeed\n", + } else { + pr_info("%s: gpio_request for xo_reset_gpio succeed\n", __func__); - //pull GPIO high - rc = gpio_direction_output(xo_reset_gpio, 1); - if (rc) { - pr_err("%s: Unable to set direction of xo_reset_gpio\n", - __func__); - } - udelay(2000); - //pull GPIO low after 2 ms delay - rc = gpio_direction_output(xo_reset_gpio, 0); - if (rc) { - pr_err("%s: Unable to set direction of xo_reset_gpio\n", - __func__); + //pull GPIO high + rc = gpio_direction_output(xo_reset_gpio, 1); + if (rc) { + pr_err("%s: Unable to set direction of xo_reset_gpio\n", + __func__); + } + udelay(2000); + //pull GPIO low after 2 ms delay + rc = gpio_direction_output(xo_reset_gpio, 0); + if (rc) { + pr_err("%s: Unable to set direction of xo_reset_gpio\n", + __func__); + } } } msleep(50);