Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4094841rdb; Mon, 11 Dec 2023 08:40:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPzKeJFVCG48HaJgRCNjQNuRB1kRF5a7Q6/BN1jl5/JYazmqZa6ga6skJVfl3U22bK+6QQ X-Received: by 2002:a05:600c:3b99:b0:40c:2324:2547 with SMTP id n25-20020a05600c3b9900b0040c23242547mr1984667wms.57.1702312846719; Mon, 11 Dec 2023 08:40:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702312846; cv=none; d=google.com; s=arc-20160816; b=KXgbe8v3DZL86IyKwvxrHILpmKG+/7I9v4hKAbGQk9r0tnrXuwkMPd5QDI6PTef0KX fWtKqsAUZapJvc92S03m1W2qoel9jNEKWX8WP/O4MSIpjxXx89Rb12QOGB+TtC4/tNZa C8haB8pGiJ/8kdwuxSBl1Tg4PNfoT87hSfWiGGEIl5Wd3xYAgZn5Sb0ovb+8/lc9/Ko8 cWC5hefecNsW3PdR7nGIwpwJDJsxrPYphFmKDVLLrfPNgaNXQ73PxBANqlgqZ5c1lh0M R4a1fCSXRpjA5Be/8m/TtgjvV9our2qP9BzC6Ot0cdSY0IZdBCCvaUth2xdbegRo5hHx idSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=JdtTeP+dBPUwDqZdcb5dhwf9gjqDmpM4ybahT/T0DD0=; fh=yIHEFU8ytSQpIDvntTWm+3VCpHh7n/aI42c6UGC22Ss=; b=szVfrlXSUqth6eAXpRWbA2yUMojaKp8dD3YVYDQ4FBI2MdLmjhXCFTuTM467eeSOKc GST4FMuLoySc9N3m3UvfaiSbzuqDB8MvJidpou5Pp+vPC8FaU/qg2KMXEGE8ogvFbM77 vizZC3H0U/nnBsOxHC+JynO0TARNXXT4/eIFDKH4lcynFKHfsx9tukPaqpB4mUH63+Hk QxanrKF2J+9yJd+8/oroY5Z9Bd6KEmqEIQ4AWeXRwrzOFv3NuCjVwh+Ef9lDyLUL6iPS Aw4dLXiO3pdtTix9U56b6Ry8ozcGedTsZ3eoCcn+OyCAatZduaiqwhI3b2GdHzYUEEUR 9f1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth+bounces-521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-521-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gz6-20020a170906f2c600b00a1ce98016c2si3805691ejb.532.2023.12.11.08.40.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:40:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth+bounces-521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-521-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 770971F2188D for ; Mon, 11 Dec 2023 16:40:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FF9D48CCF; Mon, 11 Dec 2023 16:40:35 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail11.truemail.it (mail11.truemail.it [217.194.8.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A432CB4; Mon, 11 Dec 2023 08:40:27 -0800 (PST) Received: from francesco-nb.pivistrello.it (93-49-2-63.ip317.fastwebnet.it [93.49.2.63]) by mail11.truemail.it (Postfix) with ESMTPA id A4E18208A9; Mon, 11 Dec 2023 17:40:25 +0100 (CET) From: Francesco Dolcini To: Amitkumar Karwar , Neeraj Kale , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Francesco Dolcini , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH v2 1/3] Bluetooth: btnxpuart: fix recv_buf() return value Date: Mon, 11 Dec 2023 17:40:18 +0100 Message-Id: <20231211164020.173253-2-francesco@dolcini.it> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231211164020.173253-1-francesco@dolcini.it> References: <20231211164020.173253-1-francesco@dolcini.it> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Francesco Dolcini 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/ZWEIhcUXfutb5SY6@francesco-nb.int.toradex.com/ Fixes: 689ca16e5232 ("Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets") Signed-off-by: Francesco Dolcini --- 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