Messages in this thread | | | Date | Mon, 17 Dec 2007 16:21:12 -0800 (PST) | From | Linus Torvalds <> | Subject | Re: Top kernel oopses/warnings this week |
| |
On Mon, 17 Dec 2007, Arjan van de Ven wrote: > > +char *get_boot_uuid(void) > +{ > + static char target[38]; > + unsigned char *uuid; > + > + if (sysctl_bootid[8] == 0) > + generate_random_uuid(sysctl_bootid); > + /* sysctl_bootid is signed, to print we need unsigned .. */ > + uuid = sysctl_bootid; > + > + if (target[0] == 0) { > + sprintf(target, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" > + "%02x%02x%02x%02x%02x%02x",
Why isn't *everything* inside that "if (target[0] == 0" check?
IOW, that function should look something like
const char *get_boot_uuid(void) { static char target[38];
if (!target[0]) fill_boot_uid(target) return target; }
which also allows you to clean it up a bit.
I'd _also_ suggest that you'd actually try to avoid that horrid sequence of "%02x..", and instead just make sure that sysctl_bootid[] is 4-byte aligned, and then you can do
sprintf("%08x-%04x-%04x-%04x-%04x%08x", ntohl(0[(u32 *)uuid]), ntohs(2[(u16 *)uuid]), ntohs(3[(u16 *)uuid]), ntohs(4[(u16 *)uuid]), ntohs(5[(u16 *)uuid]), ntohl(3[(u32 *)uuid]));
which also gets bonus points for being totally unreadable, and thus 100% in the spirit of uuid's.
Linus
| |