Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2889798rwb; Mon, 15 Aug 2022 13:23:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR4QHIx83j1FtoEfdno34JoIlks6T2GStGmEVdKWRp/euVfl3234R2lGXXAoJUomeAd8ha6J X-Received: by 2002:a17:907:2672:b0:734:a952:439a with SMTP id ci18-20020a170907267200b00734a952439amr11031668ejc.539.1660595026946; Mon, 15 Aug 2022 13:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660595026; cv=none; d=google.com; s=arc-20160816; b=ngGrtfCXSFgcrexaBFcO8qzHe52Wps1hEaI1PiCtKxKkzb/qpLpHF52Py8SEYj3PDf vWwsJaa2FJJYuU1mrLSARqO7KTkD6FD92X+QXaVppVfGxlWg9+s+4I/fpsPC9rfK/iyr dDwiHq6QnNjSn1IDFNwCx0RlVGDRHZegXMCI0eNxeTvIMQhU6p+Lcx/F5fJ31hh/fIlt 7zF4D/qr81SsbfH2i6rvlbRj+3xVHxTuTMNRdsv11zmZvz5NTH5juV2t01+SrpW6NmsG BJJtx8QULmxFoERpMDbXeXCGfF6El3QSbCCnF74T7J0mOtqiIkUfzzdkRa7Q1EKCs9IS s2zQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XRTzJesWlgiRmoNb6YQtw87KuhXdggCQnRXIPUyWKhc=; b=A9ItMLQK9MdOh4sra39NQytE90vgKPvudwDT0QkMxxW7eSEuHLhQ/7LczBn3wg0Bpx vSS1lsOQEyMsC0CjWCwt1M0PS26P5oXzsbjIbwxT54CkeYj8hlE8/K1uWQkWq/5kZjdh BlMaL09Ce77Zt7b01y5dYKndmNnzX05LFflehIHQ4p41lJsqR5UA9UrCPtFG40/SS22l 94vFb2NPq6e9YlRZ7qxMD0Aoq+uJHLW82yesQ4pGGGM0dHUcaexn/oD/WFikY1Zzt9D3 UyDGLEdYyePKMTGYA3cRWIJDdQpfGT1PRs5s9CTA8kfbJ8Uy9JwaxgzSXB3PDubfI1WV YHTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UQYQf6eN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a50d6d3000000b0043cae183e35si9032603edj.422.2022.08.15.13.23.17; Mon, 15 Aug 2022 13:23:46 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UQYQf6eN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243596AbiHOUOr (ORCPT + 99 others); Mon, 15 Aug 2022 16:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346050AbiHOUKn (ORCPT ); Mon, 15 Aug 2022 16:10:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 976192606; Mon, 15 Aug 2022 11:56:34 -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 547A1B81057; Mon, 15 Aug 2022 18:56:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80E9EC433D6; Mon, 15 Aug 2022 18:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589792; bh=aEfeu9f1lMXq8ZH7oRYczw5jkBVwbMgOJJdgiuGDQx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UQYQf6eNVGDTQ6XJEWX/pkRHwsto9xiN963OGO3K9AQ+eRUfEUEzVMXM0VyAN41VY TcM/chTtDzZyvFrEKrIazqsDePhvbLyoy+u8QHgp8iossHutFtNJLCkWVodIvPcZaT A5RJKKDSnYUX9xjLyYXj3k/q0qNlWdtkcT7WrdL8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Di Shen , "Rafael J. Wysocki" Subject: [PATCH 5.18 0049/1095] thermal: sysfs: Fix cooling_device_stats_setup() error code path Date: Mon, 15 Aug 2022 19:50:48 +0200 Message-Id: <20220815180431.491568771@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 commit d5a8aa5d7d80d21ab6b266f1bed4194b61746199 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/thermal_sysfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/thermal/thermal_sysfs.c +++ b/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)