diff mbox series

[net-next] IB/hfi1: removed shadowed 'err' variable

Message ID 20190710130802.1878874-1-arnd@arndb.de
State New
Headers show
Series [net-next] IB/hfi1: removed shadowed 'err' variable | expand

Commit Message

Arnd Bergmann July 10, 2019, 1:07 p.m. UTC
As clang reports, rvt_create_cq() may return an uninitialized
variable, because the 'err' variable is shadowed by another
local declaration:

drivers/infiniband/sw/rdmavt/cq.c:260:7: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                if (err)
                    ^~~
drivers/infiniband/sw/rdmavt/cq.c:310:9: note: uninitialized use occurs here
        return err;
               ^~~
drivers/infiniband/sw/rdmavt/cq.c:260:3: note: remove the 'if' if its condition is always false
                if (err)
                ^~~~~~~~
drivers/infiniband/sw/rdmavt/cq.c:253:7: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                if (!cq->ip) {
                    ^~~~~~~
drivers/infiniband/sw/rdmavt/cq.c:310:9: note: uninitialized use occurs here
        return err;
               ^~~
drivers/infiniband/sw/rdmavt/cq.c:253:3: note: remove the 'if' if its condition is always false
                if (!cq->ip) {
                ^~~~~~~~~~~~~~
drivers/infiniband/sw/rdmavt/cq.c:211:9: note: initialize the variable 'err' to silence this warning
        int err;
               ^
                = 0

I can't think of any reason for the inner variable declaration, so
remove it to avoid the issue.

Fixes: 239b0e52d8aa ("IB/hfi1: Move rvt_cq_wc struct into uapi directory")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
 drivers/infiniband/sw/rdmavt/cq.c | 2 --
 1 file changed, 2 deletions(-)

-- 
2.20.0

Comments

Marciniszyn, Mike July 10, 2019, 4:54 p.m. UTC | #1
> Subject: [PATCH] [net-next] IB/hfi1: removed shadowed 'err' variable

> 

> I can't think of any reason for the inner variable declaration, so

> remove it to avoid the issue.

> 


I agree!

> Fixes: 239b0e52d8aa ("IB/hfi1: Move rvt_cq_wc struct into uapi directory")


Thanks for catching this!

Acked-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Jason Gunthorpe July 10, 2019, 4:58 p.m. UTC | #2
On Wed, Jul 10, 2019 at 04:54:33PM +0000, Marciniszyn, Mike wrote:
> > Subject: [PATCH] [net-next] IB/hfi1: removed shadowed 'err' variable

> > 

> > I can't think of any reason for the inner variable declaration, so

> > remove it to avoid the issue.

> > 

> 

> I agree!

> 

> > Fixes: 239b0e52d8aa ("IB/hfi1: Move rvt_cq_wc struct into uapi directory")

> 

> Thanks for catching this!

> 

> Acked-by: Mike Marciniszyn <mike.marciniszyn@intel.com>


Thanks, I'm going to take Nathan's identical patch though, it arrived
first

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rdmavt/cq.c b/drivers/infiniband/sw/rdmavt/cq.c
index fac87b13329d..a85571a4cf57 100644
--- a/drivers/infiniband/sw/rdmavt/cq.c
+++ b/drivers/infiniband/sw/rdmavt/cq.c
@@ -247,8 +247,6 @@  int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
 	 * See rvt_mmap() for details.
 	 */
 	if (udata && udata->outlen >= sizeof(__u64)) {
-		int err;
-
 		cq->ip = rvt_create_mmap_info(rdi, sz, udata, u_wc);
 		if (!cq->ip) {
 			err = -ENOMEM;