[PATCH 10/10] ppc64: Define /cpus in iSeries device tree
Milton Miller
miltonm at bga.com
Wed Aug 10 17:28:39 EST 2005
>
> +void dt_cpus(struct iseries_flat_dt *dt)+{
> + unsigned char buf[32];
...
> +
> + /* yuck */
> + snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
> + p = strchr(buf, ' ');
> + if (!p) p = buf + strlen(buf);
...
> + for (i = 0; i < NR_CPUS; i++) {
...
> + snprintf(p, 32 - (p - buf), "@%d", i);
> + dt_start_node(dt, buf);
The magic number number 32 occurs at least 3 times in this context,
but later a different magic 32 occurs in this function.
The math for second one takes thought to verify.
How about just calculating the length of the desired part of the
cpu name and then doing a single snprintf with a %*s counted length
string? Alternatively, a private copy of the desired portion
might be clearer code.
We might also want to warn if we get 32 chars and/or limit the
length so that we are sure to have room for the instance address.
Something like (totally untested):
snprintf(buf, sizeof(buf), "PowerPC,%*s@%d", cpunamelen,
cur_cpu_spec->cpu_name, i);
milton
More information about the Linuxppc64-dev
mailing list