Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3403387rwa; Tue, 23 Aug 2022 04:19:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR4cmm9jgqVnDdQrtsR8lOmQ0h8mD3rZ+xuBbfzrkTpjjZv6m987F6IbWCzn8VgX5cCvmMuI X-Received: by 2002:a17:90a:e58a:b0:1fa:c67c:6107 with SMTP id g10-20020a17090ae58a00b001fac67c6107mr2923025pjz.50.1661253552131; Tue, 23 Aug 2022 04:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253552; cv=none; d=google.com; s=arc-20160816; b=TFitdGDkfR3qqivCUJtpLoKlmTvyzHpXJPd4YxW1V6wl3k52DDSkEJRzXMzqAGaJ9R rjGoUvDdwruiSNoTfH1IJ0soSo7ZcF1NKHuBV/tRP6rYwF2OdaptynoC82QLuIqYfPeH ODkaV4Rl7rZLBDu88x2XJNJ6ugc4bprqqBAov5S0f6mvuocKkAspK4w9avEzWZ/7subM E5JVumyMqpXlEgm3uL9KpEm3z9Ey6otv/Q0GhFLRvSUpSih/M/wd7owcPe9Q9GbRhcz/ 7qdFBTPHOaQNZMtmGyR6ehYGgOMzmgMyUHt0iAN29W8slgb/knkwtLROpyru8MXUivfR Us4g== 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=WhGS+FWwganwlmSk6dUZyHA14drdB+hHL7ES6IziAKQ=; b=CI2Ba7U0yYv7bGQNXTvjy8UGznds6/I/dqFx+BBiR/sOlmn6JGoSiolc6/NT1HFhje KX4p/E7gDbp0F5fl7JvBX2AThRUf64sercv/PJT/5GQ/I/bbLQbCrpmiJIejIbTxYBM/ xdTmlG51Se9oMJyzt+3wklNgBm66EOwhc92o83T1o3R6h9u5F9Ys9qtFAcxBqWPLs5e0 IN0f6/q1zCsDz54PbjBcebFIrx2A8pIXVUEdAc6yjxWilj3IbrakH1sjDrnC3MYy8sQs 1mGew6ANOf+Ml4rven+3xRPTMprbVA7XQtDUz+zKze7/K0QjH1Ws0fE2OVMRSe+M8sTZ GMUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OtY3ulT0; 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 o16-20020a170902d4d000b00170a752cae8si13169348plg.115.2022.08.23.04.19.01; Tue, 23 Aug 2022 04:19:12 -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=OtY3ulT0; 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 S1355327AbiHWKbn (ORCPT + 99 others); Tue, 23 Aug 2022 06:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353636AbiHWKP0 (ORCPT ); Tue, 23 Aug 2022 06:15:26 -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 C711E6C76D; Tue, 23 Aug 2022 02:00:43 -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 63E9261524; Tue, 23 Aug 2022 09:00:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D166C433D6; Tue, 23 Aug 2022 09:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245242; bh=/LXsrzw1yxQGL9b1Zmq8Ccx2wUQqoyNaeI0G2abhPFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OtY3ulT05xSBEW003e5R4T3iwxP948MnrvURxGF4Zl1riZdUBJeYoHFE1onJrL827 bKHNg/x9ilUSQlWS1U8LhIfF077DrktlzDEiDjqYX85yOcM53L6qjRliGUq9XClXj/ Kbp0tF8YNlOP0n3Gvi9t9riDR9C44rUlrHgro4T8= 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 4.19 017/287] thermal: sysfs: Fix cooling_device_stats_setup() error code path Date: Tue, 23 Aug 2022 10:23:06 +0200 Message-Id: <20220823080100.860829216@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 @@ -909,12 +909,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 */ @@ -924,7 +925,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); @@ -934,9 +935,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)