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 X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5291DC433FE for ; Mon, 6 Sep 2021 17:05:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F23060F70 for ; Mon, 6 Sep 2021 17:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243055AbhIFRG0 (ORCPT ); Mon, 6 Sep 2021 13:06:26 -0400 Received: from mail-ot1-f46.google.com ([209.85.210.46]:39877 "EHLO mail-ot1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233888AbhIFRGW (ORCPT ); Mon, 6 Sep 2021 13:06:22 -0400 Received: by mail-ot1-f46.google.com with SMTP id m7-20020a9d4c87000000b0051875f56b95so9463200otf.6; Mon, 06 Sep 2021 10:05:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nWSkQkSt0bxIWZikjyNv1yc6a2mBNyIggcCEjOgf7nk=; b=h8jegpGdYZGD22NG/QMUwQ947lZ7fXcYLoflwSGc8VkEz1oLstIrsONdFLBi6NkZZ/ dRmzkjds4F4GSu69leGD4/onRNXK/PJJX0KaNV+8R/ommh8Kz9qxiQpbB3JlwYqiJVml YDfYKtMEhFAnNvJmks7l+EmxQUHGPiwmJaNk6oNxnPr1bLIC5oeHTKS0g6IQSVeV28Gd Brp8v38dtZPuknaRGpDeeeAgwkVcpIFIdjDfBPryb1p/GF8u4e6ePuxD1LcfLeJxuPI1 OUZLBHv+fKru6wFFUhLc/7QIEYjeqOGcnBEd8vEi/20B2a19wP7ScIleY6ommeWMhywq yuVg== X-Gm-Message-State: AOAM532RuPH/GgS6tS/+ERoKWW8bPEyvEK4hRl4X+aT53InkQY/FeNv0 iImwnILtRd7E3WA693R6o07RhfQx1xXx4CnmzYA= X-Google-Smtp-Source: ABdhPJyX4pJ82lhruFxtVqo76a/SKXbQN1Ot4TUHTDaQfC+AMjsTShGS3vOfZirkAgS56YQITo1F5aLqKIHvTkr7q0M= X-Received: by 2002:a9d:6945:: with SMTP id p5mr11983974oto.301.1630947917061; Mon, 06 Sep 2021 10:05:17 -0700 (PDT) MIME-Version: 1.0 References: <20210904151628.6618-1-len.baker@gmx.com> In-Reply-To: <20210904151628.6618-1-len.baker@gmx.com> From: "Rafael J. Wysocki" Date: Mon, 6 Sep 2021 19:05:06 +0200 Message-ID: Subject: Re: [PATCH] cpufreq: powernow: Prefer kcalloc over open coded arithmetic To: Len Baker Cc: "Rafael J. Wysocki" , Viresh Kumar , Kees Cook , Linux PM , linux-hardening@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 4, 2021 at 5:16 PM Len Baker wrote: > > As noted in the "Deprecated Interfaces, Language Features, Attributes, > and Conventions" documentation [1], size calculations (especially > multiplication) should not be performed in memory allocator (or similar) > function arguments due to the risk of them overflowing. This could lead > to values wrapping around and a smaller allocation being made than the > caller was expecting. Using those allocations could lead to linear > overflows of heap memory and other misbehaviors. > > So, use the purpose specific kcalloc() function instead of the argument > size * count in the kzalloc() function. > > [1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments > > Signed-off-by: Len Baker I'm assuming that this patch will be picked up by the powerpc arch maintainers. > --- > drivers/cpufreq/powernow-k7.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c > index 5d515fc34836..a9d2c7bae235 100644 > --- a/drivers/cpufreq/powernow-k7.c > +++ b/drivers/cpufreq/powernow-k7.c > @@ -174,8 +174,8 @@ static int get_ranges(unsigned char *pst) > unsigned int speed; > u8 fid, vid; > > - powernow_table = kzalloc((sizeof(*powernow_table) * > - (number_scales + 1)), GFP_KERNEL); > + powernow_table = kcalloc(number_scales + 1, sizeof(*powernow_table), > + GFP_KERNEL); > if (!powernow_table) > return -ENOMEM; > > -- > 2.25.1 >