Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp96417iob; Tue, 17 May 2022 20:01:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyY3fJRsPb9aVR4b2hlTkCco8udU2Lsk3F2sTpPkgN4EoUfVWdEgko3fhAkoScvf/W6moY X-Received: by 2002:a17:903:230e:b0:15e:d0a1:922f with SMTP id d14-20020a170903230e00b0015ed0a1922fmr24945722plh.75.1652842891853; Tue, 17 May 2022 20:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652842891; cv=none; d=google.com; s=arc-20160816; b=PJnEqiTBuoRe3Z/ubRB90JqZvp0Nvm/4yvtsxC3doi+P0tddrPBIlPZRig+s6mBFkq FMpEvLD8lHMcKmHcZ5jGOMPeQCJMHPjN37FFN7R6YzvVsR517wuG5feCh4FDRqT7FNef 3HxntclSSxgbkEWCQbtiwXBNeuVcji2lZg41hWLS+h775sJtXWOBngbxovMYzjFLP2p8 MQtjdFq9KmJSgdabAlzaXWD2O0QAhnT0sh+5OmxICBaH9Llo0jF0jTH1xWlvfIGX3jkx s43pjFVNWxGsJMEaTU3I5RaHLxpiEptZNgKpD1fXsH04ZDhYrquNqXpCTEzy36kQKdF5 PZRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=5SsP37UyqV9zKFxp78tuJRRWvzmW3YnHpsNBDB5SNaY=; b=s4QtwFNwLn721TqvfLFVggkOok4hWX7UzPr/xlL3tLkZpk1Tu3idpGWx+efMgxjbSa IdGnZWEU0H/Cdr5568oi+dWyO/raJY8KEil0Cusa2tBkm1aduEo8Sgi4qPQBmh72a+zL RbLlrJGvyl+COsIH+eyuJRiI1YvsX/Z863HtxvkYlC3cU8Bc5tpapCa/Wj6bQUP31gcp hAH7mOGuLw5gjddw64DqFhF92yEjnusaHSPWF2YkA1vSWoLm9Th3ErGtsIR9Tj8gFCsc 5ZIOE6zcT7bE9IPHwB4jJ+p6wIDS1g8eYMDMQiIIaWNn/QdQFfH7fOcFe+xIHJMF/PEq k0uQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n3-20020a056a000d4300b0050bb3e9c4bdsi1294073pfv.355.2022.05.17.20.01.14; Tue, 17 May 2022 20:01:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344088AbiEQKUj (ORCPT + 99 others); Tue, 17 May 2022 06:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344102AbiEQKUP (ORCPT ); Tue, 17 May 2022 06:20:15 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B24B4C7B1 for ; Tue, 17 May 2022 03:19:01 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 07EF31042; Tue, 17 May 2022 03:19:01 -0700 (PDT) Received: from [10.57.82.55] (unknown [10.57.82.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9DADC3F66F; Tue, 17 May 2022 03:18:59 -0700 (PDT) Message-ID: <0e9356ee-9ae0-fd6d-b4ba-b1f05d8ba144@arm.com> Date: Tue, 17 May 2022 11:18:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] iommu/dma: Fix check for error return from iommu_map_sg_atomic() Content-Language: en-GB To: Niklas Schnelle , Christoph Hellwig Cc: Joerg Roedel , Will Deacon , Jason Gunthorpe , Matthew Rosato , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org References: <20220513153948.310119-1-schnelle@linux.ibm.com> <20220517083657.GA16377@lst.de> <27ae8b9f8e61dce4b31a37622e98b1c57b21b104.camel@linux.ibm.com> From: Robin Murphy In-Reply-To: <27ae8b9f8e61dce4b31a37622e98b1c57b21b104.camel@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 2022-05-17 11:17, Niklas Schnelle wrote: > On Tue, 2022-05-17 at 10:36 +0200, Christoph Hellwig wrote: >> On Fri, May 13, 2022 at 05:39:48PM +0200, Niklas Schnelle wrote: >>> In __iommu_dma_alloc_noncontiguous() the value returned by >>> iommu_map_sg_atomic() is checked for being smaller than size. Before >>> commit ad8f36e4b6b1 ("iommu: return full error code from >>> iommu_map_sg[_atomic]()") this simply checked if the requested size was >>> successfully mapped. >>> >>> After that commit iommu_map_sg_atomic() may also return a negative >>> error value. In principle this too would be covered by the existing >>> check. There is one problem however, as size is of type size_t while the >>> return type of iommu_map_sg_atomic() is now of type ssize_t the latter gets >>> converted to size_t and negative error values end up as very large >>> positive values making the check succeed. Fix this by making the return >>> type visible with a local variable and add an explicit cast to ssize_t. >>> >>> Fixes: ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()") >>> Cc: stable@vger.kernel.org >>> Signed-off-by: Niklas Schnelle >> >> I don't see what the point of the newly added local variable is here. >> Just casting size should be all that is needed as far as I can tell. > > No technical reason just found it easier to read and more descriptive. > I'll sent a v2 with just the cast, it does simplify the commit message. Note that this is already fixed upstream, though: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git/commit/?h=core&id=a3884774d731f03d3a3dd4fb70ec2d9341ceb39d Robin.