diff mbox series

block/rnbd: Fix an IS_ERR() vs NULL check in find_or_create_sess()

Message ID 20200519120347.GD42765@mwanda (mailing list archive)
State New, archived
Headers show
Series block/rnbd: Fix an IS_ERR() vs NULL check in find_or_create_sess() | expand

Commit Message

Dan Carpenter May 19, 2020, 12:03 p.m. UTC
The alloc_sess() function returns error pointers, it never returns NULL.

Fixes: f7a7a5c228d4 ("block/rnbd: client: main functionality")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/block/rnbd/rnbd-clt.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Jinpu Wang May 19, 2020, 12:52 p.m. UTC | #1
On Tue, May 19, 2020 at 2:04 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> The alloc_sess() function returns error pointers, it never returns NULL.
>
> Fixes: f7a7a5c228d4 ("block/rnbd: client: main functionality")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Thanks Dan,
Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>

> ---
>  drivers/block/rnbd/rnbd-clt.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
> index 55bff3b1be71..a033247281da 100644
> --- a/drivers/block/rnbd/rnbd-clt.c
> +++ b/drivers/block/rnbd/rnbd-clt.c
> @@ -923,13 +923,12 @@ rnbd_clt_session *find_or_create_sess(const char *sessname, bool *first)
>         sess = __find_and_get_sess(sessname);
>         if (!sess) {
>                 sess = alloc_sess(sessname);
> -               if (sess) {
> -                       list_add(&sess->list, &sess_list);
> -                       *first = true;
> -               } else {
> +               if (IS_ERR(sess)) {
>                         mutex_unlock(&sess_lock);
> -                       return ERR_PTR(-ENOMEM);
> +                       return sess;
>                 }
> +               list_add(&sess->list, &sess_list);
> +               *first = true;
>         } else
>                 *first = false;
>         mutex_unlock(&sess_lock);
> --
> 2.26.2
>
Jinpu Wang May 22, 2020, 5:13 a.m. UTC | #2
On Tue, May 19, 2020 at 2:52 PM Jinpu Wang <jinpu.wang@cloud.ionos.com> wrote:
>
> On Tue, May 19, 2020 at 2:04 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > The alloc_sess() function returns error pointers, it never returns NULL.
> >
> > Fixes: f7a7a5c228d4 ("block/rnbd: client: main functionality")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Thanks Dan,
> Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>

Hi Jason,

Could you also queue this fix for for-next?

Thanks
Jason Gunthorpe May 22, 2020, 2:48 p.m. UTC | #3
On Fri, May 22, 2020 at 07:13:08AM +0200, Jinpu Wang wrote:
> On Tue, May 19, 2020 at 2:52 PM Jinpu Wang <jinpu.wang@cloud.ionos.com> wrote:
> >
> > On Tue, May 19, 2020 at 2:04 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > >
> > > The alloc_sess() function returns error pointers, it never returns NULL.
> > >
> > > Fixes: f7a7a5c228d4 ("block/rnbd: client: main functionality")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Thanks Dan,
> > Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> 
> Hi Jason,
> 
> Could you also queue this fix for for-next?

Uhh.. Yes OK, but if it doesn't get cc'd to linux-rdma I won't see it..

Please let me know if there are others

Thanks,
Jason
Dan Carpenter May 22, 2020, 3:44 p.m. UTC | #4
On Fri, May 22, 2020 at 11:48:31AM -0300, Jason Gunthorpe wrote:
> On Fri, May 22, 2020 at 07:13:08AM +0200, Jinpu Wang wrote:
> > On Tue, May 19, 2020 at 2:52 PM Jinpu Wang <jinpu.wang@cloud.ionos.com> wrote:
> > >
> > > On Tue, May 19, 2020 at 2:04 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > > >
> > > > The alloc_sess() function returns error pointers, it never returns NULL.
> > > >
> > > > Fixes: f7a7a5c228d4 ("block/rnbd: client: main functionality")
> > > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > Thanks Dan,
> > > Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> > 
> > Hi Jason,
> > 
> > Could you also queue this fix for for-next?
> 
> Uhh.. Yes OK, but if it doesn't get cc'd to linux-rdma I won't see it..
> 

I suspect that we should update MAINTAINERS so that
./scripts/get_maintainer.pl gives the right lists.  Proabably all
drivers/block/rnbd/ patches are supposed to go through you?

regards,
dan carpenter
Jason Gunthorpe May 22, 2020, 4:41 p.m. UTC | #5
On Fri, May 22, 2020 at 06:44:03PM +0300, Dan Carpenter wrote:
> On Fri, May 22, 2020 at 11:48:31AM -0300, Jason Gunthorpe wrote:
> > On Fri, May 22, 2020 at 07:13:08AM +0200, Jinpu Wang wrote:
> > > On Tue, May 19, 2020 at 2:52 PM Jinpu Wang <jinpu.wang@cloud.ionos.com> wrote:
> > > >
> > > > On Tue, May 19, 2020 at 2:04 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > > > >
> > > > > The alloc_sess() function returns error pointers, it never returns NULL.
> > > > >
> > > > > Fixes: f7a7a5c228d4 ("block/rnbd: client: main functionality")
> > > > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > > Thanks Dan,
> > > > Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> > > 
> > > Hi Jason,
> > > 
> > > Could you also queue this fix for for-next?
> > 
> > Uhh.. Yes OK, but if it doesn't get cc'd to linux-rdma I won't see it..
> > 
> 
> I suspect that we should update MAINTAINERS so that
> ./scripts/get_maintainer.pl gives the right lists.  Proabably all
> drivers/block/rnbd/ patches are supposed to go through you?

I think Jens will take then once everything is merged, it is just for
the next few weeks

Jason
diff mbox series

Patch

diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
index 55bff3b1be71..a033247281da 100644
--- a/drivers/block/rnbd/rnbd-clt.c
+++ b/drivers/block/rnbd/rnbd-clt.c
@@ -923,13 +923,12 @@  rnbd_clt_session *find_or_create_sess(const char *sessname, bool *first)
 	sess = __find_and_get_sess(sessname);
 	if (!sess) {
 		sess = alloc_sess(sessname);
-		if (sess) {
-			list_add(&sess->list, &sess_list);
-			*first = true;
-		} else {
+		if (IS_ERR(sess)) {
 			mutex_unlock(&sess_lock);
-			return ERR_PTR(-ENOMEM);
+			return sess;
 		}
+		list_add(&sess->list, &sess_list);
+		*first = true;
 	} else
 		*first = false;
 	mutex_unlock(&sess_lock);