lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Mon,  5 Sep 2022 15:30:23 +0000
From:   Wei Yongjun <weiyongjun@...weicloud.com>
To:     Pavel Machek <pavel@....cz>, Lee Jones <lee.jones@...aro.org>,
        Ulf Hansson <ulf.hansson@...aro.org>,
        Christian Mauderer <oss@...auderer.de>
Cc:     Wei Yongjun <weiyongjun1@...wei.com>, linux-leds@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH] leds: spi-byte: fix unbalanced of_node_get()/of_node_put()

From: Wei Yongjun <weiyongjun1@...wei.com>

Enabling CONFIG_OF_DYNAMIC triggers the following error at device remove:

OF: ERROR: memory leak, expected refcount 1 instead of 2, \
 of_node_get()/of_node_put() unbalanced - destroy cset entry: \
 attach overlay node /spi/led-controller@...ed

of_get_next_available_child() is used to get child node with refcount
incremented in spi_byte_probe(), but missing of_node_put() on it when
done. This patch fix it.

Signed-off-by: Wei Yongjun <weiyongjun1@...wei.com>
---
 drivers/leds/leds-spi-byte.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c
index 9d23dc9e7639..eaad227b4542 100644
--- a/drivers/leds/leds-spi-byte.c
+++ b/drivers/leds/leds-spi-byte.c
@@ -91,12 +91,12 @@ static int spi_byte_probe(struct spi_device *spi)
 		dev_err(dev, "Device must have exactly one LED sub-node.");
 		return -EINVAL;
 	}
-	child = of_get_next_available_child(dev_of_node(dev), NULL);
 
 	led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
 	if (!led)
 		return -ENOMEM;
 
+	child = of_get_next_available_child(dev_of_node(dev), NULL);
 	of_property_read_string(child, "label", &name);
 	strlcpy(led->name, name, sizeof(led->name));
 	led->spi = spi;
@@ -113,10 +113,12 @@ static int spi_byte_probe(struct spi_device *spi)
 			led->ldev.brightness = led->ldev.max_brightness;
 		} else if (strcmp(state, "off")) {
 			/* all other cases except "off" */
+			of_node_put(child);
 			dev_err(dev, "default-state can only be 'on' or 'off'");
 			return -EINVAL;
 		}
 	}
+	of_node_put(child);
 	spi_byte_brightness_set_blocking(&led->ldev,
 					 led->ldev.brightness);
 
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ