Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp303183rwe; Wed, 24 Aug 2022 23:56:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR4qQaVsVscTA6gjWshkv2FVjRsuZysxEf0qD4s4mKD5S8hlj2HWJfXaGDQdfbEfMn4ausz4 X-Received: by 2002:a17:907:94c6:b0:730:b3a6:d612 with SMTP id dn6-20020a17090794c600b00730b3a6d612mr1653103ejc.28.1661410618563; Wed, 24 Aug 2022 23:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661410618; cv=none; d=google.com; s=arc-20160816; b=GadlaDhaHXBFbCWV6rnbjCW7tooDtLpq+LUIA+cxGZQ1k15yP+8JsgfLyg/5+icrlp XZfqNDlYoFNXd1wE+EgZc5mWvJthUbjiqJ4J8Vxfuw4zNcdqinfn0HTTw5S1iGdXFROM oykcSrDojcXlGiBR97ZbQ1Dy4g1PgQdEY8gwqNLslNoKWTozHFxOLkjRjAo5UN+vXu/X F/7/2wkYb+Cxs8VRDorW6GUxtaPABdtGVRggcB6edd4o3Ara8q9LH+AcVcvVPB3pWyHl aqnGERrg+kOZ7XAmpnJyIw74k6Tn3p8l9eWvGif9VPEowydweooG7HSVoY30wXXSSdjd LipQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WJ7GBNHN6AoVv9ZeH0urLLa0hH2huW2RwMDCHhQJQUs=; b=UawVQes5JMipG9YGBar2y3+9RX4bWDDAN1JA+JFK7cVJwUd2PhS66gLMA2e6mqlnUM yFhhNFI5eIbHhQl3n0WnLnTxJzEYGYiiKGvO6Uoq2hvhjo9gDv/AojuNVfJFTqSswsni mrmO2iTBXwSSDf7PE31q9GpI4PPcuiupOF4Ytv2CUYuiIOF8nnYoPQricakUXi1QcNWB CvePw+iNFyNmi2bNxiDs/Fr3XS8c+7/h+8cIZXuMn9ux9z8FKFZ0i/mzqaitGpbIRV/9 XikUAezO4dWXJG3oucuh2WMYGJc5Lyu76rzBx0OZ9Dk1HU3Y4zP4UhIX4/st2gEFacH2 GIGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="d6bUCj/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ionos.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt8-20020a1709072d8800b0073daf6b44a5si3668766ejc.775.2022.08.24.23.56.30; Wed, 24 Aug 2022 23:56:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="d6bUCj/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ionos.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235750AbiHYGsH (ORCPT + 99 others); Thu, 25 Aug 2022 02:48:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236203AbiHYGr4 (ORCPT ); Thu, 25 Aug 2022 02:47:56 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D3BA0276 for ; Wed, 24 Aug 2022 23:47:52 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id r4so24818937edi.8 for ; Wed, 24 Aug 2022 23:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=WJ7GBNHN6AoVv9ZeH0urLLa0hH2huW2RwMDCHhQJQUs=; b=d6bUCj/UvDMnRfnKyskgkByJo1qmZAo616iARuRQkWWCLeIP4Z9rfvc3DCBpbZsHlP KTxjAxUjNKC0ca6HElPoVtJtqBqYS8+W795nbrRnRSgRys8RpXduYkix1MZcnu6/HioI ocG6YqnD1sOrtdVpTp+mhQXlLHNtQHjayJXjAde8V2kn2GdvtFjivTfNgjaG0kLdRUaH wx0G+FeDpnQLnjj4/YOMxiUMRhzAEL3tpaPXcoRwd5ZoXwAZ9E9qCDfWaZlGBjwmit3B gcCR9kyatFVXcMPA7VQQ61iyOWutwdAvxJgbVLSU6lJ0l9kmlAqQlc3SLcMBTlRMHLOX PpqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=WJ7GBNHN6AoVv9ZeH0urLLa0hH2huW2RwMDCHhQJQUs=; b=JPrVujAE6WbTrA8znLsGp3VcdAgO4siI7flXjPbHpvL0B98UTUpemwpJYnC6dWEOhj wzyfpQE6Cyb98oq2XOXZGAPlCTlcFg7+MvfU9bxEVTJ/ALxjsWl/M8oNsmyp9rwEq7cY SA4oFI2HzM8rpj1WYnzOtdPMuSfqNYerbHWh0MX6xpvUSGgCXGxY+nemq7B3ITojNLLz kkSVo9nRsdQfQHgRrKEev7lpnXHWbgC2fjPS/PXckesrRVcH6Ton4vrR3J785Y8XnJ9G G+M/lwIsh2mMnC/JFwwVCy+nI+W2T6LKMDkcWLMf+rRdok9CZw3E1OUvwmaItrhopgqg D2Og== X-Gm-Message-State: ACgBeo1zrW+1GiBq2vuGJbPo9Aln6wrN5p1U2CuxEk/em81AXa4vT5kZ /2wIMX3I6LrU5kFZ9lnv3+ca5Q== X-Received: by 2002:a05:6402:26d6:b0:447:391:5d32 with SMTP id x22-20020a05640226d600b0044703915d32mr1913796edd.424.1661410070906; Wed, 24 Aug 2022 23:47:50 -0700 (PDT) Received: from lb02065.fritz.box ([2001:9e8:142d:a900:eab:b5b1:a064:1d0d]) by smtp.gmail.com with ESMTPSA id l5-20020a170906a40500b0073100dfa7b0sm2063564ejz.8.2022.08.24.23.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 23:47:50 -0700 (PDT) From: Jack Wang To: hch@infradead.org, axboe@kernel.dk, linux-nvme@lists.infradead.org Cc: James Smart , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] nvme-fc: Fix the error check for dma_map_sg Date: Thu, 25 Aug 2022 08:47:47 +0200 Message-Id: <20220825064747.22521-3-jinpu.wang@ionos.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220825064747.22521-1-jinpu.wang@ionos.com> References: <20220825064747.22521-1-jinpu.wang@ionos.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dma_map_sg return 0 on error, add missing check. Cc: James Smart Cc: Keith Busch Cc: Jens Axboe Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org Fixes: e399441de911 ("nvme-fabrics: Add host support for FC transport") Signed-off-by: Jack Wang --- drivers/nvme/host/fc.c | 2 +- drivers/nvme/target/fc.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 127abaf9ba5d..95050f2e0a06 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -2616,7 +2616,7 @@ nvme_fc_map_data(struct nvme_fc_ctrl *ctrl, struct request *rq, WARN_ON(op->nents > blk_rq_nr_phys_segments(rq)); freq->sg_cnt = fc_dma_map_sg(ctrl->lport->dev, freq->sg_table.sgl, op->nents, rq_dma_dir(rq)); - if (unlikely(freq->sg_cnt <= 0)) { + if (unlikely(!freq->sg_cnt)) { sg_free_table_chained(&freq->sg_table, NVME_INLINE_SG_CNT); freq->sg_cnt = 0; return -EFAULT; diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index ab2627e17bb9..3749ca28860b 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -2089,6 +2089,11 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod) ((fod->io_dir == NVMET_FCP_WRITE) ? DMA_FROM_DEVICE : DMA_TO_DEVICE)); /* note: write from initiator perspective */ + if (!fod->data_sg_cnt) { + sgl_free(fod->data_sg); + fod->data_sg = NULL; + goto out; + } fod->next_sg = fod->data_sg; return 0; -- 2.34.1