From patchwork Thu Aug 27 15:43:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis Efremov (Oracle)" X-Patchwork-Id: 11740971 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26F4E722 for ; Thu, 27 Aug 2020 15:43:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F34C22177B for ; Thu, 27 Aug 2020 15:43:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OM+Etghn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F34C22177B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=c7iwPe2exml6TrhYDnHMMybtzM5Bc+ZfoaWqeESsSMI=; b=OM+EtghnoAvwcUmAE9G7tBRwg 9UlDuLQiHznvoBP8lKt/VlHNvOwE74VX3P9w/85plAFBcOAkxzgRfpGv4PERinfgbBTk9qkMkRHKS CUONYXwmITgwznmUHkR9001ahV7ynI23p4T6xGXnw4rgx5TVtk2QgK3x8DM7h9346KY9KYxsGEf/U Um5Gbgq2dlvSl6OUFzi4SJeR5/uhoDuIiEhXf1/+z+Izdjsor4/pnmE2GnBpSQBQ0a+iNlMiaOIKJ TBQpkNGOmaBuFQWGhH9hWsGThxxwEkcBfCSVsBEUJ5zVjRyrOPc/KSQZzBp73ppCA2lJegOq/Y8Cv bs+hVgUKw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBK42-0006tv-K5; Thu, 27 Aug 2020 15:43:46 +0000 Received: from mail-lj1-f194.google.com ([209.85.208.194]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBK3z-0006t4-Tz for linux-arm-kernel@lists.infradead.org; Thu, 27 Aug 2020 15:43:44 +0000 Received: by mail-lj1-f194.google.com with SMTP id w14so6976281ljj.4 for ; Thu, 27 Aug 2020 08:43:43 -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=LkLIjI9Cs33epu04wk6P3q7FKKIW0wVv+tnMhTJcMO7TmKewoaIn5iFSZxN6eZwycB EoNeKmXKzmycyWnNGpQiWTHX8oXg7Kky0JYaqAbMiIqpDYqTUvxUSndZVrGasHGZip+w ADsJeSn7QHSINHfp8Mt43RxKQO5nc6p96MNo5Ntpd6i0vcPQck+pcZkTc96cEzcY1fnA yu0zGxTSxgggpgDCFxj970SvjI125m1jba2UiCczckN2UhR1vujADNrqkr0qtRl6SoCO sIye8cYI8Vk7Z8aFZAAAcvVTnS6lz/mH6bmz2lIhm9Anu/BawyIcY8aDhMuvZcAtA6Jz ezCw== X-Gm-Message-State: AOAM533LZ2TFuBw8uvMChLbz2iRCvYiYpjKZkKHS16RuZswrQ8zRvq8i u+BChVgYbq/D8wERlVkA40wHaGRLJik= X-Google-Smtp-Source: ABdhPJw81uRyj24zCh763+6zJC7YkxjUK4+aqtS7HyG2wlPVtSBqHqeGdr2FUiKyUQKYCxUXJtJv3A== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200827_114344_088321_7E9CDC06 X-CRM114-Status: GOOD ( 14.01 ) X-Spam-Score: 0.5 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.208.194 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.194 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [yefremov.denis[at]gmail.com] 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and EnvelopeFrom freemail headers are different X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Morton , linux-kernel@vger.kernel.org, Denis Efremov , Russell King Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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;