Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3917537iob; Tue, 17 May 2022 09:49:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2FYI4FSQTSN0GoVQKzdj241bWct2He2ck4Wr0m+HEGT6g/tNh9EizQCEnpvryWWvE11Kj X-Received: by 2002:a17:90b:1811:b0:1dc:7f26:458a with SMTP id lw17-20020a17090b181100b001dc7f26458amr25450098pjb.150.1652806192221; Tue, 17 May 2022 09:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652806192; cv=none; d=google.com; s=arc-20160816; b=0Edm/7VQA5niZSEkFIs4pM8Eo+rvWU826ZApXlC76Dw+lXuXZ2zqr4u2n6WwZ6Qaq3 PVzmqe5AHkFYiYaH8f4Ki8ZdeNgYPAHqDOTD/y3bAkcP989MWFg+W+tjWWMSMIlrEXyR +pPugamiuXPAi3CGy8HRxHcB2i3j2pVI7XIJWbS2dg5fRZ8jDTsfj2+yyFqpvJ+WU2ay oRyF6eDxZQvn9MwXQiqJ6i8mlVNZPJgI0DWNmivVFNQG1ehxTum6Wwoy+7HFkGeoPPph jlPnvhwhkAd8NOIF0fbW7vCudJ/UUYBYIZrh4ExwvhrXiTy19r13MhmxvbKUehAysO0L xR4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=08RBCiu6OQ8mEEp8MxW7myx1/ebGOeYahGa5WBlRRm0=; b=BsQzmFx0KrxWK18XmLH8iMze575ei76ZLWGuICgt1WBZ2icl/xXay4x1urxDRNvTNh FQzAy8LW7wU9hmvc4nhXM3slb/7xRQnuM3a4UiycV5hTgEnW2rJbfku6UCKFlSvDgTPX hN3ombLQrP26BBIj8YpCV5hP/OrYLLI1ESLIMLhZutFMfw3VY5Yf6KfptAKmfGJQb5Fy nFk/VIVp44uRl4piYUUyoW0OWooSqWdojbe8qXlZ3A6kLep1s3qpAXjBecp35BvtGdkS I3VJnocoZyka1J10b/1x53tUWUEZmCUl8IPT8v7s+XiDbWBNvYaAy+SWR4FbOzGntNK9 onXQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a634b01000000b003c6ae769e50si16982871pga.759.2022.05.17.09.49.39; Tue, 17 May 2022 09:49:52 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243407AbiEQIhF (ORCPT + 99 others); Tue, 17 May 2022 04:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231534AbiEQIhC (ORCPT ); Tue, 17 May 2022 04:37:02 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEE0A65BC for ; Tue, 17 May 2022 01:37:01 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id C2D2667373; Tue, 17 May 2022 10:36:57 +0200 (CEST) Date: Tue, 17 May 2022 10:36:57 +0200 From: Christoph Hellwig To: Niklas Schnelle Cc: Joerg Roedel , Will Deacon , Christoph Hellwig , Jason Gunthorpe , Robin Murphy , Matthew Rosato , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Subject: Re: [PATCH] iommu/dma: Fix check for error return from iommu_map_sg_atomic() Message-ID: <20220517083657.GA16377@lst.de> References: <20220513153948.310119-1-schnelle@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220513153948.310119-1-schnelle@linux.ibm.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 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.