Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp1262554rwa; Sun, 21 Aug 2022 04:56:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7nZWBPMzHNdjHB+HMY+hnkKUpv5eZLGFTMb+3P7pTuxhn5tM6v65udozdj0riVew5a+PrB X-Received: by 2002:a17:907:2bf7:b0:730:996d:5e8d with SMTP id gv55-20020a1709072bf700b00730996d5e8dmr10366186ejc.382.1661082981253; Sun, 21 Aug 2022 04:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661082981; cv=none; d=google.com; s=arc-20160816; b=1D17Vg6BDWJRetTHSouTt2T3oc4CJeWBQKXPZ9c2kdXjDgky6dVV9LeytlVqjRKQxS MraGikLeApwb+rqxqru13VabSnYrnbskrZGlpEzB6/PLBopuRozOWrRQWXQG7+voYe+Z WSrgK1JGGyakXR2XHn9Q+YhFLTVLgOi5cWrcZBy4+008Cbm7Yl/6wkQLMyKWtXEtPkkV kBCunXJR/ulsmD+EHE8Xorw6qZJNSZTDHodjxOlub7IuHKV6wJeldu22k6UJbRW+EBub RlqtcSekXHfnaTCf/CBktnrxqbYJ2tZFnh7MlBmBkG4NLWqmZGDJfDSTGS/qzegWq+5S DiVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7fwcFoS69puoNlKOqzgAZ5VZn5kINGfLmGY1kAuN0QE=; b=QZ7T17v7UXVREqg+bO0SLcCowHcq0OKulOWIwGnpbpdiRNeRMDxxsXZj2IrJaQVhPE 6HAMd8V+KzPaR309ora8lx5PYz/StYRBgiuuq9M1ymuIbw7lbNmeLNKiCFZ8crMpe1Km MhAdDNFjz8encR0qhZvGLYo/U3AAlvNjaX3WUNCAYonsKijNIsjUebUqehJ4x9wqYR1U 0vX65Jja/ak69RIdGxbhuWmnESSp7TBKh1z1DE3mzDNFhAj5eCo0dep2Gy0EQ0ZS04i0 BgJ8M7IJpfzuS3f8yUEumC/eP6/Y4IE2AYyFss742Bo8dGUFx9oMrhDsdfqBHDaKwfjo Se4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dPIkaW5v; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g1-20020a1709063b0100b0073d679b5595si3880934ejf.221.2022.08.21.04.55.55; Sun, 21 Aug 2022 04:56:21 -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=@kernel.org header.s=k20201202 header.b=dPIkaW5v; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbiHULqw (ORCPT + 99 others); Sun, 21 Aug 2022 07:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbiHULqv (ORCPT ); Sun, 21 Aug 2022 07:46:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9050186FB; Sun, 21 Aug 2022 04:46:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 89E99B80A08; Sun, 21 Aug 2022 11:46:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B748FC433D6; Sun, 21 Aug 2022 11:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661082407; bh=DGQUS8eXAZIHm2Ygm52BO8zfyjHBCFCIa+NCARaxGBs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dPIkaW5vsgPBT+lcFlQGkA2Y0OqcOfe9s4D6V6djZyS9nUCEaQVnBSNUc9OCrDAR/ 2IVdp2IFwwsKuKbl+4tZI7NSGxeUJ9ClIxFnZZ+DdynWYv0ioonw37BrC5ZAw7HTKL Ntb6idMYyLLJyMmtGmITpnqdDghRCqReP7Ez4vIBmj8B2FZyRVqtty3H3wKAiYszau 6rSf0sMA+OuW9qGw9nI1IHaPT6Eq+oKR3uUwWTMZ47ZuLulqTm5014sF0IG3Y724T9 ZXYcMIb4GuPmYDkSf3vYPpZZ4JsAMuVX22ZP+LUTkyFx79G9K0zZ+dzwmeanKSk00v U4TxuLSMVKIMw== Date: Sun, 21 Aug 2022 14:46:43 +0300 From: Leon Romanovsky To: Jack Wang Cc: linux-kernel@vger.kernel.org, Jason Gunthorpe , Christophe JAILLET , Kees Cook , =?iso-8859-1?Q?H=E5kon?= Bugge , linux-rdma@vger.kernel.org Subject: Re: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check Message-ID: References: <20220819060801.10443-1-jinpu.wang@ionos.com> <20220819060801.10443-3-jinpu.wang@ionos.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220819060801.10443-3-jinpu.wang@ionos.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 On Fri, Aug 19, 2022 at 08:07:44AM +0200, Jack Wang wrote: > dma_map_sg return 0 on error, in case of error set > EIO as return code. > > Cc: Jason Gunthorpe > Cc: Leon Romanovsky > Cc: Christophe JAILLET > Cc: Kees Cook > Cc: "H?kon Bugge" > Cc: linux-rdma@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Jack Wang > --- > drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c > index f2734a5c5f26..44fd5fdf64d5 100644 > --- a/drivers/infiniband/hw/mthca/mthca_memfree.c > +++ b/drivers/infiniband/hw/mthca/mthca_memfree.c > @@ -189,7 +189,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, > chunk->npages, > DMA_BIDIRECTIONAL); > > - if (chunk->nsg <= 0) > + if (!chunk->nsg) > goto fail; > } > > @@ -208,7 +208,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, > chunk->nsg = dma_map_sg(&dev->pdev->dev, chunk->mem, > chunk->npages, DMA_BIDIRECTIONAL); > > - if (chunk->nsg <= 0) > + if (!chunk->nsg) > goto fail; > } > > @@ -482,8 +482,9 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, > > ret = dma_map_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1, > DMA_TO_DEVICE); > - if (ret < 0) { > + if (!ret) { This code is not equivalent to original code. mthca didn't count ret == 0 as an error. Most likely, it is a bug, but I don't want to change old and unmaintained driver without any real need. Thanks > unpin_user_page(pages[0]); > + ret = -EIO; > goto out; > } > > -- > 2.34.1 >