Message ID | 20230811084523.1689671-1-rui.zhang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp956135vqi; Fri, 11 Aug 2023 02:13:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIWSrUtgvSaknfrJCB5lq2ly3ofT2lcCb+mzk44vtDCGYHb0HSI0I3yCp46eCp0Y+xj913 X-Received: by 2002:a17:906:109b:b0:992:61c5:dab0 with SMTP id u27-20020a170906109b00b0099261c5dab0mr1010231eju.62.1691745207524; Fri, 11 Aug 2023 02:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691745207; cv=none; d=google.com; s=arc-20160816; b=S5F0Nz5dw2p2yOLiY6czPWPcyFgCCZn+/LPRM7bcytEKJny1IUoTstJZnT8Ww2m0fs CVShoHs9M1Q3P6pZybYKSt0qeZfhFGegyi5qmGSJIviyKI61/8Bhh87xvep4g/qOBBwC Lbka2QqXAJQQXZbsfY1SUeWIVWQ4fS78F0vzCWK3xoYOFjMFOltBhxot5SJW34MWFH6D EzYx13VNPTAQyvVK6If68dxVEgPYPSmwxqCLlf/Rx8h62r10PsTA4t821ENgBi4bu/Rr VpbNCWBdGXqRC4728mIxbMSameQjnBykLSgUdYOViR7ne/RF34Y2KoUEU+zmFZ6kAxIH ooLg== 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:dkim-signature; bh=5rgNwXVPoDzAohZk+hmwA0df1rPJYmyORZaEcRZ2Ow4=; fh=4VXEjKdTtZvdJuv1piSI/C6fhkuf5wcOx6Z3K8uxANU=; b=l0zUKQwQG3+3XNVaYjStbMKu82eC74bYe6ZQAQ6itgn9UjmAamizcPLtjs2cnYAp1F kPFu7wKFz3QYYa+TbLb4nfhBvwUVBoOBY077YZvpP4kcM+pXY1YVnuUbNkqX9y83sf/A kRgvo4lplupf6oTKmD8cUsA/tShPDeLFF4n7I8B4oR/D8Wmu4239jqdli5q/dHfMCGWV ekoXduNZXlcK4C9DwLwsW1urHNgdopXP94dum/83xVOqhhiU5SuZf0vpcU9NUs0gmh/O a4XjWMyeIJyXr2WxbLGBjBsOa5SEjB0S67GL6H4e6RNIsyiA3rtOFO2Ah3BFKXSIF9XU WPjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="akd/D3jY"; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z24-20020a1709064e1800b0099ba1cf9543si2922126eju.460.2023.08.11.02.13.02; Fri, 11 Aug 2023 02:13:27 -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=@intel.com header.s=Intel header.b="akd/D3jY"; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234084AbjHKIpk (ORCPT <rfc822;shaohuahua6@gmail.com> + 99 others); Fri, 11 Aug 2023 04:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbjHKIpi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 11 Aug 2023 04:45:38 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 828E52738; Fri, 11 Aug 2023 01:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691743538; x=1723279538; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=8vz5t52xNIp4mr/rEj23o9gWzLO26c4qJAjHt04rgXk=; b=akd/D3jYdetQfMiHUjpDpf7rt1iHV4U1YIErM6bgtm/ffhpBM1VQPQFZ GcqZymUCz6fD9vmumGflIhBBSW3TyaNUrCLNH3jYawCVTrBew/MKSX8/u GLQBNiE5p3qXdd1CAZ95+0986Bwu+7ie220t1vEMw4s41yPSfZ/sfMfOJ jWJQPh3AVdnIJr1qCpOwVMx4bUWaYmTdteNdsyM8HSP6lqjC3086sSZjd 1gtFik98nTYiAcxcm3k4EGK4N2ntrhLnlEVl9Blhm7evQ+fji3AopNZAG BRBMwoSEcYfr2LYmamejxiQSddd5+86qAtAfpRTm92VRuGhu9jl0etrqf g==; X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="351234626" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="351234626" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2023 01:45:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="822594658" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="822594658" Received: from llei-mobl1.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.254.214.187]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2023 01:45:35 -0700 From: Zhang Rui <rui.zhang@intel.com> To: rafael.j.wysocki@intel.com Cc: daniel.lezcano@linaro.or, srinivas.pandruvada@intel.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH] thermal: intel: intel_soc_dts_iosf: Fix thermal_zone removal Date: Fri, 11 Aug 2023 16:45:23 +0800 Message-Id: <20230811084523.1689671-1-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773923422692607233 X-GMAIL-MSGID: 1773923422692607233 |
Series |
thermal: intel: intel_soc_dts_iosf: Fix thermal_zone removal
|
|
Commit Message
Zhang, Rui
Aug. 11, 2023, 8:45 a.m. UTC
All of the existing callers of remove_dts_thermal_zone() pass a valid
pointer as the argument, so checking for the NULL pointer is redundant.
Plus, when calling remove_dts_thermal_zone() from
intel_soc_dts_iosf_init(), it is possible that
1. dts->tzone is an error pointer, when the sensor fails to be
registered as a valid thermal zone
2. dts->tzone is unregistered in add_dts_thermal_zone(), when some
failure occurs after thermal zone registered
In both cases, there is no need to unregister dts->tzone in
remove_dts_thermal_zone().
Clear dst->tzone when add_dts_thermal_zone() fails. And do thermal zone
removal in remove_dts_thermal_zone() only when dts->tzone is set.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
drivers/thermal/intel/intel_soc_dts_iosf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Fri, Aug 11, 2023 at 10:45 AM Zhang Rui <rui.zhang@intel.com> wrote: > > All of the existing callers of remove_dts_thermal_zone() pass a valid > pointer as the argument, so checking for the NULL pointer is redundant. True. > Plus, when calling remove_dts_thermal_zone() from > intel_soc_dts_iosf_init(), it is possible that > 1. dts->tzone is an error pointer, when the sensor fails to be > registered as a valid thermal zone > 2. dts->tzone is unregistered in add_dts_thermal_zone(), when some > failure occurs after thermal zone registered > In both cases, there is no need to unregister dts->tzone in > remove_dts_thermal_zone(). > > Clear dst->tzone when add_dts_thermal_zone() fails. And do thermal zone > removal in remove_dts_thermal_zone() only when dts->tzone is set. Well, I'm not sure. thermal_zone_device_unregister() will do nothing if the thermal zone is not really registered AFAICS and it is prudent to restore SOC_DTS_OFFSET_ENABLE on failure IMO. > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > --- > drivers/thermal/intel/intel_soc_dts_iosf.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c > index 7a66d0f077b0..c5203ba8f0b9 100644 > --- a/drivers/thermal/intel/intel_soc_dts_iosf.c > +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c > @@ -212,7 +212,7 @@ static int soc_dts_enable(int id) > > static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts) > { > - if (dts) { > + if (dts->tzone) { > iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, > SOC_DTS_OFFSET_ENABLE, dts->store_status); > thermal_zone_device_unregister(dts->tzone); > @@ -277,6 +277,7 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, > err_enable: > thermal_zone_device_unregister(dts->tzone); > err_ret: > + dts->tzone = NULL; > return ret; > } > > -- > 2.34.1 >
On Fri, 2023-08-11 at 18:55 +0200, Rafael J. Wysocki wrote: > On Fri, Aug 11, 2023 at 10:45 AM Zhang Rui <rui.zhang@intel.com> > wrote: > > > > All of the existing callers of remove_dts_thermal_zone() pass a > > valid > > pointer as the argument, so checking for the NULL pointer is > > redundant. > > True. > > > Plus, when calling remove_dts_thermal_zone() from > > intel_soc_dts_iosf_init(), it is possible that > > 1. dts->tzone is an error pointer, when the sensor fails to be > > registered as a valid thermal zone > > 2. dts->tzone is unregistered in add_dts_thermal_zone(), when some > > failure occurs after thermal zone registered > > In both cases, there is no need to unregister dts->tzone in > > remove_dts_thermal_zone(). > > > > Clear dst->tzone when add_dts_thermal_zone() fails. And do thermal > > zone > > removal in remove_dts_thermal_zone() only when dts->tzone is set. > > Well, I'm not sure. > > thermal_zone_device_unregister() will do nothing if the thermal zone > is not really registered AFAICS yes. > and it is prudent to restore > SOC_DTS_OFFSET_ENABLE on failure IMO. agreed. Refreshed patch sent. As this becomes really trivial, feel free to apply it or drop it. thanks, rui
diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index 7a66d0f077b0..c5203ba8f0b9 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -212,7 +212,7 @@ static int soc_dts_enable(int id) static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts) { - if (dts) { + if (dts->tzone) { iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, SOC_DTS_OFFSET_ENABLE, dts->store_status); thermal_zone_device_unregister(dts->tzone); @@ -277,6 +277,7 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, err_enable: thermal_zone_device_unregister(dts->tzone); err_ret: + dts->tzone = NULL; return ret; }