Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp385067yba; Thu, 18 Apr 2019 03:01:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaFCnlfv2X26T33jupjkbclRBGbbo31NizvpsK5MBFHCYIVslbs6baY+80PIdvHWcAnMki X-Received: by 2002:a65:6148:: with SMTP id o8mr88848842pgv.153.1555581700438; Thu, 18 Apr 2019 03:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555581700; cv=none; d=google.com; s=arc-20160816; b=GE8hpulw0qB3iFhh5G8/bzbv2xJqzli3yeyWJZChOAdFL3AAlrcKECWxCWNDsbOm+p Uux3IloDkk4z7v34cjTEz0mruLZIN5E2nTQtrXrg0LE/wVUn0HHTbMWdermxdWRO7h9g tjTEOzTNsq1YF3WqQBCxFpiFSVrVsZ7sA5yPW5NVIWFfvqnWn15d0DBbxTMdHZxV+1Ny HQbtL2BDjEB2HPeMsroNOVUPho0TVb4nXMkF1jqDWEC8jPK1JiFwsao7Gmk5jmg6eVCG XsD5G1qkxT1L5pWiHJ2cUy7aTyg5dghHc9a0YJb3g5tGohRoOKepICZslx6TLoFMBGi3 8ZYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=Pu2Zhgf6gkG8qDoNXWyoJs0tptuybsZ0yP0av7Zrj4A=; b=AScFCm1fFnn0sVtUT3RNg7qzyNF+1aP9ARJvgOeT7viNDfGBHSprmqfXO9dW4hIiyv sDkO+eETeolnFnaOxdJsWhsoJXNC2ORIxN7VYhH4g7ODBfgJirL5lqfxblDuDCrhaF/M oauC0dzTUFmPMUq2KbT62SlDUBIZ23n/xUWcI+Lx+ULxG5EF7Zrh+ti7F9wL/Dm4uqf+ jG8imkRlPJ6T7kiR4Of1l6HbilIL5dsJ1qP1v+jBNut8BXXpHnthBNWDYIk/viHzrtIj o7zN47hJ3TFoTeBs9LSrAZskuaffSO1f/nLvE7QWEPsfHZLQ5d9AoS1uUqsmpWrlYlh+ IsBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 98si1755223plb.84.2019.04.18.03.01.25; Thu, 18 Apr 2019 03:01:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388468AbfDRKAa (ORCPT + 99 others); Thu, 18 Apr 2019 06:00:30 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:35670 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733049AbfDRKAa (ORCPT ); Thu, 18 Apr 2019 06:00:30 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 0AF69772A36535CE5C0A; Thu, 18 Apr 2019 18:00:28 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.408.0; Thu, 18 Apr 2019 18:00:17 +0800 From: Zhou Wang To: , CC: , , Zhou Wang Subject: [PATCH] lib: scatterlist: Fix to support no mapped sg Date: Thu, 18 Apr 2019 17:50:06 +0800 Message-ID: <1555581006-153458-1-git-send-email-wangzhou1@hisilicon.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In function sg_split, the second sg_calculate_split will return -EINVAL when in_mapped_nents is 0. Indeed there is no need to do second sg_calculate_split and sg_split_mapped when in_mapped_nents is 0, as in_mapped_nents indicates no mapped entry in original sgl. Signed-off-by: Zhou Wang --- lib/sg_split.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/sg_split.c b/lib/sg_split.c index b063410..d4181c8 100644 --- a/lib/sg_split.c +++ b/lib/sg_split.c @@ -178,11 +178,13 @@ int sg_split(struct scatterlist *in, const int in_mapped_nents, * The order of these 3 calls is important and should be kept. */ sg_split_phys(splitters, nb_splits); - ret = sg_calculate_split(in, in_mapped_nents, nb_splits, skip, - split_sizes, splitters, true); - if (ret < 0) - goto err; - sg_split_mapped(splitters, nb_splits); + if (in_mapped_nents) { + ret = sg_calculate_split(in, in_mapped_nents, nb_splits, skip, + split_sizes, splitters, true); + if (ret < 0) + goto err; + sg_split_mapped(splitters, nb_splits); + } for (i = 0; i < nb_splits; i++) { out[i] = splitters[i].out_sg; -- 2.8.1