From 4f47c066c9931880e814b29d2b7809ec8e06baaf Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Tue, 12 Jun 2018 10:42:01 +0800 Subject: [PATCH] iscsi initiator: remove the deleted variable. I do not think that this variable is needed. The rpc system will be always executed in the first call, so there is no sync issue, add a deleted variable and put the free in the loop sounds not very clear. For the ASAN issue (use req after free), I think that the correct solution is that: we should store the context first instead of defer the free of req. Change-Id: I49ca2708ddc2c5533bb3a0aee4622ae23bfe47c6 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/414726 Reviewed-by: Shuhei Matsumoto Tested-by: SPDK Automated Test System --- lib/bdev/iscsi/bdev_iscsi.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/bdev/iscsi/bdev_iscsi.c b/lib/bdev/iscsi/bdev_iscsi.c index a41514d243..2cefb7f4b4 100644 --- a/lib/bdev/iscsi/bdev_iscsi.c +++ b/lib/bdev/iscsi/bdev_iscsi.c @@ -100,7 +100,6 @@ struct bdev_iscsi_conn_req { spdk_bdev_iscsi_create_cb create_cb; spdk_bdev_iscsi_create_cb create_cb_arg; TAILQ_ENTRY(bdev_iscsi_conn_req) link; - bool deleted; }; static int @@ -537,7 +536,7 @@ complete_conn_req(struct bdev_iscsi_conn_req *req, struct spdk_bdev *bdev, { TAILQ_REMOVE(&g_iscsi_conn_req, req, link); req->create_cb(req->create_cb_arg, bdev, status); - req->deleted = true; + free(req); } static int @@ -646,10 +645,12 @@ iscsi_bdev_conn_poll(void *arg) { struct bdev_iscsi_conn_req *req, *tmp; struct pollfd pfd; + struct iscsi_context *context; TAILQ_FOREACH_SAFE(req, &g_iscsi_conn_req, link, tmp) { - pfd.fd = iscsi_get_fd(req->context); - pfd.events = iscsi_which_events(req->context); + context = req->context; + pfd.fd = iscsi_get_fd(context); + pfd.events = iscsi_which_events(context); pfd.revents = 0; if (poll(&pfd, 1, 0) < 0) { SPDK_ERRLOG("poll failed\n"); @@ -657,14 +658,10 @@ iscsi_bdev_conn_poll(void *arg) } if (pfd.revents != 0) { - if (iscsi_service(req->context, pfd.revents) < 0) { - SPDK_ERRLOG("iscsi_service failed: %s\n", iscsi_get_error(req->context)); + if (iscsi_service(context, pfd.revents) < 0) { + SPDK_ERRLOG("iscsi_service failed: %s\n", iscsi_get_error(context)); } } - - if (req->deleted) { - free(req); - } } return -1;