dm: core: misc fixes
cover dm: core: misc fixes
A few misc fixes to dm core. More information could be found in each commit. Patch list:
dm: core: free old name in device_set_name to prevent leak
dm: core: Correct calloc arguments
dm: core: fix wrong strlen check in of_add_subnode
dm: core: free fdt when fdt_create_empty_tree failure
---
Peng Fan (4):
dm: core: free fdt when fdt_create_empty_tree failure
dm: core: fix wrong strlen check in of_add_subnode
dm: core: Correct calloc arguments
dm: core: free old name in device_set_name to prevent leak
drivers/core/device.c | 2 ++ drivers/core/of_access.c | 2 +- drivers/core/ofnode.c | 4 +++- drivers/core/tag.c | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-)
---
base-commit: e800cc67f5b6cb50a20f37c993ec1cd4063bdbd3
change-id: 20260702-dm-core-e88b660f625e
Best regards,
Signature · 1 line
Peng Fan <[email protected]>
PATCH 1/4 dm: core: free fdt when fdt_create_empty_tree failure
From: Peng Fan <[email protected]>
If fdt_create_empty_tree fails, the malloc-ed fdt buffer is never freed. Add free before the error return.
--- drivers/core/ofnode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/core/ofnode.c +3 -1
@@ -130,8 +130,10 @@ int oftree_new(oftree *treep)if (!fdt)return log_msg_ret ("fla" , -ENOMEM ); ret =fdt_create_empty_tree (fdt, size); -if (ret) +if (ret) { +free (fdt);return log_msg_ret ("fla" , -EINVAL ); + } oftree_list[oftree_count++] = fdt; tree.fdt = fdt; }
Signature · 1 line
2.51.0
Re: [PATCH 1/4] dm: core: free fdt when fdt_create_empty_tree failure
Quoted 7 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
If
fdt_create_empty_treefails, the malloc-ed fdt buffer is never freed. Add free before the error return.Signed-off-by Peng Fan <[email protected]>---
Hi,
Best regards,
Raphaël
Re: [PATCH 1/4] dm: core: free fdt when fdt_create_empty_tree failure
In reply to Peng Fan (OSS)Quoted 10 lines · Peng Fan
dm: core: free fdt when
fdt_create_empty_treefailureIf
fdt_create_empty_treefails, the malloc-ed fdt buffer is never freed. Add free before the error return.Signed-off-by Peng Fan <[email protected]>Reviewed-by Raphaël Gallais-Pou <[email protected]>
drivers/core/ofnode.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)
PATCH 2/4 dm: core: fix wrong strlen check in of_add_subnode
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
The duplicate-name check uses strlen on the search name instead of the child name, so a child named "trevor" would falsely match a search for "trev". Fix by checking strlen of child->name.
--- drivers/core/of_access.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/core/of_access.c +1 -1
@@ -1071,7 +1071,7 @@ int of_add_subnode(struct device_node *parent, const char *name, int len,* make sure we don't use a child called "trevor" when we are * searching for "trev". */ -if (!strncmp (child->name, name, len) &&strlen (name) == len) { +if (!strncmp (child->name, name, len) &&strlen (child->name) == len) { *childp = child;return -EEXIST ; }
Signature · 1 line
2.51.0
Re: [PATCH 2/4] dm: core: fix wrong strlen check in of_add_subnode
Quoted 4 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>The duplicate-name check uses strlen on the search name instead of the child name, so a child named "trevor" would falsely match a search for "trev". Fix by checking strlen of
child->name.Signed-off-by Peng Fan <[email protected]>---
Hi,
Best regards,
Raphaël
Re: [PATCH 2/4] dm: core: fix wrong strlen check in of_add_subnode
In reply to Peng Fan (OSS)Quoted 11 lines · Peng Fan
dm: core: fix wrong strlen check in
of_add_subnodeThe duplicate-name check uses strlen on the search name instead of the child name, so a child named 'trevor' would falsely match a search for 'trev'. Fix by checking strlen of
child->name.Signed-off-by Peng Fan <[email protected]>Reviewed-by Raphaël Gallais-Pou <[email protected]>
drivers/core/of_access.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 3/4 dm: core: Correct calloc arguments
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Every other calloc in drivers/core uses calloc(count, size) with count first. Fix the two reversed calloc(sizeof, 1) calls for consistency.
--- drivers/core/tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/core/tag.c +2 -2
@@ -46,7 +46,7 @@ int dev_tag_set_ptr(struct udevice *dev, enum dm_tag_t tag, void *ptr)return -EEXIST ; } - node =calloc (sizeof (*node),1 ); + node =calloc (1 ,sizeof (*node));if (!node)return -ENOMEM ;
@@ -70,7 +70,7 @@ int dev_tag_set_val(struct udevice *dev, enum dm_tag_t tag, ulong val)return -EEXIST ; } - node =calloc (sizeof (*node),1 ); + node =calloc (1 ,sizeof (*node));if (!node)return -ENOMEM ;
Signature · 1 line
2.51.0
Re: [PATCH 3/4] dm: core: Correct calloc arguments
Quoted 3 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>Every other calloc in
drivers/coreusescalloc(count, size)with count first. Fix the two reversedcalloc(sizeof, 1)calls for consistency. Signed-off-by: Peng Fan <[email protected]>---
Hi,
Best regards,
Raphaël
Re: [PATCH 3/4] dm: core: Correct calloc arguments
In reply to Peng Fan (OSS)Quoted 10 lines · Peng Fan
dm: core: Correct calloc arguments
Every other calloc in
drivers/coreusescalloc(count, size)with count first. Fix the two reversedcalloc(sizeof, 1)calls for consistency.Signed-off-by Peng Fan <[email protected]>Reviewed-by Raphaël Gallais-Pou <[email protected]>
drivers/core/tag.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)
PATCH 4/4 dm: core: free old name in device_set_name to prevent leak
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
If device_set_name is called on a device that already has DM_FLAG_NAME_ALLOCED set, the old dynamically-allocated name is leaked. Free it before assigning the new name.
See: drivers/net/mdio_gpio.c:mdio_gpio_bind(). There is device_set_name() here, however dm_mdio_post_bind() will also call device_set_name() if "device-name" exists.
--- drivers/core/device.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/core/device.c +2 -0
@@ -1147,6 +1147,8 @@ int device_set_name(struct udevice *dev, const char *name) name =strdup (name);if (!name)return -ENOMEM ; +if (dev_get_flags (dev) &DM_FLAG_NAME_ALLOCED ) +free ((char *)dev->name); dev->name = name;device_set_name_alloced (dev);
Signature · 1 line
2.51.0
Re: [PATCH 4/4] dm: core: free old name in device_set_name to prevent leak
Quoted 6 lines · Peng Fan
dm: core: free old name in
device_set_nameto prevent leakIf
device_set_nameis called on a device that already hasDM_FLAG_NAME_ALLOCEDset, the old dynamically-allocated name is leaked. Free it before assigning the new name.
Quoted 8 lines
See: drivers/net/mdio_gpio.c:mdio_gpio_bind(). There is
device_set_name()here, howeverdm_mdio_post_bind()will also calldevice_set_name()if 'device-name' exists.Signed-off-by Peng Fan <[email protected]>
drivers/core/device.c| 2 ++1 file changed, 2 insertions(+)
Quoted 8 lines · Peng Fan (OSS)
A few misc fixes to dm core. More information could be found in each commit. Patch list:
dm: core: free old name indevice_set_nameto prevent leak
dm: core: Correct calloc arguments
dm: core: fix wrong strlen check inof_add_subnode
dm: core: free fdt whenfdt_create_empty_treefailure[...]
Applied to u-boot/main, thanks!
[1/4] dm: core: free fdt when fdt_create_empty_tree failure
commit: e871bb2463fbd6c06b6d771d9201c6d6f4abf947
[2/4] dm: core: fix wrong strlen check in of_add_subnode
commit: 65e1e66a3a38e21128582bec3b93c35548e60687
[3/4] dm: core: Correct calloc arguments
commit: 0af2ed57a3e9c34775602ea70d5c9829c4e830c6
[4/4] dm: core: free old name in device_set_name to prevent leak
commit: e1f345abf4c0df94ef6c5eca400a440c16b47d81Signature · 1 line
Tom