Skip to contentSkip to conversation

powerpc/smp: parse_thread_groups() return error on missing property

PATCH In review John Ogness 3 participants 3 messages Nov 14 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/smp: parse_thread_groups() return error on missing property

parse_thread_groups() is supposed to return -EINVAL if the property does not exist and -ENODATA if property does not have a value. However, it is currently assuming it exists and blindly calling kzalloc_objs() with whatever of_property_count_u32_elems() returns.

Since of_property_count_u32_elems() returns exactly these same error values in those cases, simply return with the returned error value.

---
 arch/powerpc/kernel/smp.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/kernel/smp.c +2 -0
index 7a25eaa59e626..58824f5f4c800 100644
@@ -824,6 +824,8 @@ static int parse_thread_groups(struct device_node *dn,
 	int i = 0;
 
 	count = of_property_count_u32_elems(dn, "ibm,thread-groups");
+	if (count < 0)
+		return count;
 	thread_group_array = kzalloc_objs(u32, count);
 	if (!thread_group_array)
 		return -ENOMEM;
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw

+ Kees, Vlastimil

Quoted 9 lines · John Ogness

parse_thread_groups() is supposed to return -EINVAL if the property does not exist and -ENODATA if property does not have a value. However, it is currently assuming it exists and blindly calling kzalloc_objs() with whatever of_property_count_u32_elems() returns.

Since of_property_count_u32_elems() returns exactly these same error values in those cases, simply return with the returned error value.

Fixes 0af298e62e5cf ("treewide: refresh kmalloc_obj() conversions")

But… The difference in the commit was:

|-       thread_group_array = kcalloc(count, sizeof(u32), GFP_KERNEL);
|+       thread_group_array = kzalloc_objs(u32, count);
|        if (!thread_group_array)
|                return -ENOMEM;

kcalloc() returned NULL on an overflow and did not continue with the allocation. So the check below worked.

kzalloc_objs() on the other hand returns for the overflow SIZE_MAX and passes this down to the allocator. We still get a NULL pointer but with a warning (from ___kmalloc_large_node()).

Is the warning on purpose now?

Sebastian

#2 lore raw
In reply to John Ogness
Quoted 5 lines · John Ogness

parse_thread_groups() is supposed to return -EINVAL if the property does not exist and -ENODATA if property does not have a value. However, it is currently assuming it exists and blindly calling kzalloc_objs() with whatever of_property_count_u32_elems() returns.

Quoted 7 lines

Since of_property_count_u32_elems() returns exactly these same error values in those cases, simply return with the returned error value.

---
 arch/powerpc/kernel/smp.c | 2 ++
 1 file changed, 2 insertions(+)

Thanks! However, the fix for this is already queued to powerpc's fixes branch.

https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?h=fixes&id=126b47221b7b98d83c118781ce724c0515d86d9c

-ritesh