[PATCH] Bluetooth: btbcm: Handle memory allocation failure in btbcm_get_board_name()

Aleksandr Mishin posted 1 patch 2 months, 1 week ago
There is a newer version of this series
drivers/bluetooth/btbcm.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] Bluetooth: btbcm: Handle memory allocation failure in btbcm_get_board_name()
Posted by Aleksandr Mishin 2 months, 1 week ago
In btbcm_get_board_name() devm_kstrdup() can return NULL due to memory
allocation failure.

Add NULL return check to prevent NULL dereference.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 63fac3343b99 ("Bluetooth: btbcm: Support per-board firmware variants")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
 drivers/bluetooth/btbcm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c
index f9a7c790d7e2..84273b7f02e1 100644
--- a/drivers/bluetooth/btbcm.c
+++ b/drivers/bluetooth/btbcm.c
@@ -554,6 +554,8 @@ static const char *btbcm_get_board_name(struct device *dev)
 
 	/* get rid of any '/' in the compatible string */
 	board_type = devm_kstrdup(dev, tmp, GFP_KERNEL);
+	if (!board_type)
+		return NULL;
 	strreplace(board_type, '/', '-');
 	of_node_put(root);
 
-- 
2.30.2