2024-04-24 15:40:21

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

From: Bartosz Golaszewski <[email protected]>

Any return value from gpiod_get_optional() other than a pointer to a
GPIO descriptor or a NULL-pointer is an error and the driver should
abort probing. That being said: commit 56d074d26c58 ("Bluetooth: hci_qca:
don't use IS_ERR_OR_NULL() with gpiod_get_optional()") no longer sets
power_ctrl_enabled on NULL-pointer returned by
devm_gpiod_get_optional(). Restore this behavior but bail-out on errors.
While at it: also bail-out on error returned when trying to get the
"swctrl" GPIO.

Reported-by: Wren Turkal <[email protected]>
Reported-by: Zijun Hu <[email protected]>
Closes: https://lore.kernel.org/linux-bluetooth/[email protected]/
Fixes: 56d074d26c58 ("Bluetooth: hci_qca: don't use IS_ERR_OR_NULL() with gpiod_get_optional()")
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Bartosz Golaszewski <[email protected]>
---
v1 -> v2:
- also restore the previous behavior for QCA6390 and other models that
fall under the default: label in the affected switch case
- bail-out on errors when getting the swctrl GPIO too

drivers/bluetooth/hci_qca.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 92fa20f5ac7d..0e98ad2c0c9d 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -2327,16 +2327,21 @@ static int qca_serdev_probe(struct serdev_device *serdev)
(data->soc_type == QCA_WCN6750 ||
data->soc_type == QCA_WCN6855)) {
dev_err(&serdev->dev, "failed to acquire BT_EN gpio\n");
- power_ctrl_enabled = false;
+ return PTR_ERR(qcadev->bt_en);
}

+ if (!qcadev->bt_en)
+ power_ctrl_enabled = false;
+
qcadev->sw_ctrl = devm_gpiod_get_optional(&serdev->dev, "swctrl",
GPIOD_IN);
if (IS_ERR(qcadev->sw_ctrl) &&
(data->soc_type == QCA_WCN6750 ||
data->soc_type == QCA_WCN6855 ||
- data->soc_type == QCA_WCN7850))
- dev_warn(&serdev->dev, "failed to acquire SW_CTRL gpio\n");
+ data->soc_type == QCA_WCN7850)) {
+ dev_err(&serdev->dev, "failed to acquire SW_CTRL gpio\n");
+ return PTR_ERR(qcadev->sw_ctrl);
+ }

qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
if (IS_ERR(qcadev->susclk)) {
@@ -2355,10 +2360,13 @@ static int qca_serdev_probe(struct serdev_device *serdev)
qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable",
GPIOD_OUT_LOW);
if (IS_ERR(qcadev->bt_en)) {
- dev_warn(&serdev->dev, "failed to acquire enable gpio\n");
- power_ctrl_enabled = false;
+ dev_err(&serdev->dev, "failed to acquire enable gpio\n");
+ return PTR_ERR(qcadev->bt_en);
}

+ if (!qcadev->bt_en)
+ power_ctrl_enabled = false;
+
qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
if (IS_ERR(qcadev->susclk)) {
dev_warn(&serdev->dev, "failed to acquire clk\n");
--
2.40.1



2024-04-24 15:44:23

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

Hi Quic_zijuhu,

On Wed, Apr 24, 2024 at 11:35 AM quic_zijuhu <[email protected]> wrote:
>
> On 4/24/2024 11:31 PM, Bartosz Golaszewski wrote:
> > On Wed, Apr 24, 2024 at 5:30 PM quic_zijuhu <[email protected]> wrote:
> >>
> >> On 4/24/2024 11:24 PM, quic_zijuhu wrote:
> >>> On 4/24/2024 10:52 PM, Bartosz Golaszewski wrote:
> >>>> On Wed, 24 Apr 2024 at 16:46, Krzysztof Kozlowski
> >>>> <[email protected]> wrote:
> >>>>>
> >>>>> On 24/04/2024 14:29, Bartosz Golaszewski wrote:
> >>>>>> From: Bartosz Golaszewski <[email protected]>
> >>>>>>
> >>>>>
> >>>>>> qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
> >>>>>> if (IS_ERR(qcadev->susclk)) {
> >>>>>> @@ -2355,10 +2360,13 @@ static int qca_serdev_probe(struct serdev_device *serdev)
> >>>>>> qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable",
> >>>>>> GPIOD_OUT_LOW);
> >>>>>> if (IS_ERR(qcadev->bt_en)) {
> >>>>>> - dev_warn(&serdev->dev, "failed to acquire enable gpio\n");
> >>>>>> - power_ctrl_enabled = false;
> >>>>>> + dev_err(&serdev->dev, "failed to acquire enable gpio\n");
> >>>>>> + return PTR_ERR(qcadev->bt_en);
> >>> please think about for QCA2066. if it is returned from here. BT will
> >>> not working at all. if you don't return here. i will be working fine
> >>> for every BT functionality.
> >> sorry, correct a type error, it is QCA6390 not QCA2066.
> >
> > Doesn't matter. If enable-gpios is not there, gpiod_get_optional()
> > will return NULL and we will not return.
> >
> i think i need to explain more for my consider case.
> let me take QCA6390, if the property enable-gpios is configured.
> but IS_ERR(qcadev->bt_en) case happens, your change will do error
> return, so BT will not work at all
>
> but if you don't do error return, BT will working fine.
>
> so your fix is not right regarding QCA6390.

Actually I'd say he is probably right with respect to DT because that
seems to require GPIO, we probably need a clearer way to differentiate
if a device is being set up via DT or not (btattach), in any case DT
is probably preferable thus why I went ahead and applied this one.

> > Bart
> >
> >>> NAK again by me.
> >>>
> >>>>>> }
> >>>>>>
> >>>>>> + if (!qcadev->bt_en)
> >>>>>> + power_ctrl_enabled = false;
> >>>>>
> >>>>> This looks duplicated - you already have such check earlier.
> >>>>>
> >>>>
> >>>> It's under a different switch case!
> >>>>
> >>>> Bartosz
> >>>
> >>>
> >>
>


--
Luiz Augusto von Dentz

2024-04-24 15:45:23

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Wed, 24 Apr 2024 14:29:32 +0200 you wrote:
> From: Bartosz Golaszewski <[email protected]>
>
> Any return value from gpiod_get_optional() other than a pointer to a
> GPIO descriptor or a NULL-pointer is an error and the driver should
> abort probing. That being said: commit 56d074d26c58 ("Bluetooth: hci_qca:
> don't use IS_ERR_OR_NULL() with gpiod_get_optional()") no longer sets
> power_ctrl_enabled on NULL-pointer returned by
> devm_gpiod_get_optional(). Restore this behavior but bail-out on errors.
> While at it: also bail-out on error returned when trying to get the
> "swctrl" GPIO.
>
> [...]

Here is the summary with links:
- [v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()
https://git.kernel.org/bluetooth/bluetooth-next/c/48a9e64a533b

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



2024-04-24 15:58:08

by quic_zijuhu

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

On 4/24/2024 11:47 PM, quic_zijuhu wrote:
> On 4/24/2024 11:41 PM, Luiz Augusto von Dentz wrote:
>> Hi Quic_zijuhu,
>>
>> On Wed, Apr 24, 2024 at 11:35 AM quic_zijuhu <[email protected]> wrote:
>>>
>>> On 4/24/2024 11:31 PM, Bartosz Golaszewski wrote:
>>>> On Wed, Apr 24, 2024 at 5:30 PM quic_zijuhu <[email protected]> wrote:
>>>>>
>>>>> On 4/24/2024 11:24 PM, quic_zijuhu wrote:
>>>>>> On 4/24/2024 10:52 PM, Bartosz Golaszewski wrote:
>>>>>>> On Wed, 24 Apr 2024 at 16:46, Krzysztof Kozlowski
>>>>>>> <[email protected]> wrote:
>>>>>>>>
>>>>>>>> On 24/04/2024 14:29, Bartosz Golaszewski wrote:
>>>>>>>>> From: Bartosz Golaszewski <[email protected]>
>>>>>>>>>
>>>>>>>>
>>>>>>>>> qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
>>>>>>>>> if (IS_ERR(qcadev->susclk)) {
>>>>>>>>> @@ -2355,10 +2360,13 @@ static int qca_serdev_probe(struct serdev_device *serdev)
>>>>>>>>> qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable",
>>>>>>>>> GPIOD_OUT_LOW);
>>>>>>>>> if (IS_ERR(qcadev->bt_en)) {
>>>>>>>>> - dev_warn(&serdev->dev, "failed to acquire enable gpio\n");
>>>>>>>>> - power_ctrl_enabled = false;
>>>>>>>>> + dev_err(&serdev->dev, "failed to acquire enable gpio\n");
>>>>>>>>> + return PTR_ERR(qcadev->bt_en);
>>>>>> please think about for QCA2066. if it is returned from here. BT will
>>>>>> not working at all. if you don't return here. i will be working fine
>>>>>> for every BT functionality.
>>>>> sorry, correct a type error, it is QCA6390 not QCA2066.
>>>>
>>>> Doesn't matter. If enable-gpios is not there, gpiod_get_optional()
>>>> will return NULL and we will not return.
>>>>
>>> i think i need to explain more for my consider case.
>>> let me take QCA6390, if the property enable-gpios is configured.
>>> but IS_ERR(qcadev->bt_en) case happens, your change will do error
>>> return, so BT will not work at all
>>>
>>> but if you don't do error return, BT will working fine.
>>>
>>> so your fix is not right regarding QCA6390.
>>
>> Actually I'd say he is probably right with respect to DT because that
>> seems to require GPIO, we probably need a clearer way to differentiate
>> if a device is being set up via DT or not (btattach), in any case DT
>> is probably preferable thus why I went ahead and applied this one.
>>
> for QCA6390, i can confirm that enable-gpios is optional. it is bring-up
> by my team. i can confirm reporter's machine don't config the GPIO pin.
> DTS binding spec also don't mark it as required.
>
> that is why i change my changing from initial reverting the whole change
> to only focus on QCA6390 that is the machine reported the issue.
>
>
>>>> Bart
>>>>
>>>>>> NAK again by me.
>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> + if (!qcadev->bt_en)
>>>>>>>>> + power_ctrl_enabled = false;
>>>>>>>>
>>>>>>>> This looks duplicated - you already have such check earlier.
>>>>>>>>
>>>>>>>
>>>>>>> It's under a different switch case!
>>>>>>>
>>>>>>> Bartosz
>>>>>>
>>>>>>
>>>>>
>>>
>>
>>
>
>
i find the change have been merged.
i think it is not good manner to merge change in this way even if i give
reasonable doubt


2024-04-26 14:37:37

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

On Wed, 24 Apr 2024 17:40:27 +0200, [email protected] said:
> Hello:
>
> This patch was applied to bluetooth/bluetooth-next.git (master)
> by Luiz Augusto von Dentz <[email protected]>:
>
> On Wed, 24 Apr 2024 14:29:32 +0200 you wrote:
>> From: Bartosz Golaszewski <[email protected]>
>>
>> Any return value from gpiod_get_optional() other than a pointer to a
>> GPIO descriptor or a NULL-pointer is an error and the driver should
>> abort probing. That being said: commit 56d074d26c58 ("Bluetooth: hci_qca:
>> don't use IS_ERR_OR_NULL() with gpiod_get_optional()") no longer sets
>> power_ctrl_enabled on NULL-pointer returned by
>> devm_gpiod_get_optional(). Restore this behavior but bail-out on errors.
>> While at it: also bail-out on error returned when trying to get the
>> "swctrl" GPIO.
>>
>> [...]
>
> Here is the summary with links:
> - [v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()
> https://git.kernel.org/bluetooth/bluetooth-next/c/48a9e64a533b
>
> You are awesome, thank you!
> --
> Deet-doot-dot, I am a bot.
> https://korg.docs.kernel.org/patchwork/pwbot.html
>
>
>

Luiz,

I think patchwork borked when picking up this one, here's what the commit
trailer looks like in next:

Reported-by: Wren Turkal <[email protected]>
Reported-by: Zijun Hu <[email protected]>
Closes: https://lore.kernel.org/linux-bluetooth/[email protected]/
Fixes: 56d074d26c58 ("Bluetooth: hci_qca: don't use
IS_ERR_OR_NULL() with gpiod_get_optional()")
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Bartosz Golaszewski <[email protected]>
Tested-by: Wren Turkal" <[email protected]>
Reported-by: Wren Turkal <[email protected]>
Reported-by: Zijun Hu <[email protected]>
Reviewed-by: Krzysztof Kozlowski<[email protected]>
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Luiz Augusto von Dentz <[email protected]>

Reported-by and Reviewed-by tags are duplicated. One of the RB tags is missing
a space.

Bartosz

2024-04-26 17:30:33

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

On Fri, 26 Apr 2024 at 17:09, Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Hi Bartosz,
>
> On Fri, Apr 26, 2024 at 10:37 AM Bartosz Golaszewski <[email protected]> wrote:
> >
> > On Wed, 24 Apr 2024 17:40:27 +0200, [email protected] said:
> > > Hello:
> > >
> > > This patch was applied to bluetooth/bluetooth-next.git (master)
> > > by Luiz Augusto von Dentz <[email protected]>:
> > >
> > > On Wed, 24 Apr 2024 14:29:32 +0200 you wrote:
> > >> From: Bartosz Golaszewski <[email protected]>
> > >>
> > >> Any return value from gpiod_get_optional() other than a pointer to a
> > >> GPIO descriptor or a NULL-pointer is an error and the driver should
> > >> abort probing. That being said: commit 56d074d26c58 ("Bluetooth: hci_qca:
> > >> don't use IS_ERR_OR_NULL() with gpiod_get_optional()") no longer sets
> > >> power_ctrl_enabled on NULL-pointer returned by
> > >> devm_gpiod_get_optional(). Restore this behavior but bail-out on errors.
> > >> While at it: also bail-out on error returned when trying to get the
> > >> "swctrl" GPIO.
> > >>
> > >> [...]
> > >
> > > Here is the summary with links:
> > > - [v2] Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()
> > > https://git.kernel.org/bluetooth/bluetooth-next/c/48a9e64a533b
> > >
> > > You are awesome, thank you!
> > > --
> > > Deet-doot-dot, I am a bot.
> > > https://korg.docs.kernel.org/patchwork/pwbot.html
> > >
> > >
> > >
> >
> > Luiz,
> >
> > I think patchwork borked when picking up this one, here's what the commit
> > trailer looks like in next:
> >
> > Reported-by: Wren Turkal <[email protected]>
> > Reported-by: Zijun Hu <[email protected]>
> > Closes: https://lore.kernel.org/linux-bluetooth/[email protected]/
> > Fixes: 56d074d26c58 ("Bluetooth: hci_qca: don't use
> > IS_ERR_OR_NULL() with gpiod_get_optional()")
> > Reviewed-by: Krzysztof Kozlowski <[email protected]>
> > Signed-off-by: Bartosz Golaszewski <[email protected]>
> > Tested-by: Wren Turkal" <[email protected]>
> > Reported-by: Wren Turkal <[email protected]>
> > Reported-by: Zijun Hu <[email protected]>
> > Reviewed-by: Krzysztof Kozlowski<[email protected]>
> > Reviewed-by: Krzysztof Kozlowski <[email protected]>
> > Signed-off-by: Luiz Augusto von Dentz <[email protected]>
> >
> > Reported-by and Reviewed-by tags are duplicated. One of the RB tags is missing
> > a space.
>
> Oh crap, should probably not trust patchwork would pick up the tags
> properly, that said the pull-request was already merged, not sure if
> we can do something about it now?
>

Nope, if it's gone upstream then it's too late.

BTW As a fresh b4 convert I highly recommend it for managing patches. :)

Bart

> --
> Luiz Augusto von Dentz