Message ID | 20230523075331.32250-6-guoqing.jiang@linux.dev (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | misc patches for rnbd | expand |
On Tue, May 23, 2023 at 9:53 AM Guoqing Jiang <guoqing.jiang@linux.dev> wrote: > > Only allocate priv after session is available. > > Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> > --- > 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; before return you have to rnbd_put_sess_dev! it seems not much benefit with the change. > 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 >
On 5/23/23 17:29, Jinpu Wang wrote: > On Tue, May 23, 2023 at 9:53 AM Guoqing Jiang <guoqing.jiang@linux.dev> wrote: >> Only allocate priv after session is available. >> >> Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> >> --- >> 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; > before return you have to rnbd_put_sess_dev! > it seems not much benefit with the change. You are right, thanks for the review. Guoqing
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; }
Only allocate priv after session is available. Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> --- drivers/block/rnbd/rnbd-srv.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)