Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3475845pxp; Tue, 8 Mar 2022 15:26:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzaTCIPgS742bNVtzoQftXKuS2GOrnhsSX8TBxITyQpo0Uum+2CU1exb+amoXJHBBcbI9O/ X-Received: by 2002:a05:6a00:1991:b0:4f7:1322:ca04 with SMTP id d17-20020a056a00199100b004f71322ca04mr9738866pfl.85.1646781959827; Tue, 08 Mar 2022 15:25:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646781959; cv=none; d=google.com; s=arc-20160816; b=Rvydouqn+i509JZEX1qHwFJ4NyyVzy8/JZf/RV5w5y9VfY5l+ys51xIx2nNL0fWRgh +nf1iEehrHWfKp2ZsIbaIxzBJVQwWjiIiplsHhzRnxrk9pieJ8vjOedr9KtnuiBH8NAj SbZX1ARzBLm6BMEt/LGM+0DPGn8RIWFcJGZgDESHB79Fj1iVNa78GqzxltRah9/KNQ56 eGkUyTl+6Gum7Ksfb5zX6I2kZEywE5QXxSQdkBsLvq6Q3XuaUnNq8k6b6iPBg/nveMl6 bS5U8w2qZbWVv+oLFf10/sVqVGUmBw13/gLbnCqOx6uuAKVMZzbJa1uaPNgT4MQTY5mH LryQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=OiqyeB0b6J0rfF+qZiyPdJHBNMRJKO0i7S5FsGcKn6U=; b=b1jOGU5UPuwNunkA4QaxO2H2T5M6ua+SQIxb1w+CeI6bnXhCnQKl/D24rO96A3inYc zs2j/Dot7JxKfrcaNayq2UVd+uy1dP9Cb5Fg+5jA8jwG7leUCVtLdOJVYBVDNYx3WsTn VngkWfbm35hxGo43fojjevpujivG2HU/PjQJwzSNeskl9JqsHWxc/dGLgG63fFUqna22 0bq+7svKP0SpjQDgykTMAHgBkMEqwyjDeUwoQVtcjZyV4jcAkpjNsCbc2JqpaLeOgkO3 nt3+qfKw3Dxr/rcwdnaBd3lvLFHS93EHbdBGhqheFyA9ZECqdDb30GhRNHgtxo9jcvXg iNdw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id oc11-20020a17090b1c0b00b001bf1cb96d0bsi403958pjb.122.2022.03.08.15.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 15:25:59 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B721695A3D; Tue, 8 Mar 2022 15:17:02 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348067AbiCHQOu (ORCPT + 99 others); Tue, 8 Mar 2022 11:14:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244605AbiCHQOr (ORCPT ); Tue, 8 Mar 2022 11:14:47 -0500 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3CF5005E; Tue, 8 Mar 2022 08:13:50 -0800 (PST) Received: by mail-io1-f45.google.com with SMTP id q11so6914226iod.6; Tue, 08 Mar 2022 08:13:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=OiqyeB0b6J0rfF+qZiyPdJHBNMRJKO0i7S5FsGcKn6U=; b=XJlIo8W6fhvylzMQQVW/0LXUccx8jyc4J7GNCQgtZZwxwz/fIpARi5Q/TJ9B4PjNmA lHNWLUR27jPmh+nQhqCiBxOrXcBHmVzKHPk+xPnjJ8xJVghPkeupdwte7e9LBbzIp4Zg gH/B8cFATPT0HEjqOx4cA1hjbPmHbC/FXTfOH/dFGFBj6J5TbZYLP1zf4iBIl7ezH0z1 TTtJtubulvLvV9RmPuwK4dD57B2UMX++NuwJBb8FJyTJPYM151PleUYlrCbnTdHGdlei ffd+HIVTp8RJGHGEk5kU9GQIEZuaBqRGl0R+JGGXH2oPQmNzFz82F/jVno3hvko4m6vk UxcA== X-Gm-Message-State: AOAM533u0dVUwv0StUdcUTwsKgX95OrYq2UQZK633uQ8aoKm++zn0sFQ 6LP+5RTTplZKW1pGSwDfF7ax27T8yPk= X-Received: by 2002:a05:6638:3012:b0:317:9a63:ecd3 with SMTP id r18-20020a056638301200b003179a63ecd3mr16838924jak.210.1646756028135; Tue, 08 Mar 2022 08:13:48 -0800 (PST) Received: from fedora (216-241-34-136.static.forethought.net. [216.241.34.136]) by smtp.gmail.com with ESMTPSA id x7-20020a056e021ca700b002c5f9136a2dsm12453334ill.36.2022.03.08.08.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 08:13:47 -0800 (PST) Date: Tue, 8 Mar 2022 11:13:44 -0500 From: Dennis Zhou To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Michael Ellerman , Andrew Morton , Tejun Heo , Christoph Lameter , Johannes Weiner , Michal Hocko , Vladimir Davydov , linux-mm@kvack.org, cgroups@vger.kernel.org Subject: Re: [PATCH 2/3] mm: use vmalloc_array and vcalloc for array allocations Message-ID: References: <20220308105918.615575-1-pbonzini@redhat.com> <20220308105918.615575-3-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220308105918.615575-3-pbonzini@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hello, On Tue, Mar 08, 2022 at 05:59:17AM -0500, Paolo Bonzini wrote: > 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 > Acked-by: Dennis Zhou Thanks, Dennis