Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9058053ybi; Tue, 23 Jul 2019 20:59:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBKT1hRR9PEWWDUEHwGdRcDvwIvx2FACnyfzjznWuTEjJvDAQonm4G59kRf1RfVeP5GJb6 X-Received: by 2002:a63:9dcb:: with SMTP id i194mr34035960pgd.444.1563940758710; Tue, 23 Jul 2019 20:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563940758; cv=none; d=google.com; s=arc-20160816; b=XXlJ4HI09gG2Br33lc8tgYH+hoEJsWpHXu2Ac/xBmoyqwlDq8oqD4Tv7IGyBkEzkA9 sQPjASxM8ATt2w6x7S/ThmL7K/IRd70HGF68aY9wAseRI0MfLDyg1XAHnCMn3g/Ae0/D sr4TjDkWZBguAXle/AFsLCT3JFX4T1UwSvQEmw33YfdPeqIGiWETVRGKd8Yg3s68oSRM 2FHlxWZ0BWEe4U3mWim5MX8QBdT/IfRCvvyhBgVP1y+ScL2FevSheKKrxfufT/+3Vgk/ V6HF/jZJ8sGu4/gwfBs0c2F8YqqSNWwo1TiGUtVoVg54ktSGNKyqRom6WIHxadznOLvQ jhCQ== 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=2dg8T0+GPML+1BICuT4M6Q8/TeE7ra3Jpcgm1/JRZ+w=; b=AUkENsvFZ/McIuM0IRRrF12I+55W5qNRNFA1qxd5rOu3c4El7I3qzW0N5WNLZyBbkw UfWwN16gbxBbdQkDRzpe2ohZghmbEHjfrk9h1xMHQbq128KKbzGbo8tnjFLTKDFZBRVO MIwggfeHTfuovHu1ihZyZZuEyefw+wDzc62wa0zzcX+lw4vsvOA066Tah5CPY7cu5coS bB9vu3SwmoU3aLxntTcxuHZZWj7EGYWxxHNfyXT22qZtQW1eiPDHb9dJP7lfAwstiPnm BFLaPh43dcPW/eWmY2f+bKICkhajD93pQU4Y1MJbY0nSLMZ3UOcPROx1UMR1dMXqEkev hJjQ== 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 i10si15590624pfr.130.2019.07.23.20.59.04; Tue, 23 Jul 2019 20:59:18 -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 S1726535AbfGXD5r (ORCPT + 99 others); Tue, 23 Jul 2019 23:57:47 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2745 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725855AbfGXD5r (ORCPT ); Tue, 23 Jul 2019 23:57:47 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id CEE496E40C58B4D5EB37; Wed, 24 Jul 2019 11:57:45 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Wed, 24 Jul 2019 11:57:39 +0800 From: Zhou Wang To: , CC: , , Zhou Wang Subject: [PATCH resend v2] lib: scatterlist: Fix to support no mapped sg Date: Wed, 24 Jul 2019 11:54:23 +0800 Message-ID: <1563940463-95597-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 Acked-by: Robert Jarzmik --- v2: Just add Acked-by from Robert. 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 9982c63..60a0bab 100644 --- a/lib/sg_split.c +++ b/lib/sg_split.c @@ -176,11 +176,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