public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] security_sk_free void return fixup
@ 2004-06-15 23:16 Chris Wright
  2004-06-16  2:53 ` Linus Torvalds
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Wright @ 2004-06-15 23:16 UTC (permalink / raw)
  To: akpm, torvalds; +Cc: linux-kernel, Mika Kukkonen

  CHECK   net/core/sock.c
include/linux/security.h:2636:39: warning: return expression in void function
  CC      net/core/sock.o

From: Mika Kukkonen <mika@osdl.org>
Signed-off-by: Chris Wright <chrisw@osdl.org>

===== include/linux/security.h 1.35 vs edited =====
--- 1.35/include/linux/security.h	2004-06-14 08:56:50 -07:00
+++ edited/include/linux/security.h	2004-06-15 16:14:56 -07:00
@@ -2633,7 +2633,7 @@
 
 static inline void security_sk_free(struct sock *sk)
 {
-	return security_ops->sk_free_security(sk);
+	security_ops->sk_free_security(sk);
 }
 #else	/* CONFIG_SECURITY_NETWORK */
 static inline int security_unix_stream_connect(struct socket * sock,

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

* Re: [PATCH] security_sk_free void return fixup
  2004-06-15 23:16 [PATCH] security_sk_free void return fixup Chris Wright
@ 2004-06-16  2:53 ` Linus Torvalds
  2004-06-16  3:00   ` Andrew Morton
  2004-06-16 12:11   ` Dick Streefland
  0 siblings, 2 replies; 5+ messages in thread
From: Linus Torvalds @ 2004-06-16  2:53 UTC (permalink / raw)
  To: Chris Wright; +Cc: akpm, linux-kernel, Mika Kukkonen



On Tue, 15 Jun 2004, Chris Wright wrote:
>
>   CHECK   net/core/sock.c
> include/linux/security.h:2636:39: warning: return expression in void function
>   CC      net/core/sock.o

I'm going to remove this warning from sparse. Apparently it is valid C99, 
and somebody (I think Richard Henderson) made the excellent point that it 
allows for type-independent code where you do something like

	mytype myfunc1(xxx);

	mytype myfunc2(xxx)
	{
		...
		return myfunc1(...);
	}

and it just works regardless of what type it is. 

sparse will obviously warn about expressions with non-void types being 
returned from a void function, but the case where the expression exists 
and has the right type should be ok.

I'm not sure it's wonderful C in general, but I certainly can't claim it 
is actively offensive, and since gcc accepts it and we have these things 
in the kernel, why complain? 

		Linus

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

* Re: [PATCH] security_sk_free void return fixup
  2004-06-16  2:53 ` Linus Torvalds
@ 2004-06-16  3:00   ` Andrew Morton
  2004-06-16  3:04     ` Linus Torvalds
  2004-06-16 12:11   ` Dick Streefland
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2004-06-16  3:00 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: chrisw, linux-kernel, mika

Linus Torvalds <torvalds@osdl.org> wrote:
>
> 
> 
> On Tue, 15 Jun 2004, Chris Wright wrote:
> >
> >   CHECK   net/core/sock.c
> > include/linux/security.h:2636:39: warning: return expression in void function
> >   CC      net/core/sock.o
> 
> I'm going to remove this warning from sparse. Apparently it is valid C99, 

yes, but in every(?) case where it triggered, the kernel code was wrong. 
So I'd suggest the warning be retained, perhaps with an option to enable
it.


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

* Re: [PATCH] security_sk_free void return fixup
  2004-06-16  3:00   ` Andrew Morton
@ 2004-06-16  3:04     ` Linus Torvalds
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Torvalds @ 2004-06-16  3:04 UTC (permalink / raw)
  To: Andrew Morton; +Cc: chrisw, linux-kernel, mika



On Tue, 15 Jun 2004, Andrew Morton wrote:
> > 
> > I'm going to remove this warning from sparse. Apparently it is valid C99, 
> 
> yes, but in every(?) case where it triggered, the kernel code was wrong.

Is that true? Hmm. That would indeed be a strong argument. However, I was 
also a bit alarmed by how one of the fixes for this warning was itself 
actually buggy by dropping the "return" statement altogether and falling 
through. 
 
> So I'd suggest the warning be retained, perhaps with an option to enable
> it.

Hmm. Sparse already has a "verbose" level, although right now it's not 
actually used by anything (it used to enable some warnings that were due 
to sparse deficiencies, but I fixed that particular problem).

		Linus

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

* Re: [PATCH] security_sk_free void return fixup
  2004-06-16  2:53 ` Linus Torvalds
  2004-06-16  3:00   ` Andrew Morton
@ 2004-06-16 12:11   ` Dick Streefland
  1 sibling, 0 replies; 5+ messages in thread
From: Dick Streefland @ 2004-06-16 12:11 UTC (permalink / raw)
  To: linux-kernel

Linus Torvalds <torvalds@osdl.org> wrote:
| I'm going to remove this warning from sparse. Apparently it is valid C99, 
| and somebody (I think Richard Henderson) made the excellent point that it 
| allows for type-independent code where you do something like
| 
| 	mytype myfunc1(xxx);
| 
| 	mytype myfunc2(xxx)
| 	{
| 		...
| 		return myfunc1(...);
| 	}
| 
| and it just works regardless of what type it is. 

It may work in gcc, but it is invalid according to ISO C99. First
sentence from section 6.8.6.4:

  A return statement with an expression shall not appear in a
  function whose return type is void.

Now, a function call is obviously an expression.

| sparse will obviously warn about expressions with non-void types being 
| returned from a void function, but the case where the expression exists 
| and has the right type should be ok.
| 
| I'm not sure it's wonderful C in general, but I certainly can't claim it 
| is actively offensive, and since gcc accepts it and we have these things 
| in the kernel, why complain? 

Gcc warns about this with the -pedantic option:

  $ gcc-3.3 -pedantic -c return.c
  return.c: In function `myfunc2':
  return.c:5: warning: `return' with a value, in function returning void

-- 
Dick Streefland                      ////                      Altium BV
dick.streefland@altium.nl           (@ @)          http://www.altium.com
--------------------------------oOO--(_)--OOo---------------------------


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

end of thread, other threads:[~2004-06-16 12:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-15 23:16 [PATCH] security_sk_free void return fixup Chris Wright
2004-06-16  2:53 ` Linus Torvalds
2004-06-16  3:00   ` Andrew Morton
2004-06-16  3:04     ` Linus Torvalds
2004-06-16 12:11   ` Dick Streefland

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