Bluetooth: btrtl: Prevent potential NULL dereference
authorDan Carpenter <dan.carpenter@linaro.org>
Wed, 2 Apr 2025 11:01:41 +0000 (14:01 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:40 +0000 (10:45 +0200)
[ Upstream commit 324dddea321078a6eeb535c2bff5257be74c9799 ]

The btrtl_initialize() function checks that rtl_load_file() either
had an error or it loaded a zero length file.  However, if it loaded
a zero length file then the error code is not set correctly.  It
results in an error pointer vs NULL bug, followed by a NULL pointer
dereference.  This was detected by Smatch:

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

Fixes: 26503ad25de8 ("Bluetooth: btrtl: split the device initialization into smaller parts")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/bluetooth/btrtl.c

index 1e7c1f9db9e4b9830e97cfe2147647d444091412..7f67e460f7f491acaa0a5b9b6c8d1260e32d3afb 100644 (file)
@@ -1194,6 +1194,8 @@ next:
                        rtl_dev_err(hdev, "mandatory config file %s not found",
                                    btrtl_dev->ic_info->cfg_name);
                        ret = btrtl_dev->cfg_len;
+                       if (!ret)
+                               ret = -EINVAL;
                        goto err_free;
                }
        }