2023-12-11 16:40:40

by Francesco Dolcini

[permalink] [raw]
Subject: [PATCH v2 0/3] Bluetooth: fix recv_buf() return value

From: Francesco Dolcini <[email protected]>

Serdev recv_buf() callback is supposed to return the amount of bytes consumed, therefore an int in between 0 and count.

Do not return negative number in case of issue, just print an error and return count. This fixes a WARN in ttyport_receive_buf().

In addition to that a small cleanup patch is added on btnxpuart to remove a useless assignment.

v2:
- improved commit messages

Francesco Dolcini (3):
Bluetooth: btnxpuart: fix recv_buf() return value
Bluetooth: btmtkuart: fix recv_buf() return value
Bluetooth: btnxpuart: remove useless assignment

drivers/bluetooth/btmtkuart.c | 11 +++--------
drivers/bluetooth/btnxpuart.c | 8 +++-----
2 files changed, 6 insertions(+), 13 deletions(-)

--
2.25.1



2023-12-11 16:40:44

by Francesco Dolcini

[permalink] [raw]
Subject: [PATCH v2 2/3] Bluetooth: btmtkuart: fix recv_buf() return value

From: Francesco Dolcini <[email protected]>

Serdev recv_buf() callback is supposed to return the amount of bytes
consumed, therefore an int in between 0 and count.

Do not return negative number in case of issue, just print an error and
return count. This fixes a WARN in ttyport_receive_buf().

Link: https://lore.kernel.org/all/[email protected]/
Fixes: 7237c4c9ec92 ("Bluetooth: mediatek: Add protocol support for MediaTek serial devices")
Signed-off-by: Francesco Dolcini <[email protected]>
---
drivers/bluetooth/btmtkuart.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
index 935feab815d9..203a000a84e3 100644
--- a/drivers/bluetooth/btmtkuart.c
+++ b/drivers/bluetooth/btmtkuart.c
@@ -336,7 +336,7 @@ mtk_stp_split(struct btmtkuart_dev *bdev, const unsigned char *data, int count,
return data;
}

-static int btmtkuart_recv(struct hci_dev *hdev, const u8 *data, size_t count)
+static void btmtkuart_recv(struct hci_dev *hdev, const u8 *data, size_t count)
{
struct btmtkuart_dev *bdev = hci_get_drvdata(hdev);
const unsigned char *p_left = data, *p_h4;
@@ -375,25 +375,20 @@ static int btmtkuart_recv(struct hci_dev *hdev, const u8 *data, size_t count)
bt_dev_err(bdev->hdev,
"Frame reassembly failed (%d)", err);
bdev->rx_skb = NULL;
- return err;
+ return;
}

sz_left -= sz_h4;
p_left += sz_h4;
}
-
- return 0;
}

static int btmtkuart_receive_buf(struct serdev_device *serdev, const u8 *data,
size_t count)
{
struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev);
- int err;

- err = btmtkuart_recv(bdev->hdev, data, count);
- if (err < 0)
- return err;
+ btmtkuart_recv(bdev->hdev, data, count);

bdev->hdev->stat.byte_rx += count;

--
2.25.1


2023-12-11 16:40:46

by Francesco Dolcini

[permalink] [raw]
Subject: [PATCH v2 1/3] Bluetooth: btnxpuart: fix recv_buf() return value

From: Francesco Dolcini <[email protected]>

Serdev recv_buf() callback is supposed to return the amount of bytes
consumed, therefore an int in between 0 and count.

Do not return a negative number in case of issue, just print an error
and return count. Before this change, in case of error, the returned
negative number was internally converted to 0 in ttyport_receive_buf,
now when the receive buffer is corrupted we return the size of the whole
received data (`count`). This should allow for better recovery in case
receiver/transmitter get out of sync if some data is lost.

This fixes a WARN in ttyport_receive_buf().

Bluetooth: hci0: Frame reassembly failed (-84)
------------[ cut here ]------------
serial serial0: receive_buf returns -84 (count = 6)
WARNING: CPU: 0 PID: 37 at drivers/tty/serdev/serdev-ttyport.c:37 ttyport_receive_buf+0xd8/0xf8
Modules linked in: mwifiex_sdio(+) ...
CPU: 0 PID: 37 Comm: kworker/u4:2 Not tainted 6.7.0-rc2-00147-gf1a09972a45a #1
Hardware name: Toradex Verdin AM62 WB on Verdin Development Board (DT)
Workqueue: events_unbound flush_to_ldisc
pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : ttyport_receive_buf+0xd8/0xf8
lr : ttyport_receive_buf+0xd8/0xf8
...
Call trace:
ttyport_receive_buf+0xd8/0xf8
flush_to_ldisc+0xbc/0x1a4
process_scheduled_works+0x16c/0x28c

Closes: https://lore.kernel.org/all/[email protected]/
Fixes: 689ca16e5232 ("Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets")
Signed-off-by: Francesco Dolcini <[email protected]>
---
v2:
- improve commit message
---
drivers/bluetooth/btnxpuart.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c
index b7e66b7ac570..951fe3014a3f 100644
--- a/drivers/bluetooth/btnxpuart.c
+++ b/drivers/bluetooth/btnxpuart.c
@@ -1276,11 +1276,10 @@ static int btnxpuart_receive_buf(struct serdev_device *serdev, const u8 *data,
if (IS_ERR(nxpdev->rx_skb)) {
int err = PTR_ERR(nxpdev->rx_skb);
/* Safe to ignore out-of-sync bootloader signatures */
- if (is_fw_downloading(nxpdev))
- return count;
- bt_dev_err(nxpdev->hdev, "Frame reassembly failed (%d)", err);
+ if (!is_fw_downloading(nxpdev))
+ bt_dev_err(nxpdev->hdev, "Frame reassembly failed (%d)", err);
nxpdev->rx_skb = NULL;
- return err;
+ return count;
}
if (!is_fw_downloading(nxpdev))
nxpdev->hdev->stat.byte_rx += count;
--
2.25.1


2023-12-11 17:32:41

by bluez.test.bot

[permalink] [raw]
Subject: RE: Bluetooth: fix recv_buf() return value

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=808866

---Test result---

Test Summary:
CheckPatch PASS 1.80 seconds
GitLint FAIL 1.16 seconds
SubjectPrefix PASS 0.37 seconds
BuildKernel PASS 27.16 seconds
CheckAllWarning PASS 30.20 seconds
CheckSparse PASS 35.43 seconds
CheckSmatch PASS 97.81 seconds
BuildKernel32 PASS 28.38 seconds
TestRunnerSetup PASS 418.27 seconds
TestRunner_l2cap-tester PASS 22.95 seconds
TestRunner_iso-tester PASS 48.12 seconds
TestRunner_bnep-tester PASS 6.96 seconds
TestRunner_mgmt-tester PASS 164.48 seconds
TestRunner_rfcomm-tester PASS 10.81 seconds
TestRunner_sco-tester PASS 14.49 seconds
TestRunner_ioctl-tester PASS 11.96 seconds
TestRunner_mesh-tester PASS 8.85 seconds
TestRunner_smp-tester PASS 9.78 seconds
TestRunner_userchan-tester PASS 7.24 seconds
IncrementalBuild PASS 34.43 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[v2,1/3] Bluetooth: btnxpuart: fix recv_buf() return value

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
20: B1 Line exceeds max length (97>80): " WARNING: CPU: 0 PID: 37 at drivers/tty/serdev/serdev-ttyport.c:37 ttyport_receive_buf+0xd8/0xf8"
34: B1 Line exceeds max length (82>80): "Closes: https://lore.kernel.org/all/[email protected]/"
[v2,2/3] Bluetooth: btmtkuart: fix recv_buf() return value

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
11: B1 Line exceeds max length (82>80): "Link: https://lore.kernel.org/all/[email protected]/"


---
Regards,
Linux Bluetooth

2023-12-12 16:20:39

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] Bluetooth: fix recv_buf() return value

Hello:

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

On Mon, 11 Dec 2023 17:40:17 +0100 you wrote:
> From: Francesco Dolcini <[email protected]>
>
> Serdev recv_buf() callback is supposed to return the amount of bytes consumed, therefore an int in between 0 and count.
>
> Do not return negative number in case of issue, just print an error and return count. This fixes a WARN in ttyport_receive_buf().
>
> In addition to that a small cleanup patch is added on btnxpuart to remove a useless assignment.
>
> [...]

Here is the summary with links:
- [v2,1/3] Bluetooth: btnxpuart: fix recv_buf() return value
https://git.kernel.org/bluetooth/bluetooth-next/c/7954bbcdd7ea
- [v2,2/3] Bluetooth: btmtkuart: fix recv_buf() return value
https://git.kernel.org/bluetooth/bluetooth-next/c/687d2de93b11
- [v2,3/3] Bluetooth: btnxpuart: remove useless assignment
https://git.kernel.org/bluetooth/bluetooth-next/c/99f188d71731

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