Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp364087imn; Fri, 29 Jul 2022 09:10:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uNcATLQTrjHkdepJzPmh/Nj57QBTexm+/RP/MtP2+95znTJnN2Oyd9vwIWnI8QjWVtfAqE X-Received: by 2002:a05:6402:1102:b0:43a:9cf7:68a3 with SMTP id u2-20020a056402110200b0043a9cf768a3mr4287532edv.68.1659111028267; Fri, 29 Jul 2022 09:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659111028; cv=none; d=google.com; s=arc-20160816; b=lToVDsggdBccqyjfN6nfHmCWotQwMdpziZ7c5J1B1ExgGSJk6nYG7If5V9xt5W9ynh pWJNI2PK4bjy50YJExWK+PfTtHN8AckL5uIPY/4NUqQXQoJV+OraWc0qmwpk4dltZVEe +Xd0Vwgh2KUzTh76ViE0ilK/Gfq/ThHgNuvf1gooLSCDQeK1ez5Mu5hta2YwmmpXZ/Jl LO9f6uCRV28HqkLsecv9wx65gjGJRAcvYhEvioonbaTgUKk2jG9IytLGvYZlRYq+0ewb Hh3QdXpj1Xl48h87krmayF3V4IrBb6WscA0Kqhcrkss3xnez6ukzwr/l78x63VQp+J7i Wbrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=B69yDU7DkmC/hI8CxGvYPIwu3CXE+4ZtI7ExHmRCJuE=; b=jBj0Bawqs+ccl18FhQs5cSOJaBD89v/7/aPB/QGbLPWW+u/ldWimT9d8dqz0VRDnmD F6kiDE5AnOXf7r6kA7FOu8NHVszX+5kwpFrWQv8XCLMIrG9sz5K0kLntlrGqt5SloYOl wH+CYBhN/Ng88W4yoH37rtgsd69FOg8YNdeedTCPQmlgJ1wCoZTJRWgNIBUiUa/USHvp +kXmnTgmgFRfSrZSrBe7wrKMV5ML57+CrVaH/zhv3cM345hsV1dMToSGTQCpM7Q+gVFG zyXPJW/yPPwBKdPVDlue03EhVLZwMO0l3ppijjz/4W55PJFx/IE4f9cSe9+BDycwbT3D XVDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a056402279200b0043b61fa24eesi4102748ede.615.2022.07.29.09.10.02; Fri, 29 Jul 2022 09:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237264AbiG2PkX (ORCPT + 99 others); Fri, 29 Jul 2022 11:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237434AbiG2Pju (ORCPT ); Fri, 29 Jul 2022 11:39:50 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5CC88E2E; Fri, 29 Jul 2022 08:39:11 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.0.0) id 7bdd6839dcc9557f; Fri, 29 Jul 2022 17:39:09 +0200 Received: from kreacher.localnet (unknown [213.134.162.35]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 553CC66CE09; Fri, 29 Jul 2022 17:39:08 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Viresh Kumar , Daniel Lezcano , Di Shen Subject: [PATCH] thermal: sysfs: Fix cooling_device_stats_setup() error code path Date: Fri, 29 Jul 2022 17:39:07 +0200 Message-ID: <2641456.mvXUDI8C0e@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.162.35 X-CLIENT-HOSTNAME: 213.134.162.35 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrudelkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeffffffkefgheehffelteeiveeffeevhfelteejvddvieejjeelvdeiheeuveeuffenucfkphepvddufedrudefgedrudeivddrfeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudeivddrfeehpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvhhirhgvshhhrdhkuhhmrghrsehlihhnrghrohdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepughi rdhshhgvnhesuhhnihhsohgtrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki If cooling_device_stats_setup() fails to create the stats object, it must clear the last slot in cooling_device_attr_groups that was initially empty (so as to make it possible to add stats attributes to the cooling device attribute groups). Failing to do so may cause the stats attributes to be created by mistake for a device that doesn't have a stats object, because the slot in question might be populated previously during the registration of another cooling device. Fixes: 8ea229511e06 ("thermal: Add cooling device's statistics in sysfs") Reported-by: Di Shen Tested-by: Di Shen Cc: 4.17+ # 4.17+ Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_sysfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -813,12 +813,13 @@ static const struct attribute_group cool static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) { + const struct attribute_group *stats_attr_group = NULL; struct cooling_dev_stats *stats; unsigned long states; int var; if (cdev->ops->get_max_state(cdev, &states)) - return; + goto out; states++; /* Total number of states is highest state + 1 */ @@ -828,7 +829,7 @@ static void cooling_device_stats_setup(s stats = kzalloc(var, GFP_KERNEL); if (!stats) - return; + goto out; stats->time_in_state = (ktime_t *)(stats + 1); stats->trans_table = (unsigned int *)(stats->time_in_state + states); @@ -838,9 +839,12 @@ static void cooling_device_stats_setup(s spin_lock_init(&stats->lock); + stats_attr_group = &cooling_device_stats_attr_group; + +out: /* Fill the empty slot left in cooling_device_attr_groups */ var = ARRAY_SIZE(cooling_device_attr_groups) - 2; - cooling_device_attr_groups[var] = &cooling_device_stats_attr_group; + cooling_device_attr_groups[var] = stats_attr_group; } static void cooling_device_stats_destroy(struct thermal_cooling_device *cdev)