From nobody Sun Sep 14 22:48:28 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7ED4C6FA8A for ; Tue, 13 Sep 2022 15:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235047AbiIMPAh (ORCPT ); Tue, 13 Sep 2022 11:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235062AbiIMO7H (ORCPT ); Tue, 13 Sep 2022 10:59:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18A6A67CB0; Tue, 13 Sep 2022 07:28:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E8EF0614CC; Tue, 13 Sep 2022 14:20:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D9E0C433D6; Tue, 13 Sep 2022 14:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078858; bh=tpfvlFFXB8h22ykFC8JnISA5KF2dIsFU0f/6O3YlmGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b85OwzYdZLbIQLY4WqhrqGSbNTcfsQ7Rq/sJGg4HzgiUcpoPJA8qDOye01Zlo5RCD uLSRiUo56Q18ck+Ue3jS4TV48A0vPPiDPrhvh8B6K6Qezxk0Bzzf4yaQko3HcGysqP vxAmgtu2QntQF2QBCkT9c3wj+t3F38CV8e2ZPtBw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eliav Farber , Andy Shevchenko , Guenter Roeck , Sasha Levin Subject: [PATCH 5.15 110/121] hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not defined Date: Tue, 13 Sep 2022 16:05:01 +0200 Message-Id: <20220913140402.075695444@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140357.323297659@linuxfoundation.org> References: <20220913140357.323297659@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Eliav Farber [ Upstream commit 81114fc3d27bf5b06b2137d2fd2b63da656a8b90 ] Bug - in case "intel,vm-map" is missing in device-tree ,'num' is set to 0, and no voltage channel infos are allocated. The reason num is set to 0 when "intel,vm-map" is missing is to set the entire pvt->vm_idx[] with incremental channel numbers, but it didn't take into consideration that same num is used later in devm_kcalloc(). If "intel,vm-map" does exist there is no need to set the unspecified channels with incremental numbers, because the unspecified channels can't be accessed in pvt_read_in() which is the only other place besides the probe functions that uses pvt->vm_idx[]. This change fixes the bug by moving the incremental channel numbers setting to be done only if "intel,vm-map" property is defined (starting loop from 0), and removing 'num =3D 0'. Fixes: 9d823351a337 ("hwmon: Add hardware monitoring driver for Moortec MR7= 5203 PVT controller") Signed-off-by: Eliav Farber Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/20220908152449.35457-3-farbere@amazon.com Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/mr75203.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 1ba1e31459690..36cbc86033ce9 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -594,7 +594,12 @@ static int mr75203_probe(struct platform_device *pdev) ret =3D device_property_read_u8_array(dev, "intel,vm-map", pvt->vm_idx, vm_num); if (ret) { - num =3D 0; + /* + * Incase intel,vm-map property is not defined, we + * assume incremental channel numbers. + */ + for (i =3D 0; i < vm_num; i++) + pvt->vm_idx[i] =3D i; } else { for (i =3D 0; i < vm_num; i++) if (pvt->vm_idx[i] >=3D vm_num || @@ -604,13 +609,6 @@ static int mr75203_probe(struct platform_device *pdev) } } =20 - /* - * Incase intel,vm-map property is not defined, we assume - * incremental channel numbers. - */ - for (i =3D num; i < vm_num; i++) - pvt->vm_idx[i] =3D i; - in_config =3D devm_kcalloc(dev, num + 1, sizeof(*in_config), GFP_KERNEL); if (!in_config) --=20 2.35.1