[PATCH 1/8] memory: atmel-ebi: Use non-devm allocations for of_update_property()

Lee Jones lee at kernel.org
Wed Dec 2 01:33:48 PST 2026


atmel_ebi_dev_disable() allocates the struct property and its name and
value strings using devm_kzalloc() and devm_kstrdup(), then installs the
property into the live device tree via of_update_property().  Because
device tree properties outlive the platform device, a subsequent probe
failure or device unbind frees those devm-managed allocations while the
property remains linked in np->properties, causing a use-after-free on
later device tree accesses.

Switch atmel_ebi_dev_disable() to kzalloc_obj() and kstrdup() with
proper kfree() unwinding on error, and drop the now-unused ebi
parameter.

Fixes: 6a4ec4cd0888 ("memory: add Atmel EBI (External Bus Interface) driver")
Closes: https://sashiko.dev/#/bug/linux-2e85dceb-25c0-4065-b486-f6bdc0a88ca6
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---
 drivers/memory/atmel-ebi.c | 40 +++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/memory/atmel-ebi.c b/drivers/memory/atmel-ebi.c
index 33d7007d9d0c..89a5b5e8a334 100644
--- a/drivers/memory/atmel-ebi.c
+++ b/drivers/memory/atmel-ebi.c
@@ -18,6 +18,7 @@
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/regmap.h>
+#include <linux/slab.h>
 #include <soc/at91/atmel-sfr.h>
 
 #define AT91_EBI_NUM_CS		8
@@ -493,26 +494,43 @@ static const struct of_device_id atmel_ebi_id_table[] = {
 	{ /* sentinel */ }
 };
 
-static int atmel_ebi_dev_disable(struct atmel_ebi *ebi, struct device_node *np)
+static int atmel_ebi_dev_disable(struct device_node *np)
 {
-	struct device *dev = ebi->dev;
 	struct property *newprop;
+	int ret;
 
-	newprop = devm_kzalloc(dev, sizeof(*newprop), GFP_KERNEL);
+	newprop = kzalloc_obj(*newprop);
 	if (!newprop)
 		return -ENOMEM;
 
-	newprop->name = devm_kstrdup(dev, "status", GFP_KERNEL);
-	if (!newprop->name)
-		return -ENOMEM;
+	newprop->name = kstrdup("status", GFP_KERNEL);
+	if (!newprop->name) {
+		ret = -ENOMEM;
+		goto err_free_prop;
+	}
 
-	newprop->value = devm_kstrdup(dev, "disabled", GFP_KERNEL);
-	if (!newprop->value)
-		return -ENOMEM;
+	newprop->value = kstrdup("disabled", GFP_KERNEL);
+	if (!newprop->value) {
+		ret = -ENOMEM;
+		goto err_free_name;
+	}
 
 	newprop->length = sizeof("disabled");
 
-	return of_update_property(np, newprop);
+	ret = of_update_property(np, newprop);
+	if (ret)
+		goto err_free_value;
+
+	return 0;
+
+err_free_value:
+	kfree(newprop->value);
+err_free_name:
+	kfree(newprop->name);
+err_free_prop:
+	kfree(newprop);
+
+	return ret;
 }
 
 static int atmel_ebi_probe(struct platform_device *pdev)
@@ -603,7 +621,7 @@ static int atmel_ebi_probe(struct platform_device *pdev)
 			dev_err(dev, "failed to configure EBI bus for %pOF, disabling the device",
 				child);
 
-			ret = atmel_ebi_dev_disable(ebi, child);
+			ret = atmel_ebi_dev_disable(child);
 			if (ret)
 				goto err_disable_clk;
 		}
-- 
2.56.1.911.g883d8bcb20-goog




More information about the linux-arm-kernel mailing list