Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp3009080pxb; Mon, 6 Sep 2021 10:09:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8lG3eEp5jE41IfhCRW2AHtk8Z55vs5PSc1qL/3cCjaIi5EzQGFfPBDvfBK4hv2vjEeRjU X-Received: by 2002:a17:906:49ce:: with SMTP id w14mr15122274ejv.273.1630948176002; Mon, 06 Sep 2021 10:09:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630948175; cv=none; d=google.com; s=arc-20160816; b=zPK7V1uV1UtDAf84cFzlWtLrEIULjhs55ru/iVTODzlZlSIn26p0mFgy2Ywx7CgbZU 7pUUgSbqiw3MsQy5/tUqnNDzq8iDjmg/kJry8sj/y2rptBJ9VVlcw2oKt5Fkx9aA3xft kRClfALqAuzJVRmBFPhbXJ68VyX/cRxxv4nD0pgnUi9SVr16zWtC+JWJsFZAGB8j9QiO XqJ9+hiLFVdUSxarSjxjfbQ3n4re044O5T84Xh15nKO3onNwqBEUU6j20DAlTdWery5w YattHMgt0d3hgML8VsB/KnM4dPp0laLe5W2fuwicbqq0GPeYEZCeyWKO3/SkAh7jLcnG R6WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=nWSkQkSt0bxIWZikjyNv1yc6a2mBNyIggcCEjOgf7nk=; b=IpBqteF8Mah/82VJAf4MId8bFV1exxOFspB+Xhr3/ZVSCXLb2jCAhMRxz2xVR0Ba8n fMxudRpUne3gmZwIDAq495b71/Ywr1ocpMDXehPO702lHt6Ih12ZEW0wfxJzgFNssuHl 52lJfUnwpZ0ik9qaUEQ6n3Uj31As5WwRTQDL8IJVkzoqrX8tv+fkS/a4T4BTCWd4ap2+ IZ9wg3uiM/DoZA5+qsBt3We7zjTS/R4iWzzbiZJ0qgQp6jLQPPj+ZThawsLs2nxBH6u2 dW+BSHrN6otVTOTuiG7jiW9ea9XKf1YP9HtvkDIN8H17bcXv1nKz4Yms24spIXCzF4yW K7BA== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si8771123edr.413.2021.09.06.10.09.12; Mon, 06 Sep 2021 10:09:35 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242944AbhIFRG0 (ORCPT + 99 others); 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-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 >