2015-12-19 21:01:42

by Julia Lawall

[permalink] [raw]
Subject: [PATCH] IB/usnic: delete unneeded IS_ERR test

kzalloc doesn't return ERR_PTR, so there is no need to test for it.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,e;
@@

* x = kzalloc(...)
... when != x = e
* IS_ERR_OR_NULL(x)
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c
index f8e3211..20f53e5 100644
--- a/drivers/infiniband/hw/usnic/usnic_ib_verbs.c
+++ b/drivers/infiniband/hw/usnic/usnic_ib_verbs.c
@@ -625,8 +625,8 @@ struct ib_mr *usnic_ib_reg_mr(struct ib_pd *pd, u64 start, u64 length,
virt_addr, length);

mr = kzalloc(sizeof(*mr), GFP_KERNEL);
- if (IS_ERR_OR_NULL(mr))
- return ERR_PTR(mr ? PTR_ERR(mr) : -ENOMEM);
+ if (!mr)
+ return ERR_PTR(-ENOMEM);

mr->umem = usnic_uiom_reg_get(to_upd(pd)->umem_pd, start, length,
access_flags, 0);


2015-12-22 15:38:45

by Dave Goodell

[permalink] [raw]
Subject: Re: [PATCH] IB/usnic: delete unneeded IS_ERR test

[copying Nelson too]

On Sat, Dec 19, 2015 at 09:48:59PM +0100, Julia Lawall wrote:
> kzalloc doesn't return ERR_PTR, so there is no need to test for it.
>
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression x,e;
> @@
>
> * x = kzalloc(...)
> ... when != x = e
> * IS_ERR_OR_NULL(x)
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>

Reviewed-by: Dave Goodell <[email protected]>

-Dave

2015-12-23 16:11:09

by Doug Ledford

[permalink] [raw]
Subject: Re: [PATCH] IB/usnic: delete unneeded IS_ERR test

On 12/22/2015 10:29 AM, Dave Goodell wrote:
> [copying Nelson too]
>
> On Sat, Dec 19, 2015 at 09:48:59PM +0100, Julia Lawall wrote:
>> kzalloc doesn't return ERR_PTR, so there is no need to test for it.
>>
>> The semantic match that finds this problem is as follows:
>> (http://coccinelle.lip6.fr/)
>>
>> // <smpl>
>> @@
>> expression x,e;
>> @@
>>
>> * x = kzalloc(...)
>> ... when != x = e
>> * IS_ERR_OR_NULL(x)
>> // </smpl>
>>
>> Signed-off-by: Julia Lawall <[email protected]>
>
> Reviewed-by: Dave Goodell <[email protected]>
>
> -Dave
>

Thanks, applied.

--
Doug Ledford <[email protected]>
GPG KeyID: 0E572FDD



Attachments:
signature.asc (884.00 B)
OpenPGP digital signature