From patchwork Mon Aug 9 03:09:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12425267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA910C432BE for ; Mon, 9 Aug 2021 02:58:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 945FB60FD8 for ; Mon, 9 Aug 2021 02:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232742AbhHIC7J (ORCPT ); Sun, 8 Aug 2021 22:59:09 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:8381 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231675AbhHIC7H (ORCPT ); Sun, 8 Aug 2021 22:59:07 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Gjgff5pbQz84Xj; Mon, 9 Aug 2021 10:54:50 +0800 (CST) Received: from dggema762-chm.china.huawei.com (10.1.198.204) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 9 Aug 2021 10:58:45 +0800 Received: from huawei.com (10.175.127.227) by dggema762-chm.china.huawei.com (10.1.198.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 9 Aug 2021 10:58:45 +0800 From: Yu Kuai To: , , , CC: , , , , Subject: [PATCH v2 2/2] nbd: convert to use blk_mq_get_rq_by_tag() Date: Mon, 9 Aug 2021 11:09:27 +0800 Message-ID: <20210809030927.1946162-3-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809030927.1946162-1-yukuai3@huawei.com> References: <20210809030927.1946162-1-yukuai3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggema762-chm.china.huawei.com (10.1.198.204) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org blk_mq_tag_to_rq() might return freed request, use blk_mq_get_rq_by_tag() instead. Signed-off-by: Yu Kuai --- drivers/block/nbd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index c38317979f74..9e56975a8eee 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -713,11 +713,10 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index) tag = nbd_handle_to_tag(handle); hwq = blk_mq_unique_tag_to_hwq(tag); if (hwq < nbd->tag_set.nr_hw_queues) - req = blk_mq_tag_to_rq(nbd->tag_set.tags[hwq], - blk_mq_unique_tag_to_tag(tag)); - if (!req || !blk_mq_request_started(req)) { - dev_err(disk_to_dev(nbd->disk), "Unexpected reply (%d) %p\n", - tag, req); + req = blk_mq_get_rq_by_tag(nbd->tag_set.tags[hwq], + blk_mq_unique_tag_to_tag(tag)); + if (!req) { + dev_err(disk_to_dev(nbd->disk), "Unexpected reply %d\n", tag); return ERR_PTR(-ENOENT); } trace_nbd_header_received(req, handle); @@ -779,6 +778,8 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index) } out: trace_nbd_payload_received(req, handle); + if (req) + blk_mq_put_rq_ref(req); mutex_unlock(&cmd->lock); return ret ? ERR_PTR(ret) : cmd; }