public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] creds: suppress warning in get_cred
@ 2009-01-19 10:10 Stephen Rothwell
  2009-01-19 11:03 ` Hannes Eder
  2009-01-19 12:29 ` David Howells
  0 siblings, 2 replies; 7+ messages in thread
From: Stephen Rothwell @ 2009-01-19 10:10 UTC (permalink / raw)
  To: David Howells; +Cc: James Morris, LKML

This is the usual way to force a conversion from a const pointer to a
non-const one and gets rid of this warning:

include/linux/cred.h: In function 'get_cred':
include/linux/cred.h:188: warning: passing argument 1 of 'get_new_cred' discards qualifiers from pointer target type

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 include/linux/cred.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/include/linux/cred.h b/include/linux/cred.h
index 3282ee4..ed38227 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -12,6 +12,7 @@
 #ifndef _LINUX_CRED_H
 #define _LINUX_CRED_H
 
+#include <linux/types.h>
 #include <linux/capability.h>
 #include <linux/key.h>
 #include <asm/atomic.h>
@@ -185,7 +186,7 @@ static inline struct cred *get_new_cred(struct cred *cred)
  */
 static inline const struct cred *get_cred(const struct cred *cred)
 {
-	return get_new_cred((struct cred *) cred);
+	return get_new_cred((struct cred *)(uintptr_t)cred);
 }
 
 /**
-- 
1.6.0.5

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

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

* Re: [PATCH] creds: suppress warning in get_cred
  2009-01-19 10:10 [PATCH] creds: suppress warning in get_cred Stephen Rothwell
@ 2009-01-19 11:03 ` Hannes Eder
  2009-01-19 14:37   ` Stephen Rothwell
  2009-01-19 12:29 ` David Howells
  1 sibling, 1 reply; 7+ messages in thread
From: Hannes Eder @ 2009-01-19 11:03 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: David Howells, James Morris, LKML

On Mon, Jan 19, 2009 at 11:10 AM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> This is the usual way to force a conversion from a const pointer to a
> non-const one and gets rid of this warning:
>
> include/linux/cred.h: In function 'get_cred':
> include/linux/cred.h:188: warning: passing argument 1 of 'get_new_cred' discards qualifiers from pointer target type
>
> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
> ---
>  include/linux/cred.h |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/include/linux/cred.h b/include/linux/cred.h
> index 3282ee4..ed38227 100644
> --- a/include/linux/cred.h
> +++ b/include/linux/cred.h
> @@ -12,6 +12,7 @@
>  #ifndef _LINUX_CRED_H
>  #define _LINUX_CRED_H
>
> +#include <linux/types.h>
>  #include <linux/capability.h>
>  #include <linux/key.h>
>  #include <asm/atomic.h>
> @@ -185,7 +186,7 @@ static inline struct cred *get_new_cred(struct cred *cred)
>  */
>  static inline const struct cred *get_cred(const struct cred *cred)
>  {
> -       return get_new_cred((struct cred *) cred);
> +       return get_new_cred((struct cred *)(uintptr_t)cred);
>  }
>
>  /**

This is most likly a compiler bug, see

http://lkml.org/lkml/2008/11/20/441 and followups.

-Hannes

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

* Re: [PATCH] creds: suppress warning in get_cred
  2009-01-19 10:10 [PATCH] creds: suppress warning in get_cred Stephen Rothwell
  2009-01-19 11:03 ` Hannes Eder
@ 2009-01-19 12:29 ` David Howells
  2009-01-19 14:52   ` Stephen Rothwell
  1 sibling, 1 reply; 7+ messages in thread
From: David Howells @ 2009-01-19 12:29 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: dhowells, James Morris, LKML

Stephen Rothwell <sfr@canb.auug.org.au> wrote:

> +	return get_new_cred((struct cred *)(uintptr_t)cred);

That should probably be 'unsigned long' within the kernel.  This is also a
compiler bug, but I think we can live with this fix.

David

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

* Re: [PATCH] creds: suppress warning in get_cred
  2009-01-19 11:03 ` Hannes Eder
@ 2009-01-19 14:37   ` Stephen Rothwell
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Rothwell @ 2009-01-19 14:37 UTC (permalink / raw)
  To: Hannes Eder; +Cc: David Howells, James Morris, LKML

[-- Attachment #1: Type: text/plain, Size: 354 bytes --]

Hi Hannes,

On Mon, 19 Jan 2009 12:03:44 +0100 "Hannes Eder" <hannes@hanneseder.net> wrote:
>
> This is most likly a compiler bug, see
> 
> http://lkml.org/lkml/2008/11/20/441 and followups.

Thanks.  Time for a new cross compiler. :-)

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: [PATCH] creds: suppress warning in get_cred
  2009-01-19 12:29 ` David Howells
@ 2009-01-19 14:52   ` Stephen Rothwell
  2009-01-19 14:59     ` Hannes Eder
  2009-01-19 20:19     ` David Howells
  0 siblings, 2 replies; 7+ messages in thread
From: Stephen Rothwell @ 2009-01-19 14:52 UTC (permalink / raw)
  To: David Howells; +Cc: James Morris, LKML, Hannes Eder

[-- Attachment #1: Type: text/plain, Size: 818 bytes --]

Hi David,

On Mon, 19 Jan 2009 12:29:31 +0000 David Howells <dhowells@redhat.com> wrote:
>
> Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> 
> > +	return get_new_cred((struct cred *)(uintptr_t)cred);
> 
> That should probably be 'unsigned long' within the kernel.  This is also a
> compiler bug, but I think we can live with this fix.

We do have uintptr_t inside the kernel (it is typedeffed to unsigned
long) but I used it explicitly because its type is defined to be large
enough to store any pointer.

However, I have also verified that using a newer compiler (4.3.2 in my
case) makes the warning go away as Hannes Eder pointed out when
mentioning his earlier patch.

So, your choice.
-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: [PATCH] creds: suppress warning in get_cred
  2009-01-19 14:52   ` Stephen Rothwell
@ 2009-01-19 14:59     ` Hannes Eder
  2009-01-19 20:19     ` David Howells
  1 sibling, 0 replies; 7+ messages in thread
From: Hannes Eder @ 2009-01-19 14:59 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: David Howells, James Morris, LKML

On Mon, Jan 19, 2009 at 3:52 PM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> Hi David,
>
> On Mon, 19 Jan 2009 12:29:31 +0000 David Howells <dhowells@redhat.com> wrote:
>>
>> Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>>
>> > +   return get_new_cred((struct cred *)(uintptr_t)cred);
>>
>> That should probably be 'unsigned long' within the kernel.  This is also a
>> compiler bug, but I think we can live with this fix.
>
> We do have uintptr_t inside the kernel (it is typedeffed to unsigned
> long) but I used it explicitly because its type is defined to be large
> enough to store any pointer.

When working around this compiler bug would it be better to do it like this:

+     return get_new_cred((struct cred *)(void *)cred);

instead of relying on the size of a pointer and using an large enough
integer data type?

Maybe would should just add a comment, to note that if such a warning
is issued, that
this is a compiler bug.

Or disable the warning for this region, but as far as I know gcc _does
not_ have this feature yet.

> However, I have also verified that using a newer compiler (4.3.2 in my
> case) makes the warning go away as Hannes Eder pointed out when
> mentioning his earlier patch.

Hannes

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

* Re: [PATCH] creds: suppress warning in get_cred
  2009-01-19 14:52   ` Stephen Rothwell
  2009-01-19 14:59     ` Hannes Eder
@ 2009-01-19 20:19     ` David Howells
  1 sibling, 0 replies; 7+ messages in thread
From: David Howells @ 2009-01-19 20:19 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: dhowells, James Morris, LKML, Hannes Eder

Stephen Rothwell <sfr@canb.auug.org.au> wrote:

> We do have uintptr_t inside the kernel (it is typedeffed to unsigned
> long) but I used it explicitly because its type is defined to be large
> enough to store any pointer.

I believe that within the kernel, unsigned long is guaranteed to be the same
size as a pointer; so much code will break if this is not true.

> However, I have also verified that using a newer compiler (4.3.2 in my
> case) makes the warning go away as Hannes Eder pointed out when
> mentioning his earlier patch.
> 
> So, your choice.

I don't mind you putting the cast in, but I'd prefer the cast to be via
unsigned long, and I think it should have a comment to indicate why the extra
cast is necessary.

David

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

end of thread, other threads:[~2009-01-19 20:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-19 10:10 [PATCH] creds: suppress warning in get_cred Stephen Rothwell
2009-01-19 11:03 ` Hannes Eder
2009-01-19 14:37   ` Stephen Rothwell
2009-01-19 12:29 ` David Howells
2009-01-19 14:52   ` Stephen Rothwell
2009-01-19 14:59     ` Hannes Eder
2009-01-19 20:19     ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox