misc: fastrpc: Fix device_open when no session is available
authorThierry Escande <thierry.escande@linaro.org>
Fri, 15 Feb 2019 10:40:07 +0000 (10:40 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Feb 2019 13:50:11 +0000 (14:50 +0100)
This change fixes fastrpc_device_open() when no session is available and
return an error in such case.

Signed-off-by: Thierry Escande <thierry.escande@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/fastrpc.c

index 4b0db33..89aec17 100644 (file)
@@ -1016,10 +1016,19 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)
        INIT_LIST_HEAD(&fl->user);
        fl->tgid = current->tgid;
        fl->cctx = cctx;
+
+       fl->sctx = fastrpc_session_alloc(cctx);
+       if (!fl->sctx) {
+               dev_err(&cctx->rpdev->dev, "No session available\n");
+               mutex_destroy(&fl->mutex);
+               kfree(fl);
+
+               return -EBUSY;
+       }
+
        spin_lock(&cctx->lock);
        list_add_tail(&fl->user, &cctx->users);
        spin_unlock(&cctx->lock);
-       fl->sctx = fastrpc_session_alloc(cctx);
 
        return 0;
 }