2020-04-27 10:37:11

by Aishwarya Ramakrishnan

[permalink] [raw]
Subject: [PATCH] dpaa_eth: Fix comparing pointer to 0

Fixes coccicheck warning:
./drivers/net/ethernet/freescale/dpaa/dpaa_eth.c:2110:30-31:
WARNING comparing pointer to 0

Avoid pointer type value compared to 0.

Signed-off-by: Aishwarya Ramakrishnan <[email protected]>
---
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 2cd1f8efdfa3..c4416a5f8816 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -2107,7 +2107,7 @@ static int dpaa_a050385_wa(struct net_device *net_dev, struct sk_buff **s)

/* Workaround for DPAA_A050385 requires data start to be aligned */
start = PTR_ALIGN(new_skb->data, DPAA_A050385_ALIGN);
- if (start - new_skb->data != 0)
+ if (start - new_skb->data)
skb_reserve(new_skb, start - new_skb->data);

skb_put(new_skb, skb->len);
--
2.17.1


2020-04-27 11:28:45

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] dpaa_eth: Fix comparing pointer to 0

> Fixes coccicheck warning:
> ./drivers/net/ethernet/freescale/dpaa/dpaa_eth.c:2110:30-31:
> WARNING comparing pointer to 0

Such information is actually provided by a known script for
the semantic patch language.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/scripts/coccinelle/null/badzero.cocci


> Avoid pointer type value compared to 0.

But I suggest to reconsider corresponding software development consequences
also around mentioned implementation details.



> +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> @@ -2107,7 +2107,7 @@ static int dpaa_a050385_wa(struct net_device *net_dev, struct sk_buff **s)

> start = PTR_ALIGN(new_skb->data, DPAA_A050385_ALIGN);
> - if (start - new_skb->data != 0)
> + if (start - new_skb->data)
> skb_reserve(new_skb, start - new_skb->data);



I interpret the source code in the way that a subtraction is performed
with two pointers. I would expect that such a pointer difference
has got an integral data type.
Will this view trigger any further software evolution?

Regards,
Markus

2020-05-01 03:31:15

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] dpaa_eth: Fix comparing pointer to 0

From: Aishwarya Ramakrishnan <[email protected]>
Date: Mon, 27 Apr 2020 16:02:30 +0530

> Fixes coccicheck warning:
> ./drivers/net/ethernet/freescale/dpaa/dpaa_eth.c:2110:30-31:
> WARNING comparing pointer to 0
>
> Avoid pointer type value compared to 0.
>
> Signed-off-by: Aishwarya Ramakrishnan <[email protected]>

Applied, thanks.