From nobody Mon Apr 6 00:12:16 2026 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 BD148C6FA82 for ; Tue, 13 Sep 2022 14:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234743AbiIMO4O (ORCPT ); Tue, 13 Sep 2022 10:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234567AbiIMOwi (ORCPT ); Tue, 13 Sep 2022 10:52:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0E9461D55; Tue, 13 Sep 2022 07:26:49 -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 ams.source.kernel.org (Postfix) with ESMTPS id DE7ACB80FAC; Tue, 13 Sep 2022 14:24:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47409C433D7; Tue, 13 Sep 2022 14:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079079; bh=GmD8OyhS5q9OcZubOKiww01zvgwVnQC/NOAKXwhA8qU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zQWMM+qi3eroPQSsDhm9jDvTgRy6pb4IofK8ZY4bML1IvZuY+bTPQRwhZdvsX0Eb7 tymNEt7PDFbheD1wvX5LFK+8cVNJ5a/D9/wygLL5qaVoeNWaxr8MrUvm7DdwmEgjID 9AQZttz8OU+BRo7Cp7BRLBfQqXRyGvW7T1KNMczU= 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.10 74/79] hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not defined Date: Tue, 13 Sep 2022 16:05:19 +0200 Message-Id: <20220913140353.728371935@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140350.291927556@linuxfoundation.org> References: <20220913140350.291927556@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 046523d47c29b..81ccb4c6fa5c0 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