From: Zhu Yanjun <yanjun.zhu@xxxxxxxxx> When dev->refcount is zero, it is not necessary to do others, exit directly. Acked-by: Jack Wang <jinpu.wang@xxxxxxxxx> Signed-off-by: Zhu Yanjun <yanjun.zhu@xxxxxxxxx> --- drivers/block/rnbd/rnbd-clt.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index b0550b68645d..84ddc79fad64 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -463,7 +463,12 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, msg.hdr.type = cpu_to_le16(RNBD_MSG_CLOSE); msg.device_id = cpu_to_le32(device_id); - WARN_ON(!rnbd_clt_get_dev(dev)); + if (WARN_ON(!rnbd_clt_get_dev(dev))) { + rnbd_put_iu(sess, iu); + err = -ENODEV; + goto exit; + } + err = send_usr_msg(sess->rtrs, WRITE, iu, &vec, 0, NULL, 0, msg_close_conf, &errno, wait); if (err) { @@ -472,7 +477,7 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, } else { err = errno; } - +exit: rnbd_put_iu(sess, iu); return err; } @@ -558,7 +563,13 @@ static int send_msg_open(struct rnbd_clt_dev *dev, enum wait_type wait) msg.access_mode = dev->access_mode; strscpy(msg.dev_name, dev->pathname, sizeof(msg.dev_name)); - WARN_ON(!rnbd_clt_get_dev(dev)); + if (WARN_ON(!rnbd_clt_get_dev(dev))) { + rnbd_put_iu(sess, iu); + kfree(rsp); + err = -ENODEV; + goto exit; + } + err = send_usr_msg(sess->rtrs, READ, iu, &vec, sizeof(*rsp), iu->sgt.sgl, 1, msg_open_conf, &errno, wait); @@ -569,7 +580,7 @@ static int send_msg_open(struct rnbd_clt_dev *dev, enum wait_type wait) } else { err = errno; } - +exit: rnbd_put_iu(sess, iu); return err; } @@ -1597,7 +1608,12 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, msg.access_mode = dev->access_mode; strscpy(msg.dev_name, dev->pathname, sizeof(msg.dev_name)); - WARN_ON(!rnbd_clt_get_dev(dev)); + if (WARN_ON(!rnbd_clt_get_dev(dev))) { + rnbd_put_iu(sess, iu); + ret = -ENODEV; + goto put_iu; + } + ret = send_usr_msg(sess->rtrs, READ, iu, &vec, sizeof(*rsp), iu->sgt.sgl, 1, msg_open_conf, &errno, RTRS_PERMIT_WAIT); -- 2.40.1