* [PATCH net] net: atm: clean up a range check
@ 2019-05-03 12:39 Dan Carpenter
2019-05-05 17:26 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2019-05-03 12:39 UTC (permalink / raw)
To: David S. Miller
Cc: Gustavo A. R. Silva, David Woodhouse, netdev, kernel-janitors
The code works fine but the problem is that check for negatives is a
no-op:
if (arg < 0)
i = 0;
The "i" value isn't used. We immediately overwrite it with:
i = array_index_nospec(arg, MAX_LEC_ITF);
The array_index_nospec() macro returns zero if "arg" is out of bounds so
this works, but the dead code is confusing and it doesn't look very
intentional.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This applies to net, but it's just a clean up.
net/atm/lec.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/net/atm/lec.c b/net/atm/lec.c
index ad4f829193f0..a0311493b01b 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -726,9 +726,7 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
struct lec_priv *priv;
if (arg < 0)
- i = 0;
- else
- i = arg;
+ arg = 0;
if (arg >= MAX_LEC_ITF)
return -EINVAL;
i = array_index_nospec(arg, MAX_LEC_ITF);
--
2.18.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: atm: clean up a range check
2019-05-03 12:39 [PATCH net] net: atm: clean up a range check Dan Carpenter
@ 2019-05-05 17:26 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-05-05 17:26 UTC (permalink / raw)
To: dan.carpenter; +Cc: gustavo, dwmw2, netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Fri, 3 May 2019 15:39:48 +0300
> The code works fine but the problem is that check for negatives is a
> no-op:
>
> if (arg < 0)
> i = 0;
>
> The "i" value isn't used. We immediately overwrite it with:
>
> i = array_index_nospec(arg, MAX_LEC_ITF);
>
> The array_index_nospec() macro returns zero if "arg" is out of bounds so
> this works, but the dead code is confusing and it doesn't look very
> intentional.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This applies to net, but it's just a clean up.
I'm applying this to net-next, thanks Dan.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-05 17:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-03 12:39 [PATCH net] net: atm: clean up a range check Dan Carpenter
2019-05-05 17:26 ` David Miller
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).