All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] fix void* arithmetic
@ 2006-08-29 20:24 Hollis Blanchard
  2006-08-29 20:35 ` Aron Griffis
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Hollis Blanchard @ 2006-08-29 20:24 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

Hi Ian, I needed the following patch to avoid lots of these warnings:
	elf.c:238: warning: pointer of type `void *' used in arithmetic

Fix void* arithmetic warnings.
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff -r 030a041bbe90 xen/common/elf.c
--- a/xen/common/elf.c  Tue Aug 29 06:53:58 2006 -0400
+++ b/xen/common/elf.c  Tue Aug 29 15:22:26 2006 -0500
@@ -102,9 +102,9 @@ static unsigned long long xen_guest_nume
 /*
  * Interface to the Xen ELF notes.
  */
-#define ELFNOTE_NAME(_n_)   ((void*)(_n_) + sizeof(*(_n_)))
-#define ELFNOTE_DESC(_n_)   (ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3))
-#define ELFNOTE_NEXT(_n_)   (ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3))
+#define ELFNOTE_NAME(_n_)   ((void*)((char*)(_n_) + sizeof(*(_n_))))
+#define ELFNOTE_DESC(_n_)   (((void*)((char*)ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3))))
+#define ELFNOTE_NEXT(_n_)   (((void*)((char*)ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3))))

 static int is_xen_elfnote_section(const char *image, Elf_Shdr *shdr)
 {
@@ -235,9 +235,9 @@ int parseelfimage(struct domain_setup_in
         shdr = (Elf_Shdr *)(image + ehdr->e_shoff + (h*ehdr->e_shentsize));
         if ( !is_xen_elfnote_section(image, shdr) )
             continue;
-        dsi->__elfnote_section = (void *)image + shdr->sh_offset;
+        dsi->__elfnote_section = (char *)image + shdr->sh_offset;
         dsi->__elfnote_section_end =
-            (void *)image + shdr->sh_offset + shdr->sh_size;
+            (char *)image + shdr->sh_offset + shdr->sh_size;
         break;
     }



-- 
Hollis Blanchard
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] fix void* arithmetic
  2006-08-29 20:24 [patch] fix void* arithmetic Hollis Blanchard
@ 2006-08-29 20:35 ` Aron Griffis
  2006-08-29 21:06 ` Ian Campbell
  2006-08-30  8:47 ` Jan Beulich
  2 siblings, 0 replies; 7+ messages in thread
From: Aron Griffis @ 2006-08-29 20:35 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: xen-devel, Ian Campbell

Hollis Blanchard wrote:  [Tue Aug 29 2006, 04:24:48PM EDT]
> +#define ELFNOTE_NAME(_n_)   ((void*)((char*)(_n_) + sizeof(*(_n_))))
> +#define ELFNOTE_DESC(_n_)   (((void*)((char*)ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3))))
> +#define ELFNOTE_NEXT(_n_)   (((void*)((char*)ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3))))

Too many parens on the latter two?  I think this is the same:

#define ELFNOTE_NAME(_n_)   ((void*)((char*)(_n_) + sizeof(*(_n_))))
#define ELFNOTE_DESC(_n_)   ((void*)((char*)ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3)))
#define ELFNOTE_NEXT(_n_)   ((void*)((char*)ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3)))

Aron

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] fix void* arithmetic
  2006-08-29 20:24 [patch] fix void* arithmetic Hollis Blanchard
  2006-08-29 20:35 ` Aron Griffis
@ 2006-08-29 21:06 ` Ian Campbell
  2006-08-29 21:18   ` Hollis Blanchard
  2006-08-30  8:47 ` Jan Beulich
  2 siblings, 1 reply; 7+ messages in thread
From: Ian Campbell @ 2006-08-29 21:06 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: xen-devel

On Tue, 2006-08-29 at 15:24 -0500, Hollis Blanchard wrote:
> Hi Ian, I needed the following patch to avoid lots of these warnings:
> 	elf.c:238: warning: pointer of type `void *' used in arithmetic
> 
> Fix void* arithmetic warnings.
> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

Looks like PPC is the only arch using -Wpointer-arith, is there a reason
for that?

Ian.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: [patch] fix void* arithmetic
  2006-08-29 21:06 ` Ian Campbell
@ 2006-08-29 21:18   ` Hollis Blanchard
  2006-08-29 21:26     ` Jeff Garzik
  2006-08-30 16:35     ` Keir Fraser
  0 siblings, 2 replies; 7+ messages in thread
From: Hollis Blanchard @ 2006-08-29 21:18 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel, xen-ppc-devel

On Tue, 2006-08-29 at 22:06 +0100, Ian Campbell wrote:
> On Tue, 2006-08-29 at 15:24 -0500, Hollis Blanchard wrote:
> > Hi Ian, I needed the following patch to avoid lots of these warnings:
> > 	elf.c:238: warning: pointer of type `void *' used in arithmetic
> > 
> > Fix void* arithmetic warnings.
> > Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
> 
> Looks like PPC is the only arch using -Wpointer-arith, is there a reason
> for that?

Is there are reason the other architectures *aren't* using it?

We have some extra warnings enabled because they've helped us in the
past (such as -Wshadow). Given that we're just playing janitor for
everyone else's code though, I think we're about to abandon that one.

-- 
Hollis Blanchard
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: [patch] fix void* arithmetic
  2006-08-29 21:18   ` Hollis Blanchard
@ 2006-08-29 21:26     ` Jeff Garzik
  2006-08-30 16:35     ` Keir Fraser
  1 sibling, 0 replies; 7+ messages in thread
From: Jeff Garzik @ 2006-08-29 21:26 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: xen-ppc-devel, xen-devel, Ian Campbell

Hollis Blanchard wrote:
> On Tue, 2006-08-29 at 22:06 +0100, Ian Campbell wrote:
>> On Tue, 2006-08-29 at 15:24 -0500, Hollis Blanchard wrote:
>>> Hi Ian, I needed the following patch to avoid lots of these warnings:
>>> 	elf.c:238: warning: pointer of type `void *' used in arithmetic
>>>
>>> Fix void* arithmetic warnings.
>>> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
>> Looks like PPC is the only arch using -Wpointer-arith, is there a reason
>> for that?
> 
> Is there are reason the other architectures *aren't* using it?
> 
> We have some extra warnings enabled because they've helped us in the
> past (such as -Wshadow). Given that we're just playing janitor for
> everyone else's code though, I think we're about to abandon that one.

Pointer arith is quite valid on void pointers, when using gcc and most 
other modern compilers.

Point of fact, any Linux kernel-related code REQUIRES that void* arith 
be valid, and not cause warnings.

As we see from your patch, all a cast to char* does is complicate the 
code, for zero gain.

	Jeff

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] fix void* arithmetic
  2006-08-29 20:24 [patch] fix void* arithmetic Hollis Blanchard
  2006-08-29 20:35 ` Aron Griffis
  2006-08-29 21:06 ` Ian Campbell
@ 2006-08-30  8:47 ` Jan Beulich
  2 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2006-08-30  8:47 UTC (permalink / raw)
  To: Hollis Blanchard, Ian Campbell; +Cc: xen-devel

>-#define ELFNOTE_NAME(_n_)   ((void*)(_n_) + sizeof(*(_n_)))
>-#define ELFNOTE_DESC(_n_)   (ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3))
>-#define ELFNOTE_NEXT(_n_)   (ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3))
>+#define ELFNOTE_NAME(_n_)   ((void*)((char*)(_n_) + sizeof(*(_n_))))
>+#define ELFNOTE_DESC(_n_)   (((void*)((char*)ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3))))
>+#define ELFNOTE_NEXT(_n_)   (((void*)((char*)ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3))))

This seems to complicate it a little too much, eg it would seem that this

#define ELFNOTE_NAME(_n_)   ((char *)(_n_) + sizeof(*(_n_)))
#define ELFNOTE_DESC(_n_)   (ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3))
#define ELFNOTE_NEXT(_n_)   ((Elf_Note *)(ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3)))

would also do, and would even allow dropping an odd cast in the return statement
of xen_elfnote_string().

Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: [patch] fix void* arithmetic
  2006-08-29 21:18   ` Hollis Blanchard
  2006-08-29 21:26     ` Jeff Garzik
@ 2006-08-30 16:35     ` Keir Fraser
  1 sibling, 0 replies; 7+ messages in thread
From: Keir Fraser @ 2006-08-30 16:35 UTC (permalink / raw)
  To: Hollis Blanchard, Ian Campbell; +Cc: xen-devel, xen-ppc-devel




On 29/8/06 10:18 pm, "Hollis Blanchard" <hollisb@us.ibm.com> wrote:

>> Looks like PPC is the only arch using -Wpointer-arith, is there a reason
>> for that?
> 
> Is there are reason the other architectures *aren't* using it?
> 
> We have some extra warnings enabled because they've helped us in the
> past (such as -Wshadow). Given that we're just playing janitor for
> everyone else's code though, I think we're about to abandon that one.

We have code borrowed from Linux that doesn't like -Wpointer-arith very
much, so we took the pragmatic path here.

 -- Keir

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-08-30 16:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-29 20:24 [patch] fix void* arithmetic Hollis Blanchard
2006-08-29 20:35 ` Aron Griffis
2006-08-29 21:06 ` Ian Campbell
2006-08-29 21:18   ` Hollis Blanchard
2006-08-29 21:26     ` Jeff Garzik
2006-08-30 16:35     ` Keir Fraser
2006-08-30  8:47 ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.