Skip to contentSkip to conversation

powerpc/85xx: fix compatible property for the L2 cache node

PATCH Superseded Timur Tabi 4 participants 10 messages Apr 29, 2011 PowerPC

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

The compatible property for the L2 cache node (on 85xx systems that don't have a CPC) was using a value for the property length that did not match the actual length of the property.

---
 arch/powerpc/cpu/mpc85xx/fdt.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
arch/powerpc/cpu/mpc85xx/fdt.c +7 -6
index 642f6c5..a3a4b65 100644
@@ -165,7 +165,6 @@ static inline void ft_fixup_l2cache(void *blob)
 	int len, off;
 	u32 *ph;
 	struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
-	char compat_buf[38];
 
 	const u32 line_size = 32;
 	const u32 num_ways = 8;
@@ -192,22 +191,24 @@ static inline void ft_fixup_l2cache(void *blob)
 	}
 
 	if (cpu) {
+		char compat_buf[40];
+
 		if (isdigit(cpu->name[0]))
 			len = sprintf(compat_buf,
-				"fsl,mpc%s-l2-cache-controller", cpu->name);
+				"fsl,mpc%s-l2-cache-controller" "%c" "cache",
+				cpu->name, 0);
 		else
 			len = sprintf(compat_buf,
-				"fsl,%c%s-l2-cache-controller",
-				tolower(cpu->name[0]), cpu->name + 1);
+				"fsl,%c%s-l2-cache-controller" "%c" "cache",
+				tolower(cpu->name[0]), cpu->name + 1, 0);
 
-		sprintf(&compat_buf[len + 1], "cache");
+		fdt_setprop(blob, off, "compatible", compat_buf, len + 1);
 	}
 	fdt_setprop(blob, off, "cache-unified", NULL, 0);
 	fdt_setprop_cell(blob, off, "cache-block-size", line_size);
 	fdt_setprop_cell(blob, off, "cache-size", size);
 	fdt_setprop_cell(blob, off, "cache-sets", num_sets);
 	fdt_setprop_cell(blob, off, "cache-level", 2);
-	fdt_setprop(blob, off, "compatible", compat_buf, sizeof(compat_buf));
 
 	/* we dont bother w/L3 since no platform of this type has one */
 }
Signature · 1 line
1.7.3.4
Applied
#1 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Quoted 8 lines · Timur Tabi

The compatible property for the L2 cache node (on 85xx systems that don't have a CPC) was using a value for the property length that did not match the actual length of the property.

---
arch/powerpc/cpu/mpc85xx/fdt.c | 13 +++++++------

1 files changed, 7 insertions(+), 6 deletions(-)

applied to 85xx

- k

#2 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Dear Kumar Gala,

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 4 lines · Timur Tabi

The compatible property for the L2 cache node (on 85xx systems that don't have a CPC) was using a value for the property length that did not match the actual length of the property.

Quoted 6 lines
Quoted 4 lines

---
arch/powerpc/cpu/mpc85xx/fdt.c | 13 +++++++------

1 files changed, 7 insertions(+), 6 deletions(-)

applied to 85xx

Kumar, don't you think that 32 minutes of review time is way too long for such a patch?? Maybe we should stop doing code reviews, and just accept all crap that gets posted here.

Hey, we could automate this and have lots of free time instead.

NAK!!

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Ernest asks Frank how long he has been working for the company.
        "Ever since they threatened to fire me."
#3 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Quoted 17 lines · Wolfgang Denk

Dear Kumar Gala,

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 4 lines · Timur Tabi

The compatible property for the L2 cache node (on 85xx systems that don't have a CPC) was using a value for the property length that did not match the actual length of the property.

Quoted 6 lines
Quoted 4 lines

---
arch/powerpc/cpu/mpc85xx/fdt.c | 13 +++++++------

1 files changed, 7 insertions(+), 6 deletions(-)

applied to 85xx

Quoted 7 lines

Kumar, don't you think that 32 minutes of review time is way too long for such a patch?? Maybe we should stop doing code reviews, and just accept all crap that gets posted here.

Hey, we could automate this and have lots of free time instead.

NAK!!

I was thinking the patch wasn't going to have any additional commentary.

- k

#4 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Dear Kumar Gala,

Quoted 2 lines · In message <[email protected]> you wrote:

I was thinking the patch wasn't going to have any additional commentary.

The rule is that we allow _a_few_working_days_ of review time normally - not just a few minutes.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
An age is called Dark not because  the  light  fails  to  shine,  but
because people refuse to see it.           -- James Michener, "Space"
#5 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

In reply to Timur Tabi

Dear Timur Tabi,

Quoted 22 lines · In message <[email protected]> you wrote:

The compatible property for the L2 cache node (on 85xx systems that don't have a CPC) was using a value for the property length that did not match the actual length of the property.

---
 arch/powerpc/cpu/mpc85xx/fdt.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
arch/powerpc/cpu/mpc85xx/fdt.c +0 -1
index 642f6c5..a3a4b65 100644
@@ -165,7 +165,6 @@ static inline void ft_fixup_l2cache(void *blob)
 	int len, off;
 	u32 *ph;
 	struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
-	char compat_buf[38];
 
 	const u32 line_size = 32;
 	const u32 num_ways = 8;

arch/powerpc/cpu/mpc85xx/fdt.c static inline void ft_fixup_l2cache(void *blob) · line 199

Quoted 10 lines
arch/powerpc/cpu/mpc85xx/fdt.c +4 -1
@@ -192,22 +191,24 @@ static inline void ft_fixup_l2cache(void *blob)
 	}
 
 	if (cpu) {
+		char compat_buf[40];
+
 		if (isdigit(cpu->name[0]))
 			len = sprintf(compat_buf,
-				"fsl,mpc%s-l2-cache-controller", cpu->name);
+				"fsl,mpc%s-l2-cache-controller" "%c" "cache",
+				cpu->name, 0);

This is a somewhat funny and complicated way of writing

				"fsl,mpc%s-l2-cache-controller\0cache"

which, when written in plain text, reveals what sort of trickery you are doing here.

This code is a dirty hack, and I will not accept it.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
...though his invention worked superbly -- his theory was a crock  of
sewage from beginning to end.         - Vernor Vinge, "The Peace War"
#6 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Quoted 38 lines · On Fri, 29 Apr 2011 22:30:58 +0200 Wolfgang Denk <[email protected]> wrote:

Dear Timur Tabi,

Quoted 22 lines · In message <[email protected]> you wrote:

The compatible property for the L2 cache node (on 85xx systems that don't have a CPC) was using a value for the property length that did not match the actual length of the property.

---
 arch/powerpc/cpu/mpc85xx/fdt.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
arch/powerpc/cpu/mpc85xx/fdt.c +0 -1
index 642f6c5..a3a4b65 100644
@@ -165,7 +165,6 @@ static inline void ft_fixup_l2cache(void *blob)
 	int len, off;
 	u32 *ph;
 	struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
-	char compat_buf[38];
 
 	const u32 line_size = 32;
 	const u32 num_ways = 8;

arch/powerpc/cpu/mpc85xx/fdt.c static inline void ft_fixup_l2cache(void *blob) · line 199

Quoted 10 lines
arch/powerpc/cpu/mpc85xx/fdt.c +4 -1
@@ -192,22 +191,24 @@ static inline void ft_fixup_l2cache(void *blob)
 	}
 
 	if (cpu) {
+		char compat_buf[40];
+
 		if (isdigit(cpu->name[0]))
 			len = sprintf(compat_buf,
-				"fsl,mpc%s-l2-cache-controller", cpu->name);
+				"fsl,mpc%s-l2-cache-controller" "%c" "cache",
+				cpu->name, 0);

This is a somewhat funny and complicated way of writing

Quoted 1 line
				"fsl,mpc%s-l2-cache-controller\0cache"

Except that his version works and your version doesn't. With your version sprintf will stop reading the format string after "controller".

Quoted 4 lines

which, when written in plain text, reveals what sort of trickery you are doing here.

This code is a dirty hack, and I will not accept it.

The alternative is two separate sprintfs, manually advancing the pointer in the calling code, but that's a bit more complicated and error-prone (the previous code did it that way, and had an error, thus this patch) and IMHO not more readable.

-Scott

#7 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Dear Scott Wood,

Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 8 lines

arch/powerpc/cpu/mpc85xx/fdt.c static inline void ft_fixup_l2cache(void *blob) · line 199

Quoted 5 lines
arch/powerpc/cpu/mpc85xx/fdt.c +2 -1
 			len = sprintf(compat_buf,
-				"fsl,mpc%s-l2-cache-controller", cpu->name);
+				"fsl,mpc%s-l2-cache-controller" "%c" "cache",
+				cpu->name, 0);

This is a somewhat funny and complicated way of writing

Quoted 4 lines
Quoted 1 line
				"fsl,mpc%s-l2-cache-controller\0cache"

Except that his version works and your version doesn't. With your version sprintf will stop reading the format string after "controller".

Yes, and this is why I call this a dirty hack, as it's obfuscating what's going on and what the intended result is.

Quoted 4 lines

The alternative is two separate sprintfs, manually advancing the pointer in the calling code, but that's a bit more complicated and error-prone (the previous code did it that way, and had an error, thus this patch) and IMHO not more readable.

At least people who read the code in a year will then be able to understand what you are doing.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
In general, if you think something isn't in Perl, try it out, because
it usually is :-) - Larry Wall in <[email protected]>
author
#8 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Quoted 5 lines · Wolfgang Denk
Quoted 2 lines
Quoted 2 lines

Except that his version works and your version doesn't. With your version sprintf will stop reading the format string after "controller".

Yes, and this is why I call this a dirty hack, as it's obfuscating what's going on and what the intended result is.

I disagree. It's quite clear what I'm trying to do. I'm trying to insert a NULL character into a string. Since device tree properties use a NULL to delimit multiple strings, it's clear that this is what the "0" is for.

Look at the original code:

	len = sprintf(compat_buf,
		"fsl,%c%s-l2-cache-controller",
		tolower(cpu->name[0]), cpu->name + 1);

	sprintf(&compat_buf[len + 1], "cache");

I think my patch is clearer than this. In fact, because the original code was so obscure, there was a bug in it. I could have done this:

	len = sprintf(compat_buf,
		"fsl,%c%s-l2-cache-controller",
		tolower(cpu->name[0]), cpu->name + 1);

	len += sprintf(&compat_buf[len + 1], "cache") + 2;

Where the "+ 2" is for each NULL in the string. I just don't see how this is better than my version.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#9 lore raw

PATCH v2 1/1 powerpc/85xx: fix compatible property for the L2 cache node

Dear Timur Tabi,

Quoted 2 lines · In message <[email protected]> you wrote:

I disagree. It's quite clear what I'm trying to do. I'm trying to insert a

This is your opinion. I disagree.

Quoted 2 lines

NULL character into a string. Since device tree properties use a NULL to delimit multiple strings, it's clear that this is what the "0" is for.

Wrong data type. In C strings are _terminated_ by '\0' characters, so using functions that are designed to deal with C strings are obviously not the right tool to deal with data structures that have _embedded_ NUL characters.

If you try, it quickly gets ugly like the code I rejected.

For example, who gives you any guarantee that sprintf() will continue to append characters after it inserted the first NUL character? A clever implementation could optimize this and return immediately after seeing a NUL...

Quoted 10 lines

Look at the original code:

	len = sprintf(compat_buf,
		"fsl,%c%s-l2-cache-controller",
		tolower(cpu->name[0]), cpu->name + 1);

	sprintf(&compat_buf[len + 1], "cache");

I think my patch is clearer than this. In fact, because the original code was so obscure, there was a bug in it. I could have done this:

Why exactly do you think you have to use sprintf() to append a constant string like "cache"?

If you want to make clean what's intended, then use something like this:

	len = sprintf(print_buf, "fsl,%c%s-l2-cache-controller",
		tolower(cpu->name[0]), cpu->name + 1);
	
	/* Include NUL characters */
	memcpy(compat_buf, print_buf, len + 1);
	memcpy(compat_buf + len + 1, "cache", sizeof("cache"));

If you want to optimize (I'm a fan of small memory footprint, but I'm also a fan of readable code), use

	len = sprintf(compat_buf, "fsl,%c%s-l2-cache-controller",
		tolower(cpu->name[0]), cpu->name + 1);
	
	/* Include NUL characters */
	memcpy(compat_buf + len + 1, "cache", sizeof("cache"));

etc.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
egrep patterns are full regular expressions; it uses a fast  determi-
nistic algorithm that sometimes needs exponential space.
- unix manuals