2024-04-22 13:01:28

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH] 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.

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()")
Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/bluetooth/hci_qca.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 92fa20f5ac7d..739248c6d6b9 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -2327,9 +2327,12 @@ 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) &&
--
2.40.1



2024-04-22 13:34:09

by bluez.test.bot

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

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=846671

---Test result---

Test Summary:
CheckPatch FAIL 0.99 seconds
GitLint FAIL 0.48 seconds
SubjectPrefix PASS 2.50 seconds
BuildKernel PASS 30.21 seconds
CheckAllWarning PASS 32.96 seconds
CheckSparse PASS 38.14 seconds
CheckSmatch FAIL 36.37 seconds
BuildKernel32 PASS 29.14 seconds
TestRunnerSetup PASS 525.20 seconds
TestRunner_l2cap-tester PASS 22.51 seconds
TestRunner_iso-tester PASS 30.96 seconds
TestRunner_bnep-tester PASS 4.65 seconds
TestRunner_mgmt-tester FAIL 110.64 seconds
TestRunner_rfcomm-tester PASS 7.23 seconds
TestRunner_sco-tester PASS 14.91 seconds
TestRunner_ioctl-tester PASS 7.72 seconds
TestRunner_mesh-tester PASS 5.73 seconds
TestRunner_smp-tester PASS 6.74 seconds
TestRunner_userchan-tester PASS 4.84 seconds
IncrementalBuild PASS 28.08 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()
WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report
#107:
Reported-by: Wren Turkal <[email protected]>
Reported-by: Zijun Hu <[email protected]>

total: 0 errors, 1 warnings, 13 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13638518.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
14: B1 Line exceeds max length (106>80): "Closes: https://lore.kernel.org/linux-bluetooth/[email protected]/"
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:

Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: net/bluetooth/hci_core.o] Error 139
make[4]: *** Deleting file 'net/bluetooth/hci_core.o'
make[3]: *** [scripts/Makefile.build:485: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: net] Error 2
make[2]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bcm203x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bcm203x.o'
make[4]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bpa10x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bpa10x.o'
make[3]: *** [scripts/Makefile.build:485: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: drivers] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1919: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 492, Passed: 489 (99.4%), Failed: 1, Not Run: 2

Failed Test Cases
LL Privacy - Add Device 7 (AL is full) Failed 0.198 seconds


---
Regards,
Linux Bluetooth

2024-04-24 04:06:19

by Krzysztof Kozlowski

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

On 22/04/2024 15:00, Bartosz Golaszewski 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.
>
> 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()")
> Signed-off-by: Bartosz Golaszewski <[email protected]>

Reviewed-by: Krzysztof Kozlowski <[email protected]>

Best regards,
Krzysztof


2024-04-24 04:55:56

by quic_zijuhu

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

On 4/22/2024 9:00 PM, Bartosz Golaszewski 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.
>
> 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()")
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> drivers/bluetooth/hci_qca.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> index 92fa20f5ac7d..739248c6d6b9 100644
> --- a/drivers/bluetooth/hci_qca.c
> +++ b/drivers/bluetooth/hci_qca.c
> @@ -2327,9 +2327,12 @@ 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);
> }
>
For QCA6390, control logic do not reach here, so it has no any help for
QCA6390.
> + if (!qcadev->bt_en)
> + power_ctrl_enabled = false;
> +
property enable-gpios are obviously marked as required for WCN6750 and
WCN6855 by dts binding spec as shown by below link:
https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/Documentation/devicetree/bindings/net/bluetooth/qualcomm-bluetooth.yaml

if user don't config the property then "qcadev->bt_en is NULL", can we
still treat this case as good case?

that is why i changed my fix from reverting the wrong commit to only
focusing on QCA6390.

i will give different fix for other impacted QCA controllers.

> qcadev->sw_ctrl = devm_gpiod_get_optional(&serdev->dev, "swctrl",
> GPIOD_IN);
> if (IS_ERR(qcadev->sw_ctrl) &&

NAK as explained above.

2024-04-24 05:07:25

by Wren Turkal

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

On 4/22/24 6:00 AM, Bartosz Golaszewski 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.

Nack. This patch does fixes neither the disable/re-enable problem nor
the warm boot problem.

Zijun replied to this patch also with what I think is the proper
reasoning for why it doesn't fix my setup.

>
> 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()")
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> drivers/bluetooth/hci_qca.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> index 92fa20f5ac7d..739248c6d6b9 100644
> --- a/drivers/bluetooth/hci_qca.c
> +++ b/drivers/bluetooth/hci_qca.c
> @@ -2327,9 +2327,12 @@ 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) &&

--
You're more amazing than you think!

2024-04-24 09:04:23

by Bartosz Golaszewski

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

On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal <[email protected]> said:
> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
>
> Nack. This patch does fixes neither the disable/re-enable problem nor
> the warm boot problem.
>
> Zijun replied to this patch also with what I think is the proper
> reasoning for why it doesn't fix my setup.
>

Indeed, I only addressed a single issue here and not the code under the
default: label of the switch case. Sorry.

Could you give the following diff a try?

Bart

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");

2024-04-24 09:50:27

by Krzysztof Kozlowski

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

On 24/04/2024 11:32, quic_zijuhu wrote:
> On 4/24/2024 5:04 PM, Bartosz Golaszewski wrote:
>> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal <[email protected]> said:
>>> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
>>>
>>> Nack. This patch does fixes neither the disable/re-enable problem nor
>>> the warm boot problem.
>>>
>>> Zijun replied to this patch also with what I think is the proper
>>> reasoning for why it doesn't fix my setup.
>>>
>>
>> Indeed, I only addressed a single issue here and not the code under the
>> default: label of the switch case. Sorry.
>>
>> Could you give the following diff a try?
>>
>> Bart
>>
>> 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");
> i suggest stop here and request you code review for my changes, i found
> the issue and given fix for my concern.

What are you answering to? What the heck are you implying here?

I think this crosses some threshold of ridiculous mailings.

Please get your managers or colleagues to review your patches and
process you follow.

Best regards,
Krzysztof


2024-04-24 11:25:43

by Wren Turkal

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

On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<[email protected]> said:
>> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
>> Nack. This patch does fixes neither the disable/re-enable problem nor
>> the warm boot problem.
>>
>> Zijun replied to this patch also with what I think is the proper
>> reasoning for why it doesn't fix my setup.
>>
> Indeed, I only addressed a single issue here and not the code under the
> default: label of the switch case. Sorry.
>
> Could you give the following diff a try?

I am compiling a kernel the patch right now, but I did want to let you
know that the patch got corrupted by extra line wrapping. I'm not sure
how you're sending it, but I thought you might want to know.

wt
--
You're more amazing than you think!

2024-04-24 11:34:04

by Wren Turkal

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

On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<[email protected]> said:
>> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
>> Nack. This patch does fixes neither the disable/re-enable problem nor
>> the warm boot problem.
>>
>> Zijun replied to this patch also with what I think is the proper
>> reasoning for why it doesn't fix my setup.
>>
> Indeed, I only addressed a single issue here and not the code under the
> default: label of the switch case. Sorry.
>
> Could you give the following diff a try?

I had a feeling that was what was going on. I'll give the patch a shot.

wt
--
You're more amazing than you think!

2024-04-24 11:54:12

by Bartosz Golaszewski

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

On Wed, Apr 24, 2024 at 1:25 PM Wren Turkal <[email protected]> wrote:
>
> On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> > On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<[email protected]> said:
> >> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
> >> Nack. This patch does fixes neither the disable/re-enable problem nor
> >> the warm boot problem.
> >>
> >> Zijun replied to this patch also with what I think is the proper
> >> reasoning for why it doesn't fix my setup.
> >>
> > Indeed, I only addressed a single issue here and not the code under the
> > default: label of the switch case. Sorry.
> >
> > Could you give the following diff a try?
>
> I am compiling a kernel the patch right now, but I did want to let you
> know that the patch got corrupted by extra line wrapping. I'm not sure
> how you're sending it, but I thought you might want to know.
>

This must be your email client wrapping lines over a certain limit.
Try and get the diff from lore[1], it should be fine.

Bart

[1] https://lore.kernel.org/lkml/CAMRc=MepDwUbAKrWgm0CXKObqy8=igtug0QDgo-CgwxjZCAC2Q@mail.gmail.com/

2024-04-24 11:56:29

by Bartosz Golaszewski

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

On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <[email protected]> wrote:
>
> On 4/24/24 4:16 AM, Wren Turkal wrote:
> > On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> >> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<[email protected]>
> >> said:
> >>> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
> >>> Nack. This patch does fixes neither the disable/re-enable problem nor
> >>> the warm boot problem.
> >>>
> >>> Zijun replied to this patch also with what I think is the proper
> >>> reasoning for why it doesn't fix my setup.
> >>>
> >> Indeed, I only addressed a single issue here and not the code under the
> >> default: label of the switch case. Sorry.
> >>
> >> Could you give the following diff a try?
> >
> > I had a feeling that was what was going on. I'll give the patch a shot.
> >
> > wt
>
> Considering this patch is basically equivalent to patch 1/2 from Zijun,
> I am not surprised that is works similarly. I.e. on a cold boot, I can
> disable/re-enable bluetooth as many time as I want.
>

Zijun didn't bail out on errors which is the issue the original patch
tried to address and this one preserves.

> However, since this patch doesn't include the quirk fix from Zijun's
> patchset (patch 2/2), bluetooth fails to work after a warm boot.
>

That's OK, we have the first part right. Let's now see if we can reuse
patch 2/2 from Zijun.

> @Zijun, this patch looks more idiomatic when I look at the surrounding
> code than your patch 1/2. Notice how it doesn't use the "else if"
> construct. It does the NULL test separately after checking for errors.
>
> --
> You're more amazing than you think!

Bart

2024-04-24 11:59:49

by Wren Turkal

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

On 4/24/24 4:53 AM, Bartosz Golaszewski wrote:
> This must be your email client wrapping lines over a certain limit.
> Try and get the diff from lore[1], it should be fine.
>
> Bart
>
> [1]https://lore.kernel.org/lkml/CAMRc=MepDwUbAKrWgm0CXKObqy8=igtug0QDgo-CgwxjZCAC2Q@mail.gmail.com/

I don't think it's my client. The extra newlines are right there in the
lore link.

Look at the line that starts with "@@". That line is wrapped. The
following line ("serdev_device *serdev)") should be at the end of the
previous line. The same thing happened on the second "@@" line as well.

wt
--
You're more amazing than you think!

2024-04-24 12:09:15

by Wren Turkal

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

On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <[email protected]> wrote:
>>
>> On 4/24/24 4:16 AM, Wren Turkal wrote:
>>> On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
>>>> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<[email protected]>
>>>> said:
>>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
>>>>> Nack. This patch does fixes neither the disable/re-enable problem nor
>>>>> the warm boot problem.
>>>>>
>>>>> Zijun replied to this patch also with what I think is the proper
>>>>> reasoning for why it doesn't fix my setup.
>>>>>
>>>> Indeed, I only addressed a single issue here and not the code under the
>>>> default: label of the switch case. Sorry.
>>>>
>>>> Could you give the following diff a try?
>>>
>>> I had a feeling that was what was going on. I'll give the patch a shot.
>>>
>>> wt
>>
>> Considering this patch is basically equivalent to patch 1/2 from Zijun,
>> I am not surprised that is works similarly. I.e. on a cold boot, I can
>> disable/re-enable bluetooth as many time as I want.
>>
>
> Zijun didn't bail out on errors which is the issue the original patch
> tried to address and this one preserves.

Ah, I see that. Yeah, Zijun's 1/2 doesn't have the returns.

>> However, since this patch doesn't include the quirk fix from Zijun's
>> patchset (patch 2/2), bluetooth fails to work after a warm boot.
>>
>
> That's OK, we have the first part right. Let's now see if we can reuse
> patch 2/2 from Zijun.
>
>> @Zijun, this patch looks more idiomatic when I look at the surrounding
>> code than your patch 1/2. Notice how it doesn't use the "else if"
>> construct. It does the NULL test separately after checking for errors.
>>
>> --
>> You're more amazing than you think!
>
> Bart

--
You're more amazing than you think!

2024-04-24 12:18:47

by Wren Turkal

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

On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <[email protected]> wrote:
>>
>> On 4/24/24 4:16 AM, Wren Turkal wrote:
>>> On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
>>>> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<[email protected]>
>>>> said:
>>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
>>>>> Nack. This patch does fixes neither the disable/re-enable problem nor
>>>>> the warm boot problem.
>>>>>
>>>>> Zijun replied to this patch also with what I think is the proper
>>>>> reasoning for why it doesn't fix my setup.
>>>>>
>>>> Indeed, I only addressed a single issue here and not the code under the
>>>> default: label of the switch case. Sorry.
>>>>
>>>> Could you give the following diff a try?
>>>
>>> I had a feeling that was what was going on. I'll give the patch a shot.
>>>
>>> wt
>>
>> Considering this patch is basically equivalent to patch 1/2 from Zijun,
>> I am not surprised that is works similarly. I.e. on a cold boot, I can
>> disable/re-enable bluetooth as many time as I want.
>>
>
> Zijun didn't bail out on errors which is the issue the original patch
> tried to address and this one preserves.
>
>> However, since this patch doesn't include the quirk fix from Zijun's
>> patchset (patch 2/2), bluetooth fails to work after a warm boot.
>>
>
> That's OK, we have the first part right. Let's now see if we can reuse
> patch 2/2 from Zijun.

I'm compiling it right now. Be back soon.

>> @Zijun, this patch looks more idiomatic when I look at the surrounding
>> code than your patch 1/2. Notice how it doesn't use the "else if"
>> construct. It does the NULL test separately after checking for errors.
>>
>> --
>> You're more amazing than you think!
>
> Bart

--
You're more amazing than you think!

2024-04-24 12:20:56

by Bartosz Golaszewski

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

On Wed, 24 Apr 2024 at 14:17, Wren Turkal <[email protected]> wrote:
>
> On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
> > On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <[email protected]> wrote:
> >>
> >> On 4/24/24 4:16 AM, Wren Turkal wrote:
> >>> On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> >>>> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<[email protected]>
> >>>> said:
> >>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski 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.
> >>>>> Nack. This patch does fixes neither the disable/re-enable problem nor
> >>>>> the warm boot problem.
> >>>>>
> >>>>> Zijun replied to this patch also with what I think is the proper
> >>>>> reasoning for why it doesn't fix my setup.
> >>>>>
> >>>> Indeed, I only addressed a single issue here and not the code under the
> >>>> default: label of the switch case. Sorry.
> >>>>
> >>>> Could you give the following diff a try?
> >>>
> >>> I had a feeling that was what was going on. I'll give the patch a shot.
> >>>
> >>> wt
> >>
> >> Considering this patch is basically equivalent to patch 1/2 from Zijun,
> >> I am not surprised that is works similarly. I.e. on a cold boot, I can
> >> disable/re-enable bluetooth as many time as I want.
> >>
> >
> > Zijun didn't bail out on errors which is the issue the original patch
> > tried to address and this one preserves.
> >
> >> However, since this patch doesn't include the quirk fix from Zijun's
> >> patchset (patch 2/2), bluetooth fails to work after a warm boot.
> >>
> >
> > That's OK, we have the first part right. Let's now see if we can reuse
> > patch 2/2 from Zijun.
>
> I'm compiling it right now. Be back soon.
>

Well I doubt it's correct as it removed Krzysztof's fix which looks
right. If I were to guess I'd say we need some mix of both.

Bart

> >> @Zijun, this patch looks more idiomatic when I look at the surrounding
> >> code than your patch 1/2. Notice how it doesn't use the "else if"
> >> construct. It does the NULL test separately after checking for errors.
> >>
> >> --
> >> You're more amazing than you think!
> >
> > Bart
>
> --
> You're more amazing than you think!

2024-04-24 12:27:55

by Bartosz Golaszewski

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

On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <[email protected]> wrote:
> >>>
> >>> That's OK, we have the first part right. Let's now see if we can reuse
> >>> patch 2/2 from Zijun.
> >>
> >> I'm compiling it right now. Be back soon.
> >>
> >
> > Well I doubt it's correct as it removed Krzysztof's fix which looks
> > right. If I were to guess I'd say we need some mix of both.
>
> Patch 2/2 remove K's fix? I thought only 1/2 did that.
>
> To be specific, I have applied your patch and Zijun's 2/2 only.
>

No, patch 1/2 from Zijun reverted my changes. Patch 2/2 removes
Krzysztof's changes and replaces them with a different if else. This
patch is a better alternative to Zijun's patch 1/2. For 2/2, I'll let
Krzysztof handle it.

Bart

2024-04-24 12:30:22

by Wren Turkal

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

On 4/24/24 5:27 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <[email protected]> wrote:
>>>>>
>>>>> That's OK, we have the first part right. Let's now see if we can reuse
>>>>> patch 2/2 from Zijun.
>>>>
>>>> I'm compiling it right now. Be back soon.
>>>>
>>>
>>> Well I doubt it's correct as it removed Krzysztof's fix which looks
>>> right. If I were to guess I'd say we need some mix of both.
>>
>> Patch 2/2 remove K's fix? I thought only 1/2 did that.
>>
>> To be specific, I have applied your patch and Zijun's 2/2 only.
>>
>
> No, patch 1/2 from Zijun reverted my changes. Patch 2/2 removes
> Krzysztof's changes and replaces them with a different if else. This
> patch is a better alternative to Zijun's patch 1/2. For 2/2, I'll let
> Krzysztof handle it.

Got it. Thx.

BTW, should this patch's commit message include the following?

Tested-by: "Wren Turkal" <[email protected]>

If so, please feel free to add it.

wt
--
You're more amazing than you think!

2024-04-24 12:57:36

by Wren Turkal

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

On 4/24/24 5:27 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <[email protected]> wrote:
>>>>>
>>>>> That's OK, we have the first part right. Let's now see if we can reuse
>>>>> patch 2/2 from Zijun.
>>>>
>>>> I'm compiling it right now. Be back soon.
>>>>
>>>
>>> Well I doubt it's correct as it removed Krzysztof's fix which looks
>>> right. If I were to guess I'd say we need some mix of both.
>>
>> Patch 2/2 remove K's fix? I thought only 1/2 did that.
>>
>> To be specific, I have applied your patch and Zijun's 2/2 only.
>>
>
> No, patch 1/2 from Zijun reverted my changes. Patch 2/2 removes
> Krzysztof's changes and replaces them with a different if else. This
> patch is a better alternative to Zijun's patch 1/2. For 2/2, I'll let
> Krzysztof handle it.

Hey there. So, applying Zijun 2/2 on top of your patch does fix the warm
boot problem for me. I can't speak about whether it's the right fix.

@Krzysztof Is the correct just add the conditional return for the quirk
without reverting your earlier change?

wt
--
You're more amazing than you think!

2024-04-24 13:30:55

by quic_zijuhu

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

On 4/24/2024 9:26 PM, Wren Turkal wrote:
> On 4/24/24 6:12 AM, quic_zijuhu wrote:
>> On 4/24/2024 8:27 PM, Bartosz Golaszewski wrote:
>>> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <[email protected]> wrote:
>>>>>>>
>>>>>>> That's OK, we have the first part right. Let's now see if we can
>>>>>>> reuse
>>>>>>> patch 2/2 from Zijun.
>>>>>>
>>>>>> I'm compiling it right now. Be back soon.
>>>>>>
>>>>>
>>>>> Well I doubt it's correct as it removed Krzysztof's fix which looks
>>>>> right. If I were to guess I'd say we need some mix of both.
>>>>
>>>> Patch 2/2 remove K's fix? I thought only 1/2 did that.
>>>>
>>>> To be specific, I have applied your patch and Zijun's 2/2 only.
>>>>
>>>
>>> No, patch 1/2 from Zijun reverted my changes. Patch 2/2 removes
>>> Krzysztof's changes and replaces them with a different if else. This
>>> patch is a better alternative to Zijun's patch 1/2. For 2/2, I'll let
>>> Krzysztof handle it.
>>>
>> do you really realize what do you talk about?
>> do you really listen what do @Wren says?
>>
>> he says that my patch 2/2 is right based on several verification results.
>
> she, not he
>
>> BTW, my 2/2 fix don't have anything about DTS usage.
>
> I think the problem with your 2/2 patch is that it removes the
> conditional bailing if the device is shutdown or not open.
>
> Maybe this patch instead?
>
> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> index 2f7ae38d85eb..fcac44ae7898 100644
> --- a/drivers/bluetooth/hci_qca.c
> +++ b/drivers/bluetooth/hci_qca.c
> @@ -2456,6 +2456,10 @@ static void qca_serdev_shutdown(struct device *dev)
>                     !test_bit(HCI_RUNNING, &hdev->flags))
>                         return;
>
> +               if (test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP,
> &hdev->quirks) ||
> +                   hci_dev_test_flag(hdev, HCI_SETUP))
> +                       return;
> +
>                 serdev_device_write_flush(serdev);
>                 ret = serdev_device_write_buf(serdev, ibs_wake_cmd,
>                                               sizeof(ibs_wake_cmd));
>
>> he maybe be a DTS expert but not BT from his present fix history for
>> bluetooth system.
>
>
Hi Wren,
i think i don't need to care about why wrong condition cause wrong results.

2024-04-24 13:54:06

by Bartosz Golaszewski

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

On Wed, 24 Apr 2024 at 15:26, Wren Turkal <[email protected]> wrote:
>
> On 4/24/24 6:12 AM, quic_zijuhu wrote:
> > On 4/24/2024 8:27 PM, Bartosz Golaszewski wrote:
> >> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <[email protected]> wrote:
> >>>>>>
> >>>>>> That's OK, we have the first part right. Let's now see if we can reuse
> >>>>>> patch 2/2 from Zijun.
> >>>>>
> >>>>> I'm compiling it right now. Be back soon.
> >>>>>
> >>>>
> >>>> Well I doubt it's correct as it removed Krzysztof's fix which looks
> >>>> right. If I were to guess I'd say we need some mix of both.
> >>>
> >>> Patch 2/2 remove K's fix? I thought only 1/2 did that.
> >>>
> >>> To be specific, I have applied your patch and Zijun's 2/2 only.
> >>>
> >>
> >> No, patch 1/2 from Zijun reverted my changes. Patch 2/2 removes
> >> Krzysztof's changes and replaces them with a different if else. This
> >> patch is a better alternative to Zijun's patch 1/2. For 2/2, I'll let
> >> Krzysztof handle it.
> >>
> > do you really realize what do you talk about?
> > do you really listen what do @Wren says?
> >
> > he says that my patch 2/2 is right based on several verification results.
>
> she, not he
>
> > BTW, my 2/2 fix don't have anything about DTS usage.
>
> I think the problem with your 2/2 patch is that it removes the
> conditional bailing if the device is shutdown or not open.
>
> Maybe this patch instead?
>
> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
> index 2f7ae38d85eb..fcac44ae7898 100644
> --- a/drivers/bluetooth/hci_qca.c
> +++ b/drivers/bluetooth/hci_qca.c
> @@ -2456,6 +2456,10 @@ static void qca_serdev_shutdown(struct device *dev)
> !test_bit(HCI_RUNNING, &hdev->flags))
> return;
>
> + if (test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP,
> &hdev->quirks) ||
> + hci_dev_test_flag(hdev, HCI_SETUP))
> + return;
> +
> serdev_device_write_flush(serdev);
> ret = serdev_device_write_buf(serdev, ibs_wake_cmd,
> sizeof(ibs_wake_cmd));
>
> > he maybe be a DTS expert but not BT from his present fix history for
> > bluetooth system.
>
>

Did you test it? Does it work? If so, please consider sending it
upstream for review.

You can keep Zijun's authorship but add your own SoB tag at the end
and mention what you did. Something like this:

[Wren: kept Krzysztof's fix]
Signed-off-by: Wren...

Bartosz

2024-04-24 23:35:59

by quic_zijuhu

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

On 4/25/2024 6:17 AM, Wren Turkal wrote:
> On 4/24/24 6:53 AM, Bartosz Golaszewski wrote:
>> On Wed, 24 Apr 2024 at 15:26, Wren Turkal <[email protected]> wrote:
>>>
>>> On 4/24/24 6:12 AM, quic_zijuhu wrote:
>>>> On 4/24/2024 8:27 PM, Bartosz Golaszewski wrote:
>>>>> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <[email protected]>
>>>>> wrote:
>>>>>>>>>
>>>>>>>>> That's OK, we have the first part right. Let's now see if we
>>>>>>>>> can reuse
>>>>>>>>> patch 2/2 from Zijun.
>>>>>>>>
>>>>>>>> I'm compiling it right now. Be back soon.
>>>>>>>>
>>>>>>>
>>>>>>> Well I doubt it's correct as it removed Krzysztof's fix which looks
>>>>>>> right. If I were to guess I'd say we need some mix of both.
>>>>>>
>>>>>> Patch 2/2 remove K's fix? I thought only 1/2 did that.
>>>>>>
>>>>>> To be specific, I have applied your patch and Zijun's 2/2 only.
>>>>>>
>>>>>
>>>>> No, patch 1/2 from Zijun reverted my changes. Patch 2/2 removes
>>>>> Krzysztof's changes and replaces them with a different if else. This
>>>>> patch is a better alternative to Zijun's patch 1/2. For 2/2, I'll let
>>>>> Krzysztof handle it.
>>>>>
>>>> do you really realize what do you talk about?
>>>> do you really listen what do @Wren says?
>>>>
>>>> he says that my patch 2/2 is right based on several verification
>>>> results.
>>>
>>> she, not he
>>>
>>>> BTW, my 2/2 fix don't have anything about DTS usage.
>>>
>>> I think the problem with your 2/2 patch is that it removes the
>>> conditional bailing if the device is shutdown or not open.
>>>
>>> Maybe this patch instead?
>>>
>>> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
>>> index 2f7ae38d85eb..fcac44ae7898 100644
>>> --- a/drivers/bluetooth/hci_qca.c
>>> +++ b/drivers/bluetooth/hci_qca.c
>>> @@ -2456,6 +2456,10 @@ static void qca_serdev_shutdown(struct device
>>> *dev)
>>>                       !test_bit(HCI_RUNNING, &hdev->flags))
>>>                           return;
>>>
>>> +               if (test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP,
>>> &hdev->quirks) ||
>>> +                   hci_dev_test_flag(hdev, HCI_SETUP))
>>> +                       return;
>>> +
>>>                   serdev_device_write_flush(serdev);
>>>                   ret = serdev_device_write_buf(serdev, ibs_wake_cmd,
>>>                                                 sizeof(ibs_wake_cmd));
>>>
>>>> he maybe be a DTS expert but not BT from his present fix history for
>>>> bluetooth system.
>>>
>>>
>>
>> Did you test it? Does it work? If so, please consider sending it
>> upstream for review.
>>
>> You can keep Zijun's authorship but add your own SoB tag at the end
>> and mention what you did. Something like this:
>>

[V7 2/2] as shown by below link is the formal fix.
https://patchwork.kernel.org/project/bluetooth/patch/[email protected]/

this fix logic was introduced from the very beginning when i saw your
issue description as shown by below link
https://lore.kernel.org/all/[email protected]/#t

>> [Wren: kept Krzysztof's fix]
>> Signed-off-by: Wren...
>>
>> Bartosz
>
> @Bartosz, I have tested this, and it works functionally for my setup. I
> cannot detect a difference between this and Zijun's logic when I compile
> a kernel with this patch.
>
> @Zijun, I think you have objections to this patch. I would like to make
> sure I hear your concern. Can you please take through it like I'm a 5
> year old who barely knows C? In retrospect, I guess that I would be a
> pretty precocious 5 year old. LOL.
>
> In all seriousness, @Zijun, I really appreciate the work you did on
> this. I would like to understand why you assert that removing the logic
> of Krzysztof is appropriate. Again, I am not a kernel developer, so this
> stuff is really outside my wheelhouse. Having said that, by my reading,
> which may very well be worng, it seems like you are just adding another
> case that is orthogonal to K's conditions. I'd like to truly understand
> you position to know if the patch I am suggesting is somehow harmful.
> This is an earnest question. I really want to respect your expertise
> here, and I really want you to know how much I appreciate your work.
> you maybe see all replies of [2/2] patch for this issue within below
link. i believe you will understand it. the bottom of the link includes
all reply history.
https://lore.kernel.org/all/[email protected]/
> wt


2024-04-25 02:35:27

by Wren Turkal

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

On 4/24/24 4:35 PM, quic_zijuhu wrote:
> On 4/25/2024 6:17 AM, Wren Turkal wrote:
>> On 4/24/24 6:53 AM, Bartosz Golaszewski wrote:
>>> On Wed, 24 Apr 2024 at 15:26, Wren Turkal <[email protected]> wrote:
>>>>
>>>> On 4/24/24 6:12 AM, quic_zijuhu wrote:
>>>>> On 4/24/2024 8:27 PM, Bartosz Golaszewski wrote:
>>>>>> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <[email protected]>
>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> That's OK, we have the first part right. Let's now see if we
>>>>>>>>>> can reuse
>>>>>>>>>> patch 2/2 from Zijun.
>>>>>>>>>
>>>>>>>>> I'm compiling it right now. Be back soon.
>>>>>>>>>
>>>>>>>>
>>>>>>>> Well I doubt it's correct as it removed Krzysztof's fix which looks
>>>>>>>> right. If I were to guess I'd say we need some mix of both.
>>>>>>>
>>>>>>> Patch 2/2 remove K's fix? I thought only 1/2 did that.
>>>>>>>
>>>>>>> To be specific, I have applied your patch and Zijun's 2/2 only.
>>>>>>>
>>>>>>
>>>>>> No, patch 1/2 from Zijun reverted my changes. Patch 2/2 removes
>>>>>> Krzysztof's changes and replaces them with a different if else. This
>>>>>> patch is a better alternative to Zijun's patch 1/2. For 2/2, I'll let
>>>>>> Krzysztof handle it.
>>>>>>
>>>>> do you really realize what do you talk about?
>>>>> do you really listen what do @Wren says?
>>>>>
>>>>> he says that my patch 2/2 is right based on several verification
>>>>> results.
>>>>
>>>> she, not he
>>>>
>>>>> BTW, my 2/2 fix don't have anything about DTS usage.
>>>>
>>>> I think the problem with your 2/2 patch is that it removes the
>>>> conditional bailing if the device is shutdown or not open.
>>>>
>>>> Maybe this patch instead?
>>>>
>>>> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
>>>> index 2f7ae38d85eb..fcac44ae7898 100644
>>>> --- a/drivers/bluetooth/hci_qca.c
>>>> +++ b/drivers/bluetooth/hci_qca.c
>>>> @@ -2456,6 +2456,10 @@ static void qca_serdev_shutdown(struct device
>>>> *dev)
>>>>                       !test_bit(HCI_RUNNING, &hdev->flags))
>>>>                           return;
>>>>
>>>> +               if (test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP,
>>>> &hdev->quirks) ||
>>>> +                   hci_dev_test_flag(hdev, HCI_SETUP))
>>>> +                       return;
>>>> +
>>>>                   serdev_device_write_flush(serdev);
>>>>                   ret = serdev_device_write_buf(serdev, ibs_wake_cmd,
>>>>                                                 sizeof(ibs_wake_cmd));
>>>>
>>>>> he maybe be a DTS expert but not BT from his present fix history for
>>>>> bluetooth system.
>>>>
>>>>
>>>
>>> Did you test it? Does it work? If so, please consider sending it
>>> upstream for review.
>>>
>>> You can keep Zijun's authorship but add your own SoB tag at the end
>>> and mention what you did. Something like this:
>>>
>
> [V7 2/2] as shown by below link is the formal fix.
> https://patchwork.kernel.org/project/bluetooth/patch/[email protected]/
>
> this fix logic was introduced from the very beginning when i saw your
> issue description as shown by below link
> https://lore.kernel.org/all/[email protected]/#t

This is not quite fully correct. You did introduce that logic. However,
you also removed the other conditional. That is what K.K. was objecting
to. I literally copied your logic without deleting K.K.'s logic. My
specific question is does that make my change incorrect in some way.

>>> [Wren: kept Krzysztof's fix]
>>> Signed-off-by: Wren...
>>>
>>> Bartosz
>>
>> @Bartosz, I have tested this, and it works functionally for my setup. I
>> cannot detect a difference between this and Zijun's logic when I compile
>> a kernel with this patch.
>>
>> @Zijun, I think you have objections to this patch. I would like to make
>> sure I hear your concern. Can you please take through it like I'm a 5
>> year old who barely knows C? In retrospect, I guess that I would be a
>> pretty precocious 5 year old. LOL.
>>
>> In all seriousness, @Zijun, I really appreciate the work you did on
>> this. I would like to understand why you assert that removing the logic
>> of Krzysztof is appropriate. Again, I am not a kernel developer, so this
>> stuff is really outside my wheelhouse. Having said that, by my reading,
>> which may very well be worng, it seems like you are just adding another
>> case that is orthogonal to K's conditions. I'd like to truly understand
>> you position to know if the patch I am suggesting is somehow harmful.
>> This is an earnest question. I really want to respect your expertise
>> here, and I really want you to know how much I appreciate your work.
>> you maybe see all replies of [2/2] patch for this issue within below
> link. i believe you will understand it. the bottom of the link includes
> all reply history.
> https://lore.kernel.org/all/[email protected]/
I read through the discussion again.

Can you please define VSC? I'm not sure what that means.

With regard to your change's logic.

First a kernel dev newbie question, does "hci_dev_test_flag(hdev,
HCI_SETUP)" test whether the hardware has ever been setup? The rest of
my discussions assumes that is the case.

So, basically, the logic in your change is something like this:

if dev_must_be_setup_every_time_opened || dev_is_in_setup_state
bail out on shutdown logic

If I am getting this correctly, you're saying that any device that must
be setup is already by definition not needing setup and should not have
shutdown logic run on it.

Okay, so question: Is it possible for a device to need setup (both not
have the quirk and "hci_dev_test_flag(hdev, HCI_SETUP)" to have BT off
or not be running?

Assuming the answer to that question is, "It is not possible." How do we
know that? I think that may be what K.K. is saying is not obvious.

If the code ever gets into that state, shouldn't we at least log that
the state is not an expected state?

I am now worried that allowing an unexpected state through could result
in a unintended logic executing. How do I know I don't need to worry
about that?

wt
--
You're more amazing than you think!