Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp530473pxa; Thu, 27 Aug 2020 08:45:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9cA61MpXmW7cbniwowaelJPZs5rqyAJkKwhq5EfuXJet61tlpzrrk9D5R/VfxspWGC4mT X-Received: by 2002:a50:dac6:: with SMTP id s6mr20456582edj.378.1598543106837; Thu, 27 Aug 2020 08:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598543106; cv=none; d=google.com; s=arc-20160816; b=eGbhiJACCywMpWf1F8VZQD9fA8uy5LBjuGVsODYgJ17ZDra7JW9sIVI723/KdN9V5v W79UTJk3WlfVMps0HXtI69GNctUnhKUHKvogWwf63zHtoymaJF94BH0pF09z5So7w83w oeunPDTtfY78CtqY7NNGGYR+oiwzjz8szfVpPj6pXJDaHFPfYoQs2pO/tDa2/CzXm1YB n00aeMWfCH250nG6HTTLk18MS+KSGSJeO/cSe+n5Oy0WwaFt5pc1J5rdEyNVl61ag/dT 3Gjn/3E+Lg9AWakGnyHsRVHqzcl9vauXCtU0pqxBqN60SsUW3ItYuTFx7V99aAR46Ro5 Hwdg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=a1axoXprReWaPScASLIzL4aItcgQogrVYwx/CXLgqrE=; b=a3YCLGMKTEGuEDlEFO4AY/S1leU1fvX1GiN60MUE1+EuZt22Wi58XCKZQYcalS3bGV JKSIngFH4MlSeGSMKHcO0dX1pEbNjLSPrN1H3D73d8nKjDxJPsUYs87k/21D0TOFo0Zv hXX5gexrbDYuuCNrNzpYm5nmlsQ3h9BgISahKmZxuWfn94UEweVR4A4Umg9+Na0sgHoZ QW9vtgB2a5kvN6y0I+8EzMu3gieE3L8ZATRwFZmTWERTsmtZ4ibk8Ra1Kb3oLfMthv0o zCGf6818abYgOh/8+KZ6nkqIGmAfoczLudl9TdF+fSc+YFVg25mb0HN/avT12t2Ujp4D tLxQ== 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 e24si1590858eds.212.2020.08.27.08.44.44; Thu, 27 Aug 2020 08:45:06 -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 S1727999AbgH0Pnq (ORCPT + 99 others); Thu, 27 Aug 2020 11:43:46 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46865 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726938AbgH0Pno (ORCPT ); Thu, 27 Aug 2020 11:43:44 -0400 Received: by mail-lj1-f193.google.com with SMTP id h19so6943563ljg.13 for ; Thu, 27 Aug 2020 08:43:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a1axoXprReWaPScASLIzL4aItcgQogrVYwx/CXLgqrE=; b=jXn6nmBYqAGwg81kx0+qPCrWQgstj6F+PtIVyp9xXceH+x51aR3acIrRPRrUHxaYor ooFE7qDeAl/1GeT4epk/zbprDDmuKHvDCE+2WmAt30jh3gUfHqQpYgIKpsTRSgbOBl6z 170+2gmRrnTSnfyLbNqDJE4qmsFh/ga8UThazMxJ2xmB1SP+JnqXC7OE7mdmTH7kyvtr rSMh76kEmL5cwC01CdNgD7Zwmvt+EdUsXiO6fZpjYtMadBtmy/HS02sDvb6Kjclj0FCm aR2dfS0PPpsJr4QKiXYyT29Jzb0GIA0K8FAiCir0JOdQ0X9ahyJ8E50G7lAwO2hqw0Ba KCjA== X-Gm-Message-State: AOAM532jK6U8Lg/7t6QYHzgl5C2RJuF25sGqUXgJjXv88kN0VhlJvQZu nA0YDJ/gOdD9hYg/ulqqQYM= X-Received: by 2002:a2e:7315:: with SMTP id o21mr3229772ljc.120.1598543022146; Thu, 27 Aug 2020 08:43:42 -0700 (PDT) Received: from localhost.localdomain ([213.87.147.111]) by smtp.googlemail.com with ESMTPSA id u6sm548595ljg.105.2020.08.27.08.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 08:43:41 -0700 (PDT) From: Denis Efremov To: linux-arm-kernel@lists.infradead.org Cc: Denis Efremov , Andrew Morton , linux-kernel@vger.kernel.org, Russell King Subject: [PATCH v2] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer() Date: Thu, 27 Aug 2020 18:43:32 +0300 Message-Id: <20200827154332.41571-1-efremov@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200827151541.39662-1-efremov@linux.com> References: <20200827151541.39662-1-efremov@linux.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use kvzalloc() in __iommu_alloc_buffer() instead of open-coding it. Size computation wrapped in array_size() macro to prevent potential integer overflows. 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; -- 2.26.2