netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netfilter: Fix compiler warning.
@ 2009-12-10  1:25 chavey
  2009-12-10  2:07 ` David Miller
  2009-12-10  4:25 ` Eric Dumazet
  0 siblings, 2 replies; 14+ messages in thread
From: chavey @ 2009-12-10  1:25 UTC (permalink / raw)
  To: davem; +Cc: netdev, chavey

Fix compiler warning "discards qualifiers from pointer target type".
The function prototype defines parameters as pointer to a constant.
Such parameters should not have their content modified in the
function.

Signed-off-by: Laurent Chavey <chavey@google.com>
---
 net/ipv4/netfilter/ipt_ULOG.c |    6 ++++--
 net/netfilter/xt_time.c       |    6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index d32cc4b..8490f9f 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -166,6 +166,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
 	size_t size, copy_len;
 	struct nlmsghdr *nlh;
 	struct timeval tv;
+	ktime_t	tstamp;
 
 	/* ffs == find first bit set, necessary because userspace
 	 * is already shifting groupnumber, but we need unshifted.
@@ -208,13 +209,14 @@ static void ipt_ulog_packet(unsigned int hooknum,
 
 	pm = NLMSG_DATA(nlh);
 
+	tstamp = skb->tstamp;
 	/* We might not have a timestamp, get one */
 	if (skb->tstamp.tv64 == 0)
-		__net_timestamp((struct sk_buff *)skb);
+		tstamp = ktime_get_real();
 
 	/* copy hook, prefix, timestamp, payload, etc. */
 	pm->data_len = copy_len;
-	tv = ktime_to_timeval(skb->tstamp);
+	tv = ktime_to_timeval(tstamp);
 	put_unaligned(tv.tv_sec, &pm->timestamp_sec);
 	put_unaligned(tv.tv_usec, &pm->timestamp_usec);
 	put_unaligned(skb->mark, &pm->mark);
diff --git a/net/netfilter/xt_time.c b/net/netfilter/xt_time.c
index 93acaa5..66e2a75 100644
--- a/net/netfilter/xt_time.c
+++ b/net/netfilter/xt_time.c
@@ -159,6 +159,7 @@ time_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 	unsigned int packet_time;
 	struct xtm current_time;
 	s64 stamp;
+	ktime_t	tstamp;
 
 	/*
 	 * We cannot use get_seconds() instead of __net_timestamp() here.
@@ -169,10 +170,11 @@ time_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 	 * may happen that the same packet matches both rules if
 	 * it arrived at the right moment before 13:00.
 	 */
+	tstamp = skb->tstamp;
 	if (skb->tstamp.tv64 == 0)
-		__net_timestamp((struct sk_buff *)skb);
+		tstamp = ktime_get_real();
 
-	stamp = ktime_to_ns(skb->tstamp);
+	stamp = ktime_to_ns(tstamp);
 	stamp = div_s64(stamp, NSEC_PER_SEC);
 
 	if (info->flags & XT_TIME_LOCAL_TZ)

^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [PATCH] netfilter: Fix compiler warning.
@ 2009-12-10 21:44 chavey
  2009-12-10 22:06 ` Jan Engelhardt
  2009-12-10 22:13 ` Andrew Morton
  0 siblings, 2 replies; 14+ messages in thread
From: chavey @ 2009-12-10 21:44 UTC (permalink / raw)
  To: davem; +Cc: netdev, netfilter-devel, chavey, eric.dumazet, akpm

Fix compiler warning "discards qualifiers from pointer target type",
by allowing explicit discard of const qualifier thru type casting.
The const_cast() macro is taken from a patch from Kaveh R. Ghazi
[PATCH]: Fix problematic -Wcast-qual cases using new CONST_CAST macro
posted on 
http://old.nabble.com/-PATCH-:-Fix-problematic--Wcast-qual-cases-using-new-CONST_CAST--macro-td11824676.html
The proposed __nowarn__ keyword has not yet been implemented, 
(see http://gcc.gnu.org/ml/gcc-patches/2009-11/msg01261.html).


Signed-off-by: Laurent Chavey <chavey@google.com>
---
 include/linux/kernel.h        |   12 ++++++++++++
 net/ipv4/netfilter/ipt_ULOG.c |    2 +-
 net/netfilter/xt_time.c       |    2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3fa4c59..0246771 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -710,4 +710,16 @@ struct sysinfo {
 # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
 #endif
 
+/* Cast away const-ness to pass -Wcast-qual */
+#ifdef __GNUC__
+union gcc_constcast
+{
+	const void *cv;
+	void *v;
+};
+#define const_cast(X) ((__extension__(union gcc_constcast)(const void *)(X)).v)
+#else
+#define const_cast(X) ((void *)(X))
+#endif
+
 #endif
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index d32cc4b..c8f8b8b 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -210,7 +210,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
 
 	/* We might not have a timestamp, get one */
 	if (skb->tstamp.tv64 == 0)
-		__net_timestamp((struct sk_buff *)skb);
+		__net_timestamp((struct sk_buff *)const_cast(skb));
 
 	/* copy hook, prefix, timestamp, payload, etc. */
 	pm->data_len = copy_len;
diff --git a/net/netfilter/xt_time.c b/net/netfilter/xt_time.c
index 93acaa5..8f34a4a 100644
--- a/net/netfilter/xt_time.c
+++ b/net/netfilter/xt_time.c
@@ -170,7 +170,7 @@ time_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 	 * it arrived at the right moment before 13:00.
 	 */
 	if (skb->tstamp.tv64 == 0)
-		__net_timestamp((struct sk_buff *)skb);
+		__net_timestamp((struct sk_buff *)const_cast(skb));
 
 	stamp = ktime_to_ns(skb->tstamp);
 	stamp = div_s64(stamp, NSEC_PER_SEC);

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

end of thread, other threads:[~2009-12-14 13:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-10  1:25 [PATCH] netfilter: Fix compiler warning chavey
2009-12-10  2:07 ` David Miller
2009-12-10  4:25 ` Eric Dumazet
2009-12-10 11:26   ` Patrick McHardy
2009-12-10 17:50   ` Laurent Chavey
2009-12-10 18:53     ` Jan Engelhardt
2009-12-10 19:31       ` Eric Dumazet
  -- strict thread matches above, loose matches on Subject: below --
2009-12-10 21:44 chavey
2009-12-10 22:06 ` Jan Engelhardt
2009-12-10 22:08   ` David Miller
2009-12-10 23:23     ` Jan Engelhardt
2009-12-10 23:44     ` Jan Engelhardt
2009-12-14 13:20       ` Patrick McHardy
2009-12-10 22:13 ` Andrew Morton

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).