* [patch] clean up tcp_sk(), 2.6.0
@ 2003-12-30 16:32 Ingo Molnar
2003-12-30 16:50 ` YOSHIFUJI Hideaki / 吉藤英明
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Ingo Molnar @ 2003-12-30 16:32 UTC (permalink / raw)
To: David S. Miller; +Cc: linux-kernel, netdev
i recently wasted a few hours on a bug where i used "tcp_sk(sock)"
instead of "tcp_sk(sock->sk)" - the former, while being blatantly
incorrect, compiles just fine on 2.6.0. The patch below is equivalent to
the define but is also type-safe. Compiles cleanly & boots fine on
2.6.0.
Ingo
--- linux/include/linux/tcp.h.orig
+++ linux/include/linux/tcp.h
@@ -386,7 +386,10 @@ struct tcp_sock {
struct tcp_opt tcp;
};
-#define tcp_sk(__sk) (&((struct tcp_sock *)__sk)->tcp)
+static inline struct tcp_opt * tcp_sk(const struct sock *__sk)
+{
+ return &((struct tcp_sock *)__sk)->tcp;
+}
#endif
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] clean up tcp_sk(), 2.6.0
2003-12-30 16:32 [patch] clean up tcp_sk(), 2.6.0 Ingo Molnar
@ 2003-12-30 16:50 ` YOSHIFUJI Hideaki / 吉藤英明
2003-12-30 16:57 ` Arnaldo Carvalho de Melo
2003-12-30 22:46 ` David S. Miller
2 siblings, 0 replies; 5+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2003-12-30 16:50 UTC (permalink / raw)
To: mingo; +Cc: davem, linux-kernel, netdev, yoshfuji
In article <20031230163230.GA12553@elte.hu> (at Tue, 30 Dec 2003 17:32:30 +0100), Ingo Molnar <mingo@elte.hu> says:
> incorrect, compiles just fine on 2.6.0. The patch below is equivalent to
> the define but is also type-safe. Compiles cleanly & boots fine on
> 2.6.0.
:
> -#define tcp_sk(__sk) (&((struct tcp_sock *)__sk)->tcp)
> +static inline struct tcp_opt * tcp_sk(const struct sock *__sk)
> +{
> + return &((struct tcp_sock *)__sk)->tcp;
> +}
>
You probably want to convert other similar things such as
inet_sk(), inet6_sk() etc. :-)
--
Hideaki YOSHIFUJI @ USAGI Project <yoshfuji@linux-ipv6.org>
GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] clean up tcp_sk(), 2.6.0
2003-12-30 16:32 [patch] clean up tcp_sk(), 2.6.0 Ingo Molnar
2003-12-30 16:50 ` YOSHIFUJI Hideaki / 吉藤英明
@ 2003-12-30 16:57 ` Arnaldo Carvalho de Melo
2003-12-30 22:46 ` David S. Miller
2 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2003-12-30 16:57 UTC (permalink / raw)
To: Ingo Molnar; +Cc: David S. Miller, linux-kernel, netdev
Em Tue, Dec 30, 2003 at 05:32:30PM +0100, Ingo Molnar escreveu:
>
> i recently wasted a few hours on a bug where i used "tcp_sk(sock)"
> instead of "tcp_sk(sock->sk)" - the former, while being blatantly
> incorrect, compiles just fine on 2.6.0. The patch below is equivalent to
> the define but is also type-safe. Compiles cleanly & boots fine on
> 2.6.0.
Don't have a problem, but then it'd be nice to do this for udp_sk, raw_sk,
etc, etc :)
- Arnaldo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] clean up tcp_sk(), 2.6.0
2003-12-30 16:32 [patch] clean up tcp_sk(), 2.6.0 Ingo Molnar
2003-12-30 16:50 ` YOSHIFUJI Hideaki / 吉藤英明
2003-12-30 16:57 ` Arnaldo Carvalho de Melo
@ 2003-12-30 22:46 ` David S. Miller
2003-12-31 10:12 ` Ingo Molnar
2 siblings, 1 reply; 5+ messages in thread
From: David S. Miller @ 2003-12-30 22:46 UTC (permalink / raw)
To: Ingo Molnar; +Cc: linux-kernel, netdev
On Tue, 30 Dec 2003 17:32:30 +0100
Ingo Molnar <mingo@elte.hu> wrote:
> i recently wasted a few hours on a bug where i used "tcp_sk(sock)"
> instead of "tcp_sk(sock->sk)" - the former, while being blatantly
> incorrect, compiles just fine on 2.6.0. The patch below is equivalent to
> the define but is also type-safe. Compiles cleanly & boots fine on
> 2.6.0.
Applied, and I'll happily accept patches for udp_sk() and all
the other ones too :)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] clean up tcp_sk(), 2.6.0
2003-12-30 22:46 ` David S. Miller
@ 2003-12-31 10:12 ` Ingo Molnar
0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2003-12-31 10:12 UTC (permalink / raw)
To: David S. Miller; +Cc: linux-kernel, netdev
* David S. Miller <davem@redhat.com> wrote:
> On Tue, 30 Dec 2003 17:32:30 +0100
> Ingo Molnar <mingo@elte.hu> wrote:
>
> > i recently wasted a few hours on a bug where i used "tcp_sk(sock)"
> > instead of "tcp_sk(sock->sk)" - the former, while being blatantly
> > incorrect, compiles just fine on 2.6.0. The patch below is equivalent to
> > the define but is also type-safe. Compiles cleanly & boots fine on
> > 2.6.0.
>
> Applied, and I'll happily accept patches for udp_sk() and all
> the other ones too :)
sure - patch for udp_sk, inet6_sk/raw6_sk and inet_sk attached. Compiles
cleanly and boots. The inet_sk one uncovered a couple of other bugs in
my code. (The other defines for protocol-private sockets seem to be safe
because they all use ->sk_protinfo which forces the type.)
Ingo
--- linux/include/linux/udp.h.orig
+++ linux/include/linux/udp.h
@@ -60,7 +60,10 @@ struct udp_sock {
struct udp_opt udp;
};
-#define udp_sk(__sk) (&((struct udp_sock *)__sk)->udp)
+static inline struct udp_opt * udp_sk(const struct sock *__sk)
+{
+ return &((struct udp_sock *)__sk)->udp;
+}
#endif
--- linux/include/linux/ipv6.h.orig
+++ linux/include/linux/ipv6.h
@@ -270,8 +270,15 @@ struct tcp6_sock {
struct ipv6_pinfo inet6;
};
-#define inet6_sk(__sk) ((struct raw6_sock *)__sk)->pinet6
-#define raw6_sk(__sk) (&((struct raw6_sock *)__sk)->raw6)
+static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
+{
+ return ((struct raw6_sock *)__sk)->pinet6;
+}
+
+static inline struct raw6_opt * raw6_sk(const struct sock *__sk)
+{
+ return &((struct raw6_sock *)__sk)->raw6;
+}
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
#define __ipv6_only_sock(sk) (inet6_sk(sk)->ipv6only)
--- linux/include/linux/ip.h.orig
+++ linux/include/linux/ip.h
@@ -159,7 +159,10 @@ struct inet_sock {
struct inet_opt inet;
};
-#define inet_sk(__sk) (&((struct inet_sock *)__sk)->inet)
+static inline struct inet_opt * inet_sk(const struct sock *__sk)
+{
+ return &((struct inet_sock *)__sk)->inet;
+}
#endif
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-12-31 10:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-30 16:32 [patch] clean up tcp_sk(), 2.6.0 Ingo Molnar
2003-12-30 16:50 ` YOSHIFUJI Hideaki / 吉藤英明
2003-12-30 16:57 ` Arnaldo Carvalho de Melo
2003-12-30 22:46 ` David S. Miller
2003-12-31 10:12 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).