sparc: add missing put_device()
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 sparc: add missing put_device()
The of_find_device_by_node() takes a reference to the underlying device structure, we should release that reference.
Detected by coccinelle with the following ERRORS:
./arch/sparc/kernel/of_device_common.c:23:1-7: ERROR: missing put_device; call of_find_device_by_node on line 18, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:36:1-7: ERROR: missing put_device; call of_find_device_by_node on line 30, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:50:1-7: ERROR: missing put_device; call of_find_device_by_node on line 42, but without a corresponding object release within this function.
--- arch/sparc/kernel/of_device_common.c | 3 +++ 1 file changed, 3 insertions(+)
arch/sparc/kernel/of_device_common.c +3 -0
@@ -20,6 +20,7 @@ unsigned int irq_of_parse_and_map(struct device_node *node, int index)if (!op || index >= op->archdata.num_irqs)return 0 ; +put_device (op->dev);return op->archdata.irqs[index]; }EXPORT_SYMBOL (irq_of_parse_and_map);
@@ -32,6 +33,7 @@ int of_address_to_resource(struct device_node *node, int index,if (!op || index >= op->num_resources)return -EINVAL ; +put_device (op->dev);memcpy (r, &op->archdata.resource[index],sizeof (*r));return 0 ; }
@@ -45,6 +47,7 @@ void __iomem *of_iomap(struct device_node *node, int index)if (!op || index >= op->num_resources)return NULL ; +put_device (op->dev); r = &op->archdata.resource[index];return of_ioremap (r,0 ,resource_size (r), (char *) r->name);
Quoted 24 lines · On 18/07/2023 10:19, [email protected] wrote:
The
of_find_device_by_node()takes a reference to the underlying device structure, we should release that reference.Detected by coccinelle with the following ERRORS:
./arch/sparc/kernel/of_device_common.c:23:1-7: ERROR: missingput_device; callof_find_device_by_nodeon line 18, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:36:1-7: ERROR: missingput_device; callof_find_device_by_nodeon line 30, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:50:1-7: ERROR: missingput_device; callof_find_device_by_nodeon line 42, but without a corresponding object release within this function.Signed-off-by Ran Sun <[email protected]>--- arch/sparc/kernel/of_device_common.c | 3 +++ 1 file changed, 3 insertions(+)arch/sparc/kernel/of_device_common.c +0
-0
arch/sparc/kernel/of_device_common.c unsigned int irq_of_parse_and_map(struct device_node · line 25
Quoted 6 lines
arch/sparc/kernel/of_device_common.c +1
-0@@ -20,6 +20,7 @@ unsigned int irq_of_parse_and_map(struct device_node *node, int index) if (!op || index >= op->archdata.num_irqs) return 0; + put_device(op->dev); return op->archdata.irqs[index];
Device can be gone and freed after the put_device() call. So at least put_device() should come after the op->archdata access.
Same applies to all the cases below.
Quoted 20 lines
arch/sparc/kernel/of_device_common.c +0
-0}EXPORT_SYMBOL(irq_of_parse_and_map);
arch/sparc/kernel/of_device_common.c +1
-0@@ -32,6 +33,7 @@ int of_address_to_resource(struct device_node *node, int index, if (!op || index >= op->num_resources) return -EINVAL; + put_device(op->dev); memcpy(r, &op->archdata.resource[index], sizeof(*r)); return 0;}
arch/sparc/kernel/of_device_common.c +1
-0@@ -45,6 +47,7 @@ void __iomem *of_iomap(struct device_node *node, int index) if (!op || index >= op->num_resources) return NULL; + put_device(op->dev); r = &op->archdata.resource[index];return
of_ioremap(r, 0, resource_size(r), (char *) r->name);
Signature · 2 lines
With best wishes Dmitry