Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1862030rwb; Fri, 19 Aug 2022 10:36:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR55aG8nZ5zetVm2HMAVNAONxr1wqWfnUV6w4KQfHmdRHwIyK+TxZpxHt6eh51Ko6mFhV3ZI X-Received: by 2002:a65:5ac4:0:b0:41b:af7f:125 with SMTP id d4-20020a655ac4000000b0041baf7f0125mr7133653pgt.224.1660930611754; Fri, 19 Aug 2022 10:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930611; cv=none; d=google.com; s=arc-20160816; b=iDNJvAVPKPsnbwrPAx9VnFrYIvY5MtxunB6XLQMwsRf95HMxbo3qZuIR8nNTdSPZYv 7AQ9ejHqsnO28uSU4CpUOP+FGwgRSVIHwWvUxmNUrrAAPJWKZRmsnUhawzwM+aohPgeJ Dn42gIsnMlkKnRGVV1KLbcdD/3TjO6IkRAyhnXNAZLjnyhPkH7Wrg9F5ZL4+Jk3RU9Pt pv78B9F7P7UR+83Hd0/ELHewW53/wR2xVGoVpz0f1BKA84kC5bqVYJSJ7ysROSob5Omb rA4YiQRnVTntpoSsnI/h5omN8Kg8rxEjs87QHGCi7k89x9qasdoYeETeQ+y8xGlwTh0A mLPw== 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=lx2ale1fhemJnF906RRgYqwdAMwZ1r1Aertw3S6Safk=; b=JxEVt8moh6PBRQR7GGzQ2Bv7E9DWvOKgqMdsypxeB6Em9g+kXD12702PeRXcHBttfe fGFjtjCY7xxGYoQNLHo64Gra6tGI5CtkP4U8zbTtSfVZQN4lQKyqM5EVIIUmZEwiOxj1 qmZ9j+kK07FXEXMYPNUL0xH9/ZwQ5rlAN/toSk370XRWnRWfMYYHdTPT0Hl22YoVq5ac NwZOn6QuDVkGeCfNo06rVB8UpQZm+c8ipAEzBn7imYbuKkJ7S7sqfyJrwOQ72X2Hq4Cs tcLDoxBsMRQdRMbyks45L6DlTnQwb8moLcS2PYO0CbDNF3jDLXioKBy/0ZOdO5Mb1WPl 775g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o30tEwcL; 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 d4-20020a633604000000b0041dd0c35c54si2687465pga.47.2022.08.19.10.36.40; Fri, 19 Aug 2022 10:36:51 -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=o30tEwcL; 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 S1350285AbiHSPtL (ORCPT + 99 others); Fri, 19 Aug 2022 11:49:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350240AbiHSPsP (ORCPT ); Fri, 19 Aug 2022 11:48:15 -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 9B57C4F6A9; Fri, 19 Aug 2022 08:47:17 -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 836AB61639; Fri, 19 Aug 2022 15:47:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8755FC433D7; Fri, 19 Aug 2022 15:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924035; bh=uFzZxa1DAsAnpje1oj5nJcTTkB2cg0MgAfOakmIud/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o30tEwcLveoGo+1OSwcZu+Mf6XTK8gopyU7ghSVx3J8QqhMRYH6EyPZ2Hf36Oi3rj PoskkjRMPCzqAg4PMyDlZvy46kxIVITDubje4/5LWTdcksQdoTN7H6kHAJ29v8B2LW ZVv1Za3pCzuUWIPRs7k0yJLPNfB+Ayb/Bty7Vn7I= 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.10 034/545] thermal: sysfs: Fix cooling_device_stats_setup() error code path Date: Fri, 19 Aug 2022 17:36:44 +0200 Message-Id: <20220819153830.732191026@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 @@ -893,12 +893,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 */ @@ -908,7 +909,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); @@ -918,9 +919,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)