Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1239368rwb; Thu, 18 Aug 2022 23:12:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4xfIiUMM4ITPUhiwiXeGNOqxLlsAAJxza6E1fTP70V0I5DQonTTFrIW/jGRWxH5uvvOKTQ X-Received: by 2002:a17:906:9b8b:b0:732:d464:92ea with SMTP id dd11-20020a1709069b8b00b00732d46492eamr3799730ejc.3.1660889522883; Thu, 18 Aug 2022 23:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660889522; cv=none; d=google.com; s=arc-20160816; b=qc1KubaYaOsregXvpbgkMNnqglrdLn7hfcjTHLfgqde6QivPEJ29GipqumRV3DlrOJ vVzHNhq/zhYSemAI6hgIhIa5kMTGf7aQarGFivG7pRATWm7G6CZW7ER7lfN0U7JJT3az b/0FAwawf96yuZeG7nZHKpserR/HQieVTzdZ+vPRCs4Zber8tiWCw1YYfzlR6Nv/dzlP 7CN08i0SssMCenvEol4yWM180OWloAWKDNDIp6Dn6ALgS8bQxn7btupiWkHgNTLjIUjR kgEJ+ikABsfMjsDd24nvTiEjlF82Gl0z2/jPsg9cr97wgeUfsGr83vj5rhLL9jmv/f/u 9Fag== 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=5dgh0mRNVGiAT981rc+BiMLlWYrkrNgUD8IdfprQkqA=; b=MaGfcGcK+BtFj0BnLtZhQUeCpIRU8BwKy8JpMdRd8ZEW9W1CWt7zTIw4acTzMcvaEU UN508O2XeH9qGhBbQstqpP9AGWR26gUckSs4qHgiBffoXGF1nWIGbkHRs+LhPDkyd/cR OL90pcJfPZqhVOpigzAn1tUDmUov1gIyK6AOtwK5AMEn6vSXCzNu8wLamWHd9uyDX4a4 nnmGAncZgERlrNQwFSTLeAarc+e+EqZpjg0lGOhG+rsJ4Mb0/yNrN9rLslMrL7Kf1sia Czkwt6ngdVHt2u56y9hXivRw5d24xl2Vz682kzlfuf0zWwZ7Bcl67gLWKPoF9L2Q1T9v dKCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=W5WMmy+a; 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 d8-20020a1709061f4800b00730a3b5af1fsi2424120ejk.338.2022.08.18.23.11.36; Thu, 18 Aug 2022 23:12:02 -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=W5WMmy+a; 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 S1346776AbiHSGJq (ORCPT + 99 others); Fri, 19 Aug 2022 02:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346595AbiHSGIv (ORCPT ); Fri, 19 Aug 2022 02:08:51 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3D7B356C5 for ; Thu, 18 Aug 2022 23:08:28 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id w19so6977160ejc.7 for ; Thu, 18 Aug 2022 23:08:27 -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=5dgh0mRNVGiAT981rc+BiMLlWYrkrNgUD8IdfprQkqA=; b=W5WMmy+an0THIibSKrr3bcWg4gjuYgGgd72fP/ALycZ+7+Pa0SfJykH8cr7EcbmFhQ azhFHI6OBwkWgPK6ZpMfr9Om11xd/5LqmEKxVhg6en5ryfV3ZPV0QgnB/7UKMtO/gzan Z//ONWSeVL4TaZpjD7YmjJpps5VFk3z3CfxYVx6wMJO+M1Zh3Z8STOFwIoBCOpMHiSjD zkZxUsCZuHqQ59thjGYOvNcdcAZ2nY00mRORym3v7Fjb2NKri7WM4bq1wuFPX9Tcg/3l EkQaSVW96Onm/Rz+9wbCm9GDcPL9ONsaT1bt5Ymm4kl/5J+miqTeNDeNblYHym9NerAd ghVA== 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=5dgh0mRNVGiAT981rc+BiMLlWYrkrNgUD8IdfprQkqA=; b=QM42p8ziDQdn3TUFCAs1aWb4xu0PhHcHXo+7ySATAk5CSVwGhAampnOB50FQLqoDxk xfPULX3jHZ+CXPcyo11oIzsdk8eqN2VGU6DqLfPs9A4tnvCB7ref+Rmv5/uveoiw6kqb vXAah3Fykq8SEMjWjQdZpWbfqL+q4fViqHzS5DEJbUdTgicTN/dx8Gw184AbNe2rUnuV Rf2NS/tVeTR2hBcnFAqY6MCZryC6u2zVTGEGhGYqt2HAQES9nSUOHqN3/DzkPYvRo0l0 d7ZuCi93rs2Jf3rptPl12vDj54rTbwWQGPChby485XQIyy3foBSWS91aTUibAyS7N1nX LjeQ== X-Gm-Message-State: ACgBeo1vQo2TpBYzbLuMidVX0reSTFgxJ0lT+c3sx+rbywj5slRkntB6 ir0g940ZlhTJcIX/5omoL5vu4f7ROeHmv3JO X-Received: by 2002:a17:906:730c:b0:730:da74:3453 with SMTP id di12-20020a170906730c00b00730da743453mr3837859ejc.270.1660889306078; Thu, 18 Aug 2022 23:08:26 -0700 (PDT) Received: from lb02065.fritz.box ([2001:9e8:143b:fd00:5207:8c7f:747a:b80d]) by smtp.gmail.com with ESMTPSA id y14-20020a1709063a8e00b0073a644ef803sm1809660ejd.101.2022.08.18.23.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 23:08:25 -0700 (PDT) From: Jack Wang To: linux-kernel@vger.kernel.org Cc: James Smart , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org Subject: [PATCH v1 15/19] nvme-fc: Fix the error check for dma_map_sg Date: Fri, 19 Aug 2022 08:07:57 +0200 Message-Id: <20220819060801.10443-16-jinpu.wang@ionos.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819060801.10443-1-jinpu.wang@ionos.com> References: <20220819060801.10443-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 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 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