Only allocate priv after session is available. Signed-off-by: Guoqing Jiang <guoqing.jiang@xxxxxxxxx> --- drivers/block/rnbd/rnbd-srv.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index c4122e65b36a..b4c880759a52 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -128,20 +128,17 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, trace_process_rdma(srv_sess, msg, id, datalen, usrlen); - priv = kmalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - dev_id = le32_to_cpu(msg->device_id); - sess_dev = rnbd_get_sess_dev(dev_id, srv_sess); if (IS_ERR(sess_dev)) { pr_err_ratelimited("Got I/O request on session %s for unknown device id %d\n", srv_sess->sessname, dev_id); - err = -ENOTCONN; - goto err; + return -ENOTCONN; } + priv = kmalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; priv->sess_dev = sess_dev; priv->id = id; @@ -169,7 +166,6 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, bio_put: bio_put(bio); rnbd_put_sess_dev(sess_dev); -err: kfree(priv); return err; } -- 2.35.3