2008-07-21 07:57:20

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/7] drivers/infiniband: Release mutex in error handling code

From: Julia Lawall <[email protected]>

The mutex is released on a successful return, so it would seem that it
should be released on an error return as well.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
expression l;
@@

mutex_lock(l);
... when != mutex_unlock(l)
when any
when strict
(
if (...) { ... when != mutex_unlock(l)
+ mutex_unlock(l);
return ...;
}
|
mutex_unlock(l);
)
// </smpl>

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

---
diff -u -p a/drivers/infiniband/hw/ehca/ipz_pt_fn.c b/drivers/infiniband/hw/ehca/ipz_pt_fn.c
--- a/drivers/infiniband/hw/ehca/ipz_pt_fn.c
+++ b/drivers/infiniband/hw/ehca/ipz_pt_fn.c
@@ -163,6 +163,7 @@ static int alloc_small_queue_page(struct

out:
ehca_err(pd->ib_pd.device, "failed to allocate small queue page");
+ mutex_unlock(&pd->lock);
return 0;
}


2008-07-21 16:25:24

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH 1/7] drivers/infiniband: Release mutex in error handling code

> --- a/drivers/infiniband/hw/ehca/ipz_pt_fn.c
> +++ b/drivers/infiniband/hw/ehca/ipz_pt_fn.c
> @@ -163,6 +163,7 @@ static int alloc_small_queue_page(struct
>
> out:
> ehca_err(pd->ib_pd.device, "failed to allocate small queue page");
> + mutex_unlock(&pd->lock);
> return 0;
> }

Thanks, looks obviously correct. ehca guys, I will queue this for my
next pull request to Linus; please let me know if you see a problem and
want me to drop it.

- R.

2008-07-21 18:30:27

by Hoang-Nam Nguyen

[permalink] [raw]
Subject: Re: [PATCH 1/7] drivers/infiniband: Release mutex in error handling code

Roland and Julia,
Looks good to me. Thanks for pointing this out.
Nam

Roland Dreier <[email protected]> wrote on 21.07.2008 18:25:07:

> > --- a/drivers/infiniband/hw/ehca/ipz_pt_fn.c
> > +++ b/drivers/infiniband/hw/ehca/ipz_pt_fn.c
> > @@ -163,6 +163,7 @@ static int alloc_small_queue_page(struct
> >
> > out:
> > ehca_err(pd->ib_pd.device, "failed to allocate small queue page");
> > + mutex_unlock(&pd->lock);
> > return 0;
> > }
>
> Thanks, looks obviously correct. ehca guys, I will queue this for my
> next pull request to Linus; please let me know if you see a problem and
> want me to drop it.
>
> - R.