diff mbox series

Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional()

Message ID 20240422130036.31856-1-brgl@bgdev.pl (mailing list archive)
State Superseded
Headers show
Series Bluetooth: qca: set power_ctrl_enabled on NULL returned by gpiod_get_optional() | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch warning WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report #107: Reported-by: Wren Turkal <wt@penguintechs.org> Reported-by: Zijun Hu <quic_zijuhu@quicinc.com> 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.
tedd_an/GitLint fail 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/1713449192-25926-2-git-send-email-quic_zijuhu@quicinc.com/"
tedd_an/SubjectPrefix success Gitlint PASS
tedd_an/BuildKernel success BuildKernel PASS
tedd_an/CheckAllWarning success CheckAllWarning PASS
tedd_an/CheckSparse success CheckSparse PASS
tedd_an/CheckSmatch fail CheckSparse: FAIL: 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
tedd_an/BuildKernel32 success BuildKernel32 PASS
tedd_an/TestRunnerSetup success TestRunnerSetup PASS
tedd_an/TestRunner_l2cap-tester success TestRunner PASS
tedd_an/TestRunner_iso-tester success TestRunner PASS
tedd_an/TestRunner_bnep-tester success TestRunner PASS
tedd_an/TestRunner_mgmt-tester fail TestRunner_mgmt-tester: Total: 492, Passed: 489 (99.4%), Failed: 1, Not Run: 2
tedd_an/TestRunner_rfcomm-tester success TestRunner PASS
tedd_an/TestRunner_sco-tester success TestRunner PASS
tedd_an/TestRunner_ioctl-tester success TestRunner PASS
tedd_an/TestRunner_mesh-tester success TestRunner PASS
tedd_an/TestRunner_smp-tester success TestRunner PASS
tedd_an/TestRunner_userchan-tester success TestRunner PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Bartosz Golaszewski April 22, 2024, 1 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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 <wt@penguintechs.org>
Reported-by: Zijun Hu <quic_zijuhu@quicinc.com>
Closes: https://lore.kernel.org/linux-bluetooth/1713449192-25926-2-git-send-email-quic_zijuhu@quicinc.com/
Fixes: 56d074d26c58 ("Bluetooth: hci_qca: don't use IS_ERR_OR_NULL() with gpiod_get_optional()")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/bluetooth/hci_qca.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

bluez.test.bot@gmail.com April 22, 2024, 1:33 p.m. UTC | #1
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 <wt@penguintechs.org>
Reported-by: Zijun Hu <quic_zijuhu@quicinc.com>

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/1713449192-25926-2-git-send-email-quic_zijuhu@quicinc.com/"
##############################
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
Krzysztof Kozlowski April 24, 2024, 4:05 a.m. UTC | #2
On 22/04/2024 15:00, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> 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 <wt@penguintechs.org>
> Reported-by: Zijun Hu <quic_zijuhu@quicinc.com>
> Closes: https://lore.kernel.org/linux-bluetooth/1713449192-25926-2-git-send-email-quic_zijuhu@quicinc.com/
> Fixes: 56d074d26c58 ("Bluetooth: hci_qca: don't use IS_ERR_OR_NULL() with gpiod_get_optional()")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof
Zijun Hu April 24, 2024, 4:55 a.m. UTC | #3
On 4/22/2024 9:00 PM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> 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 <wt@penguintechs.org>
> Reported-by: Zijun Hu <quic_zijuhu@quicinc.com>
> Closes: https://lore.kernel.org/linux-bluetooth/1713449192-25926-2-git-send-email-quic_zijuhu@quicinc.com/
> Fixes: 56d074d26c58 ("Bluetooth: hci_qca: don't use IS_ERR_OR_NULL() with gpiod_get_optional()")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
>  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.
Wren Turkal April 24, 2024, 5:07 a.m. UTC | #4
On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> 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 <wt@penguintechs.org>
> Reported-by: Zijun Hu <quic_zijuhu@quicinc.com>
> Closes: https://lore.kernel.org/linux-bluetooth/1713449192-25926-2-git-send-email-quic_zijuhu@quicinc.com/
> Fixes: 56d074d26c58 ("Bluetooth: hci_qca: don't use IS_ERR_OR_NULL() with gpiod_get_optional()")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
>   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) &&
Bartosz Golaszewski April 24, 2024, 9:04 a.m. UTC | #5
On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal <wt@penguintechs.org> said:
> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>>
>> 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");
Zijun Hu April 24, 2024, 9:32 a.m. UTC | #6
On 4/24/2024 5:04 PM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal <wt@penguintechs.org> said:
>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>>>
>>> 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.
Krzysztof Kozlowski April 24, 2024, 9:50 a.m. UTC | #7
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 <wt@penguintechs.org> said:
>>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>>> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>>>>
>>>> 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
Wren Turkal April 24, 2024, 11:16 a.m. UTC | #8
On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<wt@penguintechs.org>  said:
>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
>>>
>>> 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
Wren Turkal April 24, 2024, 11:25 a.m. UTC | #9
On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<wt@penguintechs.org>  said:
>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
>>>
>>> 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
Wren Turkal April 24, 2024, 11:53 a.m. UTC | #10
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<wt@penguintechs.org>  
>> said:
>>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
>>>>
>>>> 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.

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.

@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.
Bartosz Golaszewski April 24, 2024, 11:53 a.m. UTC | #11
On Wed, Apr 24, 2024 at 1:25 PM Wren Turkal <wt@penguintechs.org> wrote:
>
> On 4/24/24 2:04 AM, Bartosz Golaszewski wrote:
> > On Wed, 24 Apr 2024 07:07:05 +0200, Wren Turkal<wt@penguintechs.org>  said:
> >> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
> >>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
> >>>
> >>> 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/
Bartosz Golaszewski April 24, 2024, 11:56 a.m. UTC | #12
On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <wt@penguintechs.org> 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<wt@penguintechs.org>
> >> said:
> >>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
> >>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
> >>>>
> >>>> 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
Wren Turkal April 24, 2024, 11:59 a.m. UTC | #13
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
Bartosz Golaszewski April 24, 2024, 12:01 p.m. UTC | #14
On Wed, 24 Apr 2024 at 13:59, Wren Turkal <wt@penguintechs.org> wrote:
>
> 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.
>

Indeed. I just noticed that it applies fine with git apply and figured
the output must be right. Anyway, this is not a proper patch, I will
send one once I adapt Zijun's code.

Bart
Wren Turkal April 24, 2024, 12:05 p.m. UTC | #15
On 4/24/24 5:01 AM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 at 13:59, Wren Turkal <wt@penguintechs.org> wrote:
>>
>> 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.
>>
> 
> Indeed. I just noticed that it applies fine with git apply and figured
> the output must be right. Anyway, this is not a proper patch, I will
> send one once I adapt Zijun's code.
> 
> Bart

Weird. Git apply failed for me. That's how I noticed it.

 From my terminal:
➜  linux git:(my_master) ✗ git apply ../blah.diff
error: corrupt patch at line 6


FWIW, I also tried pasting it into stdin by running `git apply` as well.

wt
Wren Turkal April 24, 2024, 12:09 p.m. UTC | #16
On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <wt@penguintechs.org> 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<wt@penguintechs.org>
>>>> said:
>>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>>>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
>>>>>>
>>>>>> 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
Wren Turkal April 24, 2024, 12:17 p.m. UTC | #17
On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <wt@penguintechs.org> 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<wt@penguintechs.org>
>>>> said:
>>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>>>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
>>>>>>
>>>>>> 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
Bartosz Golaszewski April 24, 2024, 12:20 p.m. UTC | #18
On Wed, 24 Apr 2024 at 14:17, Wren Turkal <wt@penguintechs.org> wrote:
>
> On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
> > On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <wt@penguintechs.org> 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<wt@penguintechs.org>
> >>>> said:
> >>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
> >>>>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
> >>>>>>
> >>>>>> 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!
Bartosz Golaszewski April 24, 2024, 12:23 p.m. UTC | #19
On Wed, Apr 24, 2024 at 2:20 PM Bartosz Golaszewski
<bartosz.golaszewski@linaro.org> wrote:
>
> On Wed, 24 Apr 2024 at 14:17, Wren Turkal <wt@penguintechs.org> wrote:
> >
> > On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
> > > On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <wt@penguintechs.org> 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<wt@penguintechs.org>
> > >>>> said:
> > >>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
> > >>>>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
> > >>>>>>
> > >>>>>> 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
>

Anyway, these are two separate issues. Let me send a v2 of this one to
address at least one of them. I think Krzysztof will be better at
fixing the other one as it's his patch that caused the second
regression.

Bart
Wren Turkal April 24, 2024, 12:24 p.m. UTC | #20
On 4/24/24 5:20 AM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 at 14:17, Wren Turkal <wt@penguintechs.org> wrote:
>>
>> On 4/24/24 4:56 AM, Bartosz Golaszewski wrote:
>>> On Wed, Apr 24, 2024 at 1:53 PM Wren Turkal <wt@penguintechs.org> 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<wt@penguintechs.org>
>>>>>> said:
>>>>>>> On 4/22/24 6:00 AM, Bartosz Golaszewski wrote:
>>>>>>>> From: Bartosz Golaszewski<bartosz.golaszewski@linaro.org>
>>>>>>>>
>>>>>>>> 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.

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.

> 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!
Bartosz Golaszewski April 24, 2024, 12:27 p.m. UTC | #21
On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <wt@penguintechs.org> 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
Wren Turkal April 24, 2024, 12:30 p.m. UTC | #22
On 4/24/24 5:27 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <wt@penguintechs.org> 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" <wt@penguintechs.org>

If so, please feel free to add it.

wt
Wren Turkal April 24, 2024, 12:57 p.m. UTC | #23
On 4/24/24 5:27 AM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <wt@penguintechs.org> 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
Bartosz Golaszewski April 24, 2024, 12:57 p.m. UTC | #24
On Wed, 24 Apr 2024 at 14:30, Wren Turkal <wt@penguintechs.org> wrote:
>
> On 4/24/24 5:27 AM, Bartosz Golaszewski wrote:
> > On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <wt@penguintechs.org> 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" <wt@penguintechs.org>
>

Please respond with this tag under the v2 patch and b4, patchwork or
whatever other tools the maintainer will use will pick it up.

Thanks,
Bartosz

> If so, please feel free to add it.
>
> wt
> --
> You're more amazing than you think!
Zijun Hu April 24, 2024, 1:12 p.m. UTC | #25
On 4/24/2024 8:27 PM, Bartosz Golaszewski wrote:
> On Wed, Apr 24, 2024 at 2:24 PM Wren Turkal <wt@penguintechs.org> 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.

BTW, my 2/2 fix don't have anything about DTS usage.

he maybe be a DTS expert but not BT from his present fix history for
bluetooth system.

> Bart
Wren Turkal April 24, 2024, 1:26 p.m. UTC | #26
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 <wt@penguintechs.org> 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.
Zijun Hu April 24, 2024, 1:30 p.m. UTC | #27
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 <wt@penguintechs.org> 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.
Bartosz Golaszewski April 24, 2024, 1:53 p.m. UTC | #28
On Wed, 24 Apr 2024 at 15:26, Wren Turkal <wt@penguintechs.org> 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 <wt@penguintechs.org> 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
Wren Turkal April 24, 2024, 10:09 p.m. UTC | #29
On 4/24/24 6:30 AM, quic_zijuhu wrote:
> 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 <wt@penguintechs.org> 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.

I can't speak the intellectual purity of this patch. However, I can say 
that the patch works for my hardware. I am able to disable/enable on 
cold boot and on warm boot.

@Zijun, Functionally, it seems incorporate your new logic without 
reverting Krzysztof's. Are you saying this is incorrect logic?

wt
Wren Turkal April 24, 2024, 10:17 p.m. UTC | #30
On 4/24/24 6:53 AM, Bartosz Golaszewski wrote:
> On Wed, 24 Apr 2024 at 15:26, Wren Turkal <wt@penguintechs.org> 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 <wt@penguintechs.org> 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

@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.

wt
Zijun Hu April 24, 2024, 11:35 p.m. UTC | #31
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 <wt@penguintechs.org> 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 <wt@penguintechs.org>
>>>>> 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/1713932807-19619-3-git-send-email-quic_zijuhu@quicinc.com/

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/1713095825-4954-3-git-send-email-quic_zijuhu@quicinc.com/#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/fe1a0e3b-3408-4a33-90e9-d4ffcfc7a99b@quicinc.com/
> wt
Wren Turkal April 25, 2024, 2:34 a.m. UTC | #32
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 <wt@penguintechs.org> 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 <wt@penguintechs.org>
>>>>>> 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/1713932807-19619-3-git-send-email-quic_zijuhu@quicinc.com/
> 
> 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/1713095825-4954-3-git-send-email-quic_zijuhu@quicinc.com/#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/fe1a0e3b-3408-4a33-90e9-d4ffcfc7a99b@quicinc.com/
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
diff mbox series

Patch

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) &&