[PATCH 2/2] Bluetooth: btrtl: Set an error code when skb allocation fails

From: Artur

Date: Sun Nov 15 2026 - 14:54:23 EST


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@xxxxxxxxxxx>
Signed-off-by: Artur <arturfaleiros1254@xxxxxxxxx>
---

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