From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AECC5C433F5 for ; Tue, 8 Mar 2022 10:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE81B8D0001; Tue, 8 Mar 2022 05:59:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A97948D0003; Tue, 8 Mar 2022 05:59:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 938C78D0001; Tue, 8 Mar 2022 05:59:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 794AE8D0003 for ; Tue, 8 Mar 2022 05:59:30 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4E608216F9 for ; Tue, 8 Mar 2022 10:59:30 +0000 (UTC) X-FDA: 79220922900.09.472AFBC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id AD442100005 for ; Tue, 8 Mar 2022 10:59:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646737169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aqPCGU3/YxaZYETOn7Lp2yXhW5De7uTDNtK+spwoHhQ=; b=B8zRqxlj6tUvCIQEM0VATH5HXq17MrfwGV3ViUWOV4vl031ZRMEgGx5T9J+onLDN06Qxqb tHujEFEjhRHlDq5Gi44oTZjKbFxoJrD/wPVdnwDqMfcuVGKi5XaoETPb7eW3XD9uVssC6H iZwqU8SssokTdQuOtS9lzwlk7nsOnQw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-391-rc6sWkT3NxS1VHxqq63bzA-1; Tue, 08 Mar 2022 05:59:25 -0500 X-MC-Unique: rc6sWkT3NxS1VHxqq63bzA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6412C800050; Tue, 8 Mar 2022 10:59:23 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82C976FB03; Tue, 8 Mar 2022 10:59:22 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Michael Ellerman , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Johannes Weiner , Michal Hocko , Vladimir Davydov , linux-mm@kvack.org, cgroups@vger.kernel.org Subject: [PATCH 2/3] mm: use vmalloc_array and vcalloc for array allocations Date: Tue, 8 Mar 2022 05:59:17 -0500 Message-Id: <20220308105918.615575-3-pbonzini@redhat.com> In-Reply-To: <20220308105918.615575-1-pbonzini@redhat.com> References: <20220308105918.615575-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Rspamd-Queue-Id: AD442100005 X-Stat-Signature: fzjh36trkk7348e3zcnsggihd3md1xnp X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B8zRqxlj; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf14.hostedemail.com: domain of pbonzini@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=pbonzini@redhat.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646737169-596906 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Instead of using array_size or just a multiply, use a function that takes care of both the multiplication and the overflow checks. Cc: linux-mm@kvack.org Signed-off-by: Paolo Bonzini --- mm/percpu-stats.c | 2 +- mm/swap_cgroup.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/percpu-stats.c b/mm/percpu-stats.c index c6bd092ff7a3..e71651cda2de 100644 --- a/mm/percpu-stats.c +++ b/mm/percpu-stats.c @@ -144,7 +144,7 @@ static int percpu_stats_show(struct seq_file *m, void *v) spin_unlock_irq(&pcpu_lock); /* there can be at most this many free and allocated fragments */ - buffer = vmalloc(array_size(sizeof(int), (2 * max_nr_alloc + 1))); + buffer = vmalloc_array(2 * max_nr_alloc + 1, sizeof(int)); if (!buffer) return -ENOMEM; diff --git a/mm/swap_cgroup.c b/mm/swap_cgroup.c index 7f34343c075a..5a9442979a18 100644 --- a/mm/swap_cgroup.c +++ b/mm/swap_cgroup.c @@ -167,14 +167,12 @@ unsigned short lookup_swap_cgroup_id(swp_entry_t ent) int swap_cgroup_swapon(int type, unsigned long max_pages) { void *array; - unsigned long array_size; unsigned long length; struct swap_cgroup_ctrl *ctrl; length = DIV_ROUND_UP(max_pages, SC_PER_PAGE); - array_size = length * sizeof(void *); - array = vzalloc(array_size); + array = vcalloc(length, sizeof(void *)); if (!array) goto nomem; -- 2.31.1