Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp636087pxa; Thu, 27 Aug 2020 11:30:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOAb+4BqQiwPV+W//vF1gASyeCNCOcYiW3/9FQZ4kSkRdXKlanomEBI7+Vow48IAqz9SbT X-Received: by 2002:a17:906:5205:: with SMTP id g5mr21827758ejm.488.1598553034175; Thu, 27 Aug 2020 11:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598553034; cv=none; d=google.com; s=arc-20160816; b=dQv5C7i/JVwE2d2SUkYCFqa3KmEkzMXC9+SV62w8FJdxFq0Jm32nWfhZCmtaFAUUMS 4H47/Oha0Qv6spTXPEIFIlh5JGAu7QqE9vw7Sx4Zaay1jXGxfY/09Bs+Nbjx+MnVw+bI 329vgqIN4UFUMqBhxfpw5xcDyfII4Fs9fZBFhwdI5i+9WqlgMQ2MmCy1q7VGLlkER1Dh AApGvN6qjX8zZQzHVQApOVZ+Z50cTgSyf7PdIzPV2cGqOC7aQ82dCRYbp8p/e78fT+tM uxTccAsRsWf2cbk8ameCC1zLOkIV+0axb4HpifoCgnIvQPunmYVqodk/1jloJBql1WYr DtVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ulM4zphVmYjc4S9b2Lnt29gOEjsPBhXOSlZ5WIDIwjI=; b=gybyp1TddZV3E1+9WC/RF73YncfnI2ydYdf6kY0MoiqWLoW5pv+6Iyehb2Tnzlt544 /Cjh6W1VmWhSTPNGvF5zt1VltLUJPW8S9gAZg6tmShMt6R/cVIq12f2xtfVeqVKjs6FM w6lffYCXz5nJGylRbXnV3SfXyS7E4zL4An0gHn8xHlAPVkuvwJaADAy0H/J/uhonqI9S 3ftH4v8JRXCu55ZeL52Ug3R/Bia5lbOd5Gr5Q7PqE/RubF3BW9fuIVrEGCC8TgTcp/nq 06fpVZ4WbxtS5dSLJj7r1f+Jeqk8GEgq+6iDhVTMD5fyVJqU8wrgxvmTTrPUuVvCAGpO 1ExQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a2si2035389edm.136.2020.08.27.11.30.11; Thu, 27 Aug 2020 11:30:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbgH0S1D (ORCPT + 99 others); Thu, 27 Aug 2020 14:27:03 -0400 Received: from foss.arm.com ([217.140.110.172]:33130 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgH0S1D (ORCPT ); Thu, 27 Aug 2020 14:27:03 -0400 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 71E80101E; Thu, 27 Aug 2020 11:27:02 -0700 (PDT) Received: from [10.57.40.122] (unknown [10.57.40.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 888073F68F; Thu, 27 Aug 2020 11:27:01 -0700 (PDT) Subject: Re: [PATCH v2] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer() To: Denis Efremov , linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, Russell King References: <20200827151541.39662-1-efremov@linux.com> <20200827154332.41571-1-efremov@linux.com> From: Robin Murphy Message-ID: <5c84eec0-c249-6e8f-590b-cbb32bad3601@arm.com> Date: Thu, 27 Aug 2020 19:27:00 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200827154332.41571-1-efremov@linux.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-08-27 16:43, Denis Efremov wrote: > Use kvzalloc() in __iommu_alloc_buffer() instead of open-coding it. > Size computation wrapped in array_size() macro to prevent potential > integer overflows. FWIW I'm currently working on a much more thorough cleanup by way of removing this code entirely [1] ;) Robin. [1] https://lore.kernel.org/linux-arm-kernel/cover.1597931875.git.robin.murphy@arm.com/ > Signed-off-by: Denis Efremov > --- > Changes in v2: > - array_size() added > > arch/arm/mm/dma-mapping.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index 8a8949174b1c..c1f864ff7b84 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -1199,14 +1199,10 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, > { > struct page **pages; > int count = size >> PAGE_SHIFT; > - int array_size = count * sizeof(struct page *); > int i = 0; > int order_idx = 0; > > - if (array_size <= PAGE_SIZE) > - pages = kzalloc(array_size, GFP_KERNEL); > - else > - pages = vzalloc(array_size); > + pages = kvzalloc(array_size(sizeof(*pages), count), GFP_KERNEL); > if (!pages) > return NULL; > >