mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Artur <arturfaleiros1254@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Max Chou <max.chou@realtek.com>,
	linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
	Artur <arturfaleiros1254@gmail.com>
Subject: [PATCH 2/2] Bluetooth: btrtl: Set an error code when skb allocation fails
Date: Sun, 15 Nov 2026 19:53:13 +0000	[thread overview]
Message-ID: <20261115195313.20809-3-arturfaleiros1254@gmail.com> (raw)
In-Reply-To: <20261115195313.20809-1-arturfaleiros1254@gmail.com>

When btrtl_initialize() asks the controller to drop its firmware and
bt_skb_alloc() fails, it jumps to its error path without setting 'ret'.
'ret' still holds 0 from the previous successful vendor command, so
btrtl_initialize() returns ERR_PTR(0), which is NULL.

Both callers, btrtl_setup_realtek() and h5_btrtl_setup(), only check
the result with IS_ERR() and then dereference the NULL pointer in
btrtl_download_firmware() and btrtl_get_uart_settings().

This path used to jump to a label that carried on with the setup.
Commit 9a24ce5e29b1 ("Bluetooth: btrtl: Firmware format v2 support")
turned it into a failure but did not set an error code.

Set 'ret' to -ENOMEM before jumping to the error path.

The problem was found with smatch, which keeps reporting the following
for this path once the RTL_SEC_PROJ read failure is fixed:

  drivers/bluetooth/btrtl.c:1252 btrtl_initialize() warn: passing zero to 'ERR_PTR'

The analysis, the fix and this description were prepared with the help
of an AI coding assistant (Claude Opus 5.5).

Fixes: 9a24ce5e29b1 ("Bluetooth: btrtl: Firmware format v2 support")
Cc: Max Chou <max.chou@realtek.com>
Signed-off-by: Artur <arturfaleiros1254@gmail.com>
---

Notes:
    Compile tested only (x86_64, W=1, sparse, smatch). The error path has
    not been exercised at runtime: no Realtek Bluetooth controller was
    available and no reproducer was written.

 drivers/bluetooth/btrtl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c
index d2c2e79800fc..35a2c9d3380c 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -1143,8 +1143,10 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
 
 	if (btrtl_dev->drop_fw) {
 		skb = bt_skb_alloc(sizeof(*cmd), GFP_KERNEL);
-		if (!skb)
+		if (!skb) {
+			ret = -ENOMEM;
 			goto err_free;
+		}
 
 		cmd = skb_put(skb, HCI_COMMAND_HDR_SIZE);
 		cmd->opcode = cpu_to_le16(0xfc66);
-- 
2.43.0


  parent reply	other threads:[~2026-11-15 19:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 19:53 [PATCH 0/2] Bluetooth: btrtl: Don't return NULL from btrtl_initialize() Artur
2026-11-15 19:53 ` [PATCH 1/2] Bluetooth: btrtl: Return an error when reading the key id fails Artur
2026-11-15 19:53 ` Artur [this message]
2026-11-19 18:50 ` [PATCH 0/2] Bluetooth: btrtl: Don't return NULL from btrtl_initialize() patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261115195313.20809-3-arturfaleiros1254@gmail.com \
    --to=arturfaleiros1254@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=max.chou@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®