RE: [PATCH 2/6] setup.c: move initrd code inside dedicated functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Franck Bui-Huu wrote:
> Atsushi Nemoto wrote:
> >> +	printk(KERN_INFO "Initial ramdisk at: 0x%p (%lu bytes)\n",
> >> +	       (void *)initrd_start, initrd_size);
> > 
> > You can use "0x%lx" for initrd_start and remove the cast.  
> I know this
> > fragment are copied from corrent code as is, but it would be a good
> > chance to clean it up.
> > 
> 
> You're right.

Actually the cast that is there is only pedantic. ANSI C says that
%p must be met with a void *, which might be important on some
exotic machine where pointers have a different representation
based on their type. Elsewhere, it would be very surprising
if omitting the (void *) caused a problem with %p.

You definitely do need a cast if you are printing a pointer
as an integer though.

And you have to cast to an integer that is wide enough for the
pointer.  If you are compiling for 64 bit, that means
"unsigned long long", unless you are sure that the upper
32 bits are all zero. 

Ideally, you should just be able to use %p to print pointers,
and I'd love to recommend that. It should be smart enough to
know that they are 64 bits wide. I'm looking at the vsprintf
in 2.6.17 and see that, sadly, it converts the void * pulled
from the va_arg to "unsigned long".

Oopsies!

One last note: if you are printing hex, and want that
0x prefix, you can use the # flag, e.g.

  printk(KERN_INFO "%#lx\n", 0xdeadbeefUL);

Cheers ...







[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux