[PATCH net-next] Bluetooth: btrtl: Fix passing zero to 'ERR_PTR'

Yue Haibing posted 1 patch 3 months, 1 week ago
drivers/bluetooth/btrtl.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH net-next] Bluetooth: btrtl: Fix passing zero to 'ERR_PTR'
Posted by Yue Haibing 3 months, 1 week ago
If bt_skb_alloc() fails, ret should be -ENOMEM then pass to ERR_PTR().

Fixes: 1996d9cad6ad ("Bluetooth: btrtl: Ask 8821C to drop old firmware")
Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
---
 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 7838c89e529e..6d5b37990be6 100644
--- a/drivers/bluetooth/btrtl.c
+++ b/drivers/bluetooth/btrtl.c
@@ -1137,8 +1137,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.34.1
Re: [PATCH net-next] Bluetooth: btrtl: Fix passing zero to 'ERR_PTR'
Posted by Markus Elfring 2 months, 3 weeks ago
> If bt_skb_alloc() fails, ret should be -ENOMEM then pass to ERR_PTR().

You would like to achieve a more appropriate error code for another case.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16-rc6#n94


…
> +++ b/drivers/bluetooth/btrtl.c
> @@ -1137,8 +1137,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);
…

Will it be a bit nicer to perform the desired variable assignment
after an additional label like “err_no_mem”?

Regards,
Markus