From nobody Fri Dec 19 07:49:53 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 6C3B2C6FA8B for ; Tue, 13 Sep 2022 14:29:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233371AbiIMO3n (ORCPT ); Tue, 13 Sep 2022 10:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233826AbiIMO1o (ORCPT ); Tue, 13 Sep 2022 10:27:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D17962AA2; Tue, 13 Sep 2022 07:17:16 -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 63DD0B80F9A; Tue, 13 Sep 2022 14:15:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B513FC433C1; Tue, 13 Sep 2022 14:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078522; bh=rD+Zgf85uu8YoYCltsffuOqkGyccymJZYpP3cYLbDGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O1oLLWY1bUY6f9NmR1NJMc0RDodbMdjoChZdXXPKK9y6k7ZXl0RT7FowY1R6l2Rhe MoV3JE9ZOL9IoJH5RIeWPauoDgZVPw7zC86Z/xP6bbL01KMwfpzsDZnHAFB0b/dVwz Ei0G01QPfnCYWSROBcluy3Wmbq5jLGNzFg6EScZo= 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.19 173/192] hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not defined Date: Tue, 13 Sep 2022 16:04:39 +0200 Message-Id: <20220913140418.658240142@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@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 26278b0f17a98..8b72e8fe34c1b 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -584,7 +584,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 || @@ -594,13 +599,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