netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code
@ 2015-06-25  9:03 Maciej Żenczykowski
  2015-06-25  9:03 ` [PATCH 2/2] iproute2: misc/ss.c - fix run_ssfilter af_packet when protocol == 0 Maciej Żenczykowski
  2015-06-25 12:54 ` [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Maciej Żenczykowski @ 2015-06-25  9:03 UTC (permalink / raw)
  To: Maciej Żenczykowski, Stephen Hemminger, Eric Dumazet; +Cc: netdev

From: Maciej Żenczykowski <maze@google.com>

The initializers are simply not needed.

These if-blocks are outright dead code, because '0 > unsigned' is always
false, so only else clause triggers and regardless of which clause triggers
it only updates 'ind' which is later unconditionally written to before
being used anyway.

Otherwise we get errors from clang:

  m_pedit.c:166:8: error: comparison of 0 > unsigned expression is always false [-Werror,-Wtautological-compare]
    if (0 > tkey->off) {
        ~ ^ ~~~~~~~~~
  m_pedit.c:209:8: error: comparison of 0 > unsigned expression is always false [-Werror,-Wtautological-compare]
    if (0 > tkey->off) {
        ~ ^ ~~~~~~~~~
  2 errors generated.

Change-Id: I3c9e9092915088fc56f992e5df736851541a4458
---
 tc/m_pedit.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/tc/m_pedit.c b/tc/m_pedit.c
index dfe9b2ebd6e0..4fdd189d7d9c 100644
--- a/tc/m_pedit.c
+++ b/tc/m_pedit.c
@@ -160,17 +160,9 @@ pack_key32(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 int
 pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
-	int ind = 0, stride = 0;
+	int ind, stride;
 	__u32 m[4] = {0xFFFF0000,0xFF0000FF,0x0000FFFF};
 
-	if (0 > tkey->off) {
-		ind = tkey->off + 1;
-		if (0 > ind)
-			ind = -1*ind;
-	} else {
-		ind = tkey->off;
-	}
-
 	if (tkey->val > 0xFFFF || tkey->mask > 0xFFFF) {
 		fprintf(stderr, "pack_key16 bad value\n");
 		return -1;
@@ -178,18 +170,16 @@ pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 
 	ind = tkey->off & 3;
 
-	if (0 > ind || 2 < ind) {
+	if (ind == 3) {
 		fprintf(stderr, "pack_key16 bad index value %d\n",ind);
 		return -1;
 	}
 
 	stride = 8 * ind;
 	tkey->val = htons(tkey->val);
-	if (stride > 0) {
-		tkey->val <<= stride;
-		tkey->mask <<= stride;
-		retain <<= stride;
-	}
+	tkey->val <<= stride;
+	tkey->mask <<= stride;
+	retain <<= stride;
 	tkey->mask = retain|m[ind];
 
 	tkey->off &= ~3;
@@ -203,28 +193,22 @@ pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 int
 pack_key8(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
 {
-	int ind = 0, stride = 0;
+	int ind, stride;
 	__u32 m[4] = {0xFFFFFF00,0xFFFF00FF,0xFF00FFFF,0x00FFFFFF};
 
-	if (0 > tkey->off) {
-		ind = tkey->off + 1;
-		if (0 > ind)
-			ind = -1*ind;
-	} else {
-		ind = tkey->off;
-	}
-
 	if (tkey->val > 0xFF || tkey->mask > 0xFF) {
 		fprintf(stderr, "pack_key8 bad value (val %x mask %x\n", tkey->val, tkey->mask);
 		return -1;
 	}
 
 	ind = tkey->off & 3;
+
 	stride = 8 * ind;
 	tkey->val <<= stride;
 	tkey->mask <<= stride;
 	retain <<= stride;
 	tkey->mask = retain|m[ind];
+
 	tkey->off &= ~3;
 
 	if (pedit_debug)
-- 
2.4.3.573.g4eafbef

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

* [PATCH 2/2] iproute2: misc/ss.c - fix run_ssfilter af_packet when protocol == 0
  2015-06-25  9:03 [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code Maciej Żenczykowski
@ 2015-06-25  9:03 ` Maciej Żenczykowski
  2015-06-25 12:54 ` [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Maciej Żenczykowski @ 2015-06-25  9:03 UTC (permalink / raw)
  To: Maciej Żenczykowski, Stephen Hemminger, Eric Dumazet; +Cc: netdev

From: Maciej Żenczykowski <maze@google.com>

s->local.data is a pointer to a field of a non-NULL struct, and hence
cannot be NULL, thus comparing it to 0 is always false, and thus the
return is always false.

Presumably this was meant to be a check whether s->local.data[0] (which
I believe stores af_packet protocol) is 0, ie. ANY.

Change-Id: Ia232f5b06ce081e3b2fb6338f1a709cd94e03ae5
Fixes:
  ss.c:1018:37: error: comparison of array 's->local.data' equal to a null pointer is always false [-Werror,-Wtautological-pointer-compare]
    return s->lport == 0 && s->local.data == 0;
                            ~~~~~~~~~^~~~    ~
  1 error generated.
---
 misc/ss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index dba0901791c7..36b0efdfd32f 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1090,7 +1090,7 @@ static int run_ssfilter(struct ssfilter *f, struct sockstat *s)
 					     strspn(p+1, "0123456789abcdef") == 5);
 		}
 		if (s->local.family == AF_PACKET)
-			return s->lport == 0 && s->local.data == 0;
+			return s->lport == 0 && s->local.data[0] == 0;
 		if (s->local.family == AF_NETLINK)
 			return s->lport < 0;
 
-- 
2.4.3.573.g4eafbef

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

* Re: [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code
  2015-06-25  9:03 [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code Maciej Żenczykowski
  2015-06-25  9:03 ` [PATCH 2/2] iproute2: misc/ss.c - fix run_ssfilter af_packet when protocol == 0 Maciej Żenczykowski
@ 2015-06-25 12:54 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2015-06-25 12:54 UTC (permalink / raw)
  To: Maciej Żenczykowski; +Cc: Maciej Żenczykowski, Eric Dumazet, netdev

On Thu, 25 Jun 2015 02:03:02 -0700
Maciej Żenczykowski <zenczykowski@gmail.com> wrote:

> From: Maciej Żenczykowski <maze@google.com>
> 
> The initializers are simply not needed.
> 
> These if-blocks are outright dead code, because '0 > unsigned' is always
> false, so only else clause triggers and regardless of which clause triggers
> it only updates 'ind' which is later unconditionally written to before
> being used anyway.
> 
> Otherwise we get errors from clang:
> 
>   m_pedit.c:166:8: error: comparison of 0 > unsigned expression is always false [-Werror,-Wtautological-compare]
>     if (0 > tkey->off) {
>         ~ ^ ~~~~~~~~~
>   m_pedit.c:209:8: error: comparison of 0 > unsigned expression is always false [-Werror,-Wtautological-compare]
>     if (0 > tkey->off) {
>         ~ ^ ~~~~~~~~~
>   2 errors generated.
> 
> Change-Id: I3c9e9092915088fc56f992e5df736851541a4458
> ---
>  tc/m_pedit.c | 32 ++++++++------------------------
>  1 file changed, 8 insertions(+), 24 deletions(-)

Both applied

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

end of thread, other threads:[~2015-06-25 12:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-25  9:03 [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code Maciej Żenczykowski
2015-06-25  9:03 ` [PATCH 2/2] iproute2: misc/ss.c - fix run_ssfilter af_packet when protocol == 0 Maciej Żenczykowski
2015-06-25 12:54 ` [PATCH 1/2] iproute2: tc/m_pedit.c - remove dead code Stephen Hemminger

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