Skip to contentSkip to conversation

arm64: idreg-override: Use property length in get_bootargs_cmdline()

PATCH In review Thorsten Blum 2 participants 2 messages Oct 15 – Oct 27 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: idreg-override: Use property length in get_bootargs_cmdline()

fdt_getprop() already provides the length of the bootargs property. Use it to reject a zero-length property before dereferencing it, and test the first byte directly instead of calling strlen().

---
 arch/arm64/kernel/pi/idreg-override.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/arm64/kernel/pi/idreg-override.c +5 -3
index acaf56234973..588c8af2a567 100644
@@ -383,15 +383,17 @@ static __init const u8 *get_bootargs_cmdline(const void *fdt, int node)
 {
 	static char const bootargs[] __initconst = "bootargs";
 	const u8 *prop;
+	int len;
 
 	if (node < 0)
 		return NULL;
 
-	prop = fdt_getprop(fdt, node, bootargs, NULL);
-	if (!prop)
+	prop = fdt_getprop(fdt, node, bootargs, &len);
+	/* No bootargs for a missing, zero-length, or empty-string property. */
+	if (!prop || !len || !*prop)
 		return NULL;
 
-	return strlen(prop) ? prop : NULL;
+	return prop;
 }
 
 static __init void parse_cmdline(const void *fdt, int chosen)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Thorsten Blum

fdt_getprop() already provides the length of the bootargs property. Use it to reject a zero-length property before dereferencing it, and test the first byte directly instead of calling strlen().

---
 arch/arm64/kernel/pi/idreg-override.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/arm64/kernel/pi/idreg-override.c +1 -0
index acaf56234973..588c8af2a567 100644
@@ -383,15 +383,17 @@ static __init const u8 *get_bootargs_cmdline(const void *fdt, int node)
 {
 	static char const bootargs[] __initconst = "bootargs";
 	const u8 *prop;
+	int len;
 
 	if (node < 0)
 		return NULL;

arch/arm64/kernel/pi/idreg-override.c static __init const u8 *get_bootargs_cmdline(const void *fdt, int node) · line 396

Quoted 10 lines
arch/arm64/kernel/pi/idreg-override.c +4 -3
 
-	prop = fdt_getprop(fdt, node, bootargs, NULL);
-	if (!prop)
+	prop = fdt_getprop(fdt, node, bootargs, &len);
+	/* No bootargs for a missing, zero-length, or empty-string property. */
+	if (!prop || !len || !*prop)
 		return NULL;
 
-	return strlen(prop) ? prop : NULL;
+	return prop;

I think the patch makes sense. In theory we may have a value-less bootargs property and prop points to the next token (or some FDT_END_NODE) but they would all have 0 as the first byte, so the strlen() check would catch it. Anyway, the above is clearer, so: