Bluetooth: btbcm: fix missing of_node_put() in btbcm_get_board_name()

BugLink: https://bugs.launchpad.net/bugs/2101915

[ Upstream commit e42eec0f182ac0605e658145f6fe3b6a7c256c45 ]

of_find_node_by_path() returns a pointer to a device_node with its
refcount incremented, and a call to of_node_put() is required to
decrement the refcount again and avoid leaking the resource.

If 'of_property_read_string_index(root, "compatible", 0, &tmp)' fails,
the function returns without calling of_node_put(root) before doing so.

The automatic cleanup attribute can be used by means of the __free()
macro to automatically call of_node_put() when the variable goes out of
scope, fixing the issue and also accounting for new error paths.

Fixes: 63fac3343b ("Bluetooth: btbcm: Support per-board firmware variants")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[koichiroden: adjusted context due to missing commit:
e49f18b92bd1 ("Bluetooth: btbcm: Use strreplace()")]
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
This commit is contained in:
Javier Carrasco
2025-03-11 08:51:19 +09:00
committed by Stefan Bader
parent 631c7ade41
commit 7031dfacbc
+1 -3
View File
@@ -540,13 +540,12 @@ static const struct bcm_subver_table bcm_usb_subver_table[] = {
static const char *btbcm_get_board_name(struct device *dev)
{
#ifdef CONFIG_OF
struct device_node *root;
struct device_node *root __free(device_node) = of_find_node_by_path("/");
char *board_type;
const char *tmp;
int len;
int i;
root = of_find_node_by_path("/");
if (!root)
return NULL;
@@ -561,7 +560,6 @@ static const char *btbcm_get_board_name(struct device *dev)
if (board_type[i] == '/')
board_type[i] = '-';
}
of_node_put(root);
return board_type;
#else