Message ID | 20230329090055.7537-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:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp277187vqo; Wed, 29 Mar 2023 02:20:20 -0700 (PDT) X-Google-Smtp-Source: AKy350anZNyXe2WIUAL7cz2evoJYH2wQ8JBmbsdkIwN7gsJCEchctgWOAFib0hhAU5qCVADwPJBX X-Received: by 2002:a17:902:ced0:b0:19e:7a2c:78a7 with SMTP id d16-20020a170902ced000b0019e7a2c78a7mr20585511plg.57.1680081620599; Wed, 29 Mar 2023 02:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680081620; cv=none; d=google.com; s=arc-20160816; b=RWYjyE1zjReQ95lo0kM0s9GPyfj5qtU/gNI+kl8YeE85u+ZM0yGh+CoPjENKF5UlvZ B5KlUwn3yZDh21CZTJS1wuKQyWq91XlM0d5DHZVRo36sNdd6IoSncyN6537sNKyRaaiC CwKJxcTJ1gohevzM7OzwBJeblezS/fGkOvqeBp66ggFNXt0Ml0WnXXd8bCZR5rfiESFV AB6mbcu5cmkDlzvC0xExhfKEpiwAH5wxM4zguTiH5qQlLwMECjQa0AmO0lQEUDdtanKW PqMXhWFoBcrYSlc67XsoYIcpKgY1d49C4tcMSbhM2DjOOCZcuT3uk0NlTerfbapRUGEI NILw== 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=/em/cTbH5xFNgT5F0G1wwB8OubHKzw0ZFET6cLvYbI4=; b=b1utmNvGraOeR3KlX85pNemUUwsnvLgcuqfsnW8Dx2BMxfMK0jIA6zu2CJ41zJs5Vi Pfb1s5ffz2h1GdgEV8h0ag7yvBqGeebbENAe39QO5yLmwwn5DfARPyV73FZbjzr9VT2n CN7DTTCYQhEbNMlKiwEnee+Hr9Imo0F1aOUVejpMJVNJDzwwX0ZIdKSyVM6zeAc20e6B Jk1PhCOmrlZTOCirwhKgujv/noIFYUXPlZCaOtU7PUTnpDLuXvKrl08QPzWccaIXbaHE wmZKD7je9vv6/gby+W2QNLvwqj/8ikhSiaujQ1W7/FMgEXMstpHGfKUe2P2VxW2a2wCo eQUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VJvlDSum; 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 u8-20020a170903124800b0019f7977c9cfsi8654051plh.319.2023.03.29.02.20.07; Wed, 29 Mar 2023 02:20:20 -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=VJvlDSum; 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 S230096AbjC2JC0 (ORCPT <rfc822;rua109.linux@gmail.com> + 99 others); Wed, 29 Mar 2023 05:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjC2JCV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 29 Mar 2023 05:02:21 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46DD549C7; Wed, 29 Mar 2023 02:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680080509; x=1711616509; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=MpN+NoE8ltrbIOFRhoiH8RX1fmB1SfinxkoJtqy1yZQ=; b=VJvlDSumZvChIuQE72fkllLEKkkOVJkHZLdhTmR128bZ978zpCRHRUyR Msklf7Co3nNoy1WWs+vUuceDB9ocfnyPvIXwopKtPtnCKZ9gvSs5yKTiN E3awsYZ5bx5dRAImEgwl8t7ydZxjq8tJDOGAFFZzp4drQUpBotH7bSstQ u4g+oYUsXKrF3lEyAHHdwuQoqkRlcoJVKK+4bkXUbzDbzBnFljn7o2xyD Pw5ZIrZtfLfnBTIQagYLuQEN7KvSDQ6v9uC/tEOX7DC3fRV/mUdXoIMLf YeytPmGqGHRCbOZXZ0KeAJmhk0yniAf7ddqIY8qnOqG94BfM04uLcaVts Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="324726927" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="324726927" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 02:01:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="748717768" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="748717768" Received: from wenqin8x-mobl1.ccr.corp.intel.com (HELO rzhang1-DESK.intel.com) ([10.254.212.141]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 02:01:03 -0700 From: Zhang Rui <rui.zhang@intel.com> To: linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com, daniel.lezcano@linaro.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH -next] thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference Date: Wed, 29 Mar 2023 17:00:55 +0800 Message-Id: <20230329090055.7537-1-rui.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761693265315078001?= X-GMAIL-MSGID: =?utf-8?q?1761693265315078001?= |
Series |
[-next] thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference
|
|
Commit Message
Zhang, Rui
March 29, 2023, 9 a.m. UTC
When the hwmon device node of a thermal zone device is not found,
using hwmon->device causes a kernel NULL pointer dereference.
Reported-by: Preble Adam C <adam.c.preble@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field")
dec07d399cc8 is a commit in the linux-next branch of linux-pm repo.
I'm not sure if the Fix tag applies to such commit or not.
---
drivers/thermal/thermal_hwmon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 29/03/2023 11:00, Zhang Rui wrote: > When the hwmon device node of a thermal zone device is not found, > using hwmon->device causes a kernel NULL pointer dereference. > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > --- > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > I'm not sure if the Fix tag applies to such commit or not. Actually it reverts the work done to encapsulate the thermal zone device structure. > --- > drivers/thermal/thermal_hwmon.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c > index c59db17dddd6..261743f461be 100644 > --- a/drivers/thermal/thermal_hwmon.c > +++ b/drivers/thermal/thermal_hwmon.c > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) > hwmon = thermal_hwmon_lookup_by_type(tz); > if (unlikely(!hwmon)) { > /* Should never happen... */ > - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); > + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); As it 'Should never happen', I would replace that by: if (WARN_ON(!hwmon)) /* Should never happen... */ return; > return; > } >
On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 29/03/2023 11:00, Zhang Rui wrote: > > When the hwmon device node of a thermal zone device is not found, > > using hwmon->device causes a kernel NULL pointer dereference. > > > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > > --- > > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > > dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > > I'm not sure if the Fix tag applies to such commit or not. > > Actually it reverts the work done to encapsulate the thermal zone device > structure. > > > --- > > drivers/thermal/thermal_hwmon.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c > > index c59db17dddd6..261743f461be 100644 > > --- a/drivers/thermal/thermal_hwmon.c > > +++ b/drivers/thermal/thermal_hwmon.c > > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) > > hwmon = thermal_hwmon_lookup_by_type(tz); > > if (unlikely(!hwmon)) { > > /* Should never happen... */ > > - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); > > + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); > > As it 'Should never happen', I would replace that by: > > if (WARN_ON(!hwmon)) > /* Should never happen... */ > return; > Or just use pr_debug() instead of dev_dbg(). > > > return; > > } > >
On Wed, 2023-03-29 at 11:57 +0200, Daniel Lezcano wrote: > On 29/03/2023 11:00, Zhang Rui wrote: > > When the hwmon device node of a thermal zone device is not found, > > using hwmon->device causes a kernel NULL pointer dereference. > > > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > > --- > > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal > > zone structure field") > > dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > > I'm not sure if the Fix tag applies to such commit or not. > > Actually it reverts the work done to encapsulate the thermal zone > device > structure. > > > --- > > drivers/thermal/thermal_hwmon.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/thermal/thermal_hwmon.c > > b/drivers/thermal/thermal_hwmon.c > > index c59db17dddd6..261743f461be 100644 > > --- a/drivers/thermal/thermal_hwmon.c > > +++ b/drivers/thermal/thermal_hwmon.c > > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct > > thermal_zone_device *tz) > > hwmon = thermal_hwmon_lookup_by_type(tz); > > if (unlikely(!hwmon)) { > > /* Should never happen... */ > > - dev_dbg(hwmon->device, "hwmon device lookup > > failed!\n"); > > + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); > > As it 'Should never happen', I would replace that by: > > if (WARN_ON(!hwmon)) > /* Should never happen... */ > return; Actually, the comment is wrong. For thermal zones with tzp->no_hwmon set, this is always true. We should add an extra check for that. thanks, rui
On Wed, Mar 29, 2023 at 1:24 PM Zhang, Rui <rui.zhang@intel.com> wrote: > > On Wed, 2023-03-29 at 11:57 +0200, Daniel Lezcano wrote: > > On 29/03/2023 11:00, Zhang Rui wrote: > > > When the hwmon device node of a thermal zone device is not found, > > > using hwmon->device causes a kernel NULL pointer dereference. > > > > > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > > > --- > > > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal > > > zone structure field") > > > dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > > > I'm not sure if the Fix tag applies to such commit or not. > > > > Actually it reverts the work done to encapsulate the thermal zone > > device > > structure. > > > > > --- > > > drivers/thermal/thermal_hwmon.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/thermal/thermal_hwmon.c > > > b/drivers/thermal/thermal_hwmon.c > > > index c59db17dddd6..261743f461be 100644 > > > --- a/drivers/thermal/thermal_hwmon.c > > > +++ b/drivers/thermal/thermal_hwmon.c > > > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct > > > thermal_zone_device *tz) > > > hwmon = thermal_hwmon_lookup_by_type(tz); > > > if (unlikely(!hwmon)) { > > > /* Should never happen... */ > > > - dev_dbg(hwmon->device, "hwmon device lookup > > > failed!\n"); > > > + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); > > > > As it 'Should never happen', I would replace that by: > > > > if (WARN_ON(!hwmon)) > > /* Should never happen... */ > > return; > > Actually, the comment is wrong. > > For thermal zones with tzp->no_hwmon set, this is always true. > > We should add an extra check for that. OK, can you please send a patch fixing all this mess?
On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 29/03/2023 11:00, Zhang Rui wrote: > > When the hwmon device node of a thermal zone device is not found, > > using hwmon->device causes a kernel NULL pointer dereference. > > > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > > --- > > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > > dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > > I'm not sure if the Fix tag applies to such commit or not. > > Actually it reverts the work done to encapsulate the thermal zone device > structure. So maybe instead of the wholesale switch to using "driver-specific" device pointers for printing messages, something like thermal_zone_debug/info/warn/error() taking a thermal zone pointer as the first argument can be defined? At least this particular bug could be avoided this way. > > --- > > drivers/thermal/thermal_hwmon.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c > > index c59db17dddd6..261743f461be 100644 > > --- a/drivers/thermal/thermal_hwmon.c > > +++ b/drivers/thermal/thermal_hwmon.c > > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) > > hwmon = thermal_hwmon_lookup_by_type(tz); > > if (unlikely(!hwmon)) { > > /* Should never happen... */ > > - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); > > + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); > > As it 'Should never happen', I would replace that by: > > if (WARN_ON(!hwmon)) > /* Should never happen... */ > return; > > > > > return; > > } > > > > -- > <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs > > Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | > <http://twitter.com/#!/linaroorg> Twitter | > <http://www.linaro.org/linaro-blog/> Blog >
On Wed, 2023-03-29 at 14:06 +0200, Rafael J. Wysocki wrote: > On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: > > On 29/03/2023 11:00, Zhang Rui wrote: > > > When the hwmon device node of a thermal zone device is not found, > > > using hwmon->device causes a kernel NULL pointer dereference. > > > > > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > > > --- > > > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal > > > thermal zone structure field") > > > dec07d399cc8 is a commit in the linux-next branch of linux-pm > > > repo. > > > I'm not sure if the Fix tag applies to such commit or not. > > > > Actually it reverts the work done to encapsulate the thermal zone > > device > > structure. > > So maybe instead of the wholesale switch to using "driver-specific" > device pointers for printing messages, something like > thermal_zone_debug/info/warn/error() taking a thermal zone pointer as > the first argument can be defined? > > At least this particular bug could be avoided this way. I didn't see your email before sending patch v2. are we going to rework the previous series from Daniel thus patch v2 is no longer needed? thanks, rui > > > > --- > > > drivers/thermal/thermal_hwmon.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/thermal/thermal_hwmon.c > > > b/drivers/thermal/thermal_hwmon.c > > > index c59db17dddd6..261743f461be 100644 > > > --- a/drivers/thermal/thermal_hwmon.c > > > +++ b/drivers/thermal/thermal_hwmon.c > > > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct > > > thermal_zone_device *tz) > > > hwmon = thermal_hwmon_lookup_by_type(tz); > > > if (unlikely(!hwmon)) { > > > /* Should never happen... */ > > > - dev_dbg(hwmon->device, "hwmon device lookup > > > failed!\n"); > > > + dev_dbg(&tz->device, "hwmon device lookup > > > failed!\n"); > > > > As it 'Should never happen', I would replace that by: > > > > if (WARN_ON(!hwmon)) > > /* Should never happen... */ > > return; > > > > > > > > > return; > > > } > > > > > > > -- > > <http://www.linaro.org/> Linaro.org │ Open source software for ARM > > SoCs > > > > Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | > > <http://twitter.com/#!/linaroorg> Twitter | > > <http://www.linaro.org/linaro-blog/> Blog > >
On Wed, Mar 29, 2023 at 2:33 PM Zhang, Rui <rui.zhang@intel.com> wrote: > > On Wed, 2023-03-29 at 14:06 +0200, Rafael J. Wysocki wrote: > > On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano > > <daniel.lezcano@linaro.org> wrote: > > > On 29/03/2023 11:00, Zhang Rui wrote: > > > > When the hwmon device node of a thermal zone device is not found, > > > > using hwmon->device causes a kernel NULL pointer dereference. > > > > > > > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > > > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > > > > --- > > > > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal > > > > thermal zone structure field") > > > > dec07d399cc8 is a commit in the linux-next branch of linux-pm > > > > repo. > > > > I'm not sure if the Fix tag applies to such commit or not. > > > > > > Actually it reverts the work done to encapsulate the thermal zone > > > device > > > structure. > > > > So maybe instead of the wholesale switch to using "driver-specific" > > device pointers for printing messages, something like > > thermal_zone_debug/info/warn/error() taking a thermal zone pointer as > > the first argument can be defined? > > > > At least this particular bug could be avoided this way. > > I didn't see your email before sending patch v2. > > are we going to rework the previous series from Daniel thus patch v2 is > no longer needed? Well, let's see what Daniel says.. In any case, though, it is not very useful to carry an obvious NULL pointer dereference in linux-next and the pr_debug() statement added by the v2 can be replaced later, so I think I'll apply it.
On 29/03/2023 14:06, Rafael J. Wysocki wrote: > On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: >> >> On 29/03/2023 11:00, Zhang Rui wrote: >>> When the hwmon device node of a thermal zone device is not found, >>> using hwmon->device causes a kernel NULL pointer dereference. >>> >>> Reported-by: Preble Adam C <adam.c.preble@intel.com> >>> Signed-off-by: Zhang Rui <rui.zhang@intel.com> >>> --- >>> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") >>> dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. >>> I'm not sure if the Fix tag applies to such commit or not. >> >> Actually it reverts the work done to encapsulate the thermal zone device >> structure. > > So maybe instead of the wholesale switch to using "driver-specific" > device pointers for printing messages, something like > thermal_zone_debug/info/warn/error() taking a thermal zone pointer as > the first argument can be defined? > > At least this particular bug could be avoided this way. Actually we previously said the thermal_hwmon can be considered as part of the thermal core code, so we can keep using tz->device. I'll drop this change from the series. On the other side, adding more thermal_zone_debug/info.. gives opportunities to external components of the core thermal framework to write thermal zone device related message. I'm not sure that is a good thing, each writer should stay in its namespace, no ? >>> --- >>> drivers/thermal/thermal_hwmon.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c >>> index c59db17dddd6..261743f461be 100644 >>> --- a/drivers/thermal/thermal_hwmon.c >>> +++ b/drivers/thermal/thermal_hwmon.c >>> @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) >>> hwmon = thermal_hwmon_lookup_by_type(tz); >>> if (unlikely(!hwmon)) { >>> /* Should never happen... */ >>> - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); >>> + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); >> >> As it 'Should never happen', I would replace that by: >> >> if (WARN_ON(!hwmon)) >> /* Should never happen... */ >> return; >> >> >> >>> return; >>> } >>> >> >> -- >> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs >> >> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | >> <http://twitter.com/#!/linaroorg> Twitter | >> <http://www.linaro.org/linaro-blog/> Blog >>
On Wed, Mar 29, 2023 at 4:16 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 29/03/2023 14:06, Rafael J. Wysocki wrote: > > On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano > > <daniel.lezcano@linaro.org> wrote: > >> > >> On 29/03/2023 11:00, Zhang Rui wrote: > >>> When the hwmon device node of a thermal zone device is not found, > >>> using hwmon->device causes a kernel NULL pointer dereference. > >>> > >>> Reported-by: Preble Adam C <adam.c.preble@intel.com> > >>> Signed-off-by: Zhang Rui <rui.zhang@intel.com> > >>> --- > >>> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > >>> dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > >>> I'm not sure if the Fix tag applies to such commit or not. > >> > >> Actually it reverts the work done to encapsulate the thermal zone device > >> structure. > > > > So maybe instead of the wholesale switch to using "driver-specific" > > device pointers for printing messages, something like > > thermal_zone_debug/info/warn/error() taking a thermal zone pointer as > > the first argument can be defined? > > > > At least this particular bug could be avoided this way. > > Actually we previously said the thermal_hwmon can be considered as part > of the thermal core code, so we can keep using tz->device. > > I'll drop this change from the series. But it's there in my thermal branch already. Do you want to revert the thermal_hwmon.c part of commit dec07d399cc8? > On the other side, adding more thermal_zone_debug/info.. gives > opportunities to external components of the core thermal framework to > write thermal zone device related message. I'm not sure that is a good > thing, each writer should stay in its namespace, no ? IMV whoever is allowed to use a thermal zone pointer should also be allowed to print messages related to its use, especially debug ones. "Encapsulation" means that the members of a thermal zone device object should not be accessed directly by its users other than the core, not that it cannot be used as a message tag.
On 29/03/2023 16:38, Rafael J. Wysocki wrote: > On Wed, Mar 29, 2023 at 4:16 PM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: >> >> On 29/03/2023 14:06, Rafael J. Wysocki wrote: >>> On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano >>> <daniel.lezcano@linaro.org> wrote: >>>> >>>> On 29/03/2023 11:00, Zhang Rui wrote: >>>>> When the hwmon device node of a thermal zone device is not found, >>>>> using hwmon->device causes a kernel NULL pointer dereference. >>>>> >>>>> Reported-by: Preble Adam C <adam.c.preble@intel.com> >>>>> Signed-off-by: Zhang Rui <rui.zhang@intel.com> >>>>> --- >>>>> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") >>>>> dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. >>>>> I'm not sure if the Fix tag applies to such commit or not. >>>> >>>> Actually it reverts the work done to encapsulate the thermal zone device >>>> structure. >>> >>> So maybe instead of the wholesale switch to using "driver-specific" >>> device pointers for printing messages, something like >>> thermal_zone_debug/info/warn/error() taking a thermal zone pointer as >>> the first argument can be defined? >>> >>> At least this particular bug could be avoided this way. >> >> Actually we previously said the thermal_hwmon can be considered as part >> of the thermal core code, so we can keep using tz->device. >> >> I'll drop this change from the series. > > But it's there in my thermal branch already. > > Do you want to revert the thermal_hwmon.c part of commit dec07d399cc8? Oh, right. Fair enough. I think Rui's patch is fine then. >> On the other side, adding more thermal_zone_debug/info.. gives >> opportunities to external components of the core thermal framework to >> write thermal zone device related message. I'm not sure that is a good >> thing, each writer should stay in its namespace, no ? > > IMV whoever is allowed to use a thermal zone pointer should also be > allowed to print messages related to its use, especially debug ones. > > "Encapsulation" means that the members of a thermal zone device object > should not be accessed directly by its users other than the core, not > that it cannot be used as a message tag. Actually it is not about the encapsulation but the namespace of the messages. If a driver has an issue, IMO it is better it uses the device related messages and let thermal zone messages to be related to what is happening in the thermal framework, not in the back end.
On 29/03/2023 11:00, Zhang Rui wrote: > When the hwmon device node of a thermal zone device is not found, > using hwmon->device causes a kernel NULL pointer dereference. > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > Signed-off-by: Zhang Rui <rui.zhang@intel.com> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org> > --- > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > I'm not sure if the Fix tag applies to such commit or not. > --- > drivers/thermal/thermal_hwmon.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c > index c59db17dddd6..261743f461be 100644 > --- a/drivers/thermal/thermal_hwmon.c > +++ b/drivers/thermal/thermal_hwmon.c > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) > hwmon = thermal_hwmon_lookup_by_type(tz); > if (unlikely(!hwmon)) { > /* Should never happen... */ > - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); > + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); > return; > } >
On Wed, Mar 29, 2023 at 5:59 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 29/03/2023 16:38, Rafael J. Wysocki wrote: > > On Wed, Mar 29, 2023 at 4:16 PM Daniel Lezcano > > <daniel.lezcano@linaro.org> wrote: > >> > >> On 29/03/2023 14:06, Rafael J. Wysocki wrote: > >>> On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano > >>> <daniel.lezcano@linaro.org> wrote: > >>>> > >>>> On 29/03/2023 11:00, Zhang Rui wrote: > >>>>> When the hwmon device node of a thermal zone device is not found, > >>>>> using hwmon->device causes a kernel NULL pointer dereference. > >>>>> > >>>>> Reported-by: Preble Adam C <adam.c.preble@intel.com> > >>>>> Signed-off-by: Zhang Rui <rui.zhang@intel.com> > >>>>> --- > >>>>> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > >>>>> dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > >>>>> I'm not sure if the Fix tag applies to such commit or not. > >>>> > >>>> Actually it reverts the work done to encapsulate the thermal zone device > >>>> structure. > >>> > >>> So maybe instead of the wholesale switch to using "driver-specific" > >>> device pointers for printing messages, something like > >>> thermal_zone_debug/info/warn/error() taking a thermal zone pointer as > >>> the first argument can be defined? > >>> > >>> At least this particular bug could be avoided this way. > >> > >> Actually we previously said the thermal_hwmon can be considered as part > >> of the thermal core code, so we can keep using tz->device. > >> > >> I'll drop this change from the series. > > > > But it's there in my thermal branch already. > > > > Do you want to revert the thermal_hwmon.c part of commit dec07d399cc8? > > Oh, right. Fair enough. > > I think Rui's patch is fine then. I guess you mean the $subject one, that is: https://patchwork.kernel.org/project/linux-pm/patch/20230329090055.7537-1-rui.zhang@intel.com What about the message printed when temp is NULL. Should the original form of it be restored too? > >> On the other side, adding more thermal_zone_debug/info.. gives > >> opportunities to external components of the core thermal framework to > >> write thermal zone device related message. I'm not sure that is a good > >> thing, each writer should stay in its namespace, no ? > > > > IMV whoever is allowed to use a thermal zone pointer should also be > > allowed to print messages related to its use, especially debug ones. > > > > "Encapsulation" means that the members of a thermal zone device object > > should not be accessed directly by its users other than the core, not > > that it cannot be used as a message tag. > > Actually it is not about the encapsulation but the namespace of the > messages. If a driver has an issue, IMO it is better it uses the device > related messages and let thermal zone messages to be related to what is > happening in the thermal framework, not in the back end. > > > > -- > <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs > > Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | > <http://twitter.com/#!/linaroorg> Twitter | > <http://www.linaro.org/linaro-blog/> Blog >
On 29/03/2023 18:03, Rafael J. Wysocki wrote: > On Wed, Mar 29, 2023 at 5:59 PM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: >> >> On 29/03/2023 16:38, Rafael J. Wysocki wrote: >>> On Wed, Mar 29, 2023 at 4:16 PM Daniel Lezcano >>> <daniel.lezcano@linaro.org> wrote: >>>> >>>> On 29/03/2023 14:06, Rafael J. Wysocki wrote: >>>>> On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano >>>>> <daniel.lezcano@linaro.org> wrote: >>>>>> >>>>>> On 29/03/2023 11:00, Zhang Rui wrote: >>>>>>> When the hwmon device node of a thermal zone device is not found, >>>>>>> using hwmon->device causes a kernel NULL pointer dereference. >>>>>>> >>>>>>> Reported-by: Preble Adam C <adam.c.preble@intel.com> >>>>>>> Signed-off-by: Zhang Rui <rui.zhang@intel.com> >>>>>>> --- >>>>>>> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") >>>>>>> dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. >>>>>>> I'm not sure if the Fix tag applies to such commit or not. >>>>>> >>>>>> Actually it reverts the work done to encapsulate the thermal zone device >>>>>> structure. >>>>> >>>>> So maybe instead of the wholesale switch to using "driver-specific" >>>>> device pointers for printing messages, something like >>>>> thermal_zone_debug/info/warn/error() taking a thermal zone pointer as >>>>> the first argument can be defined? >>>>> >>>>> At least this particular bug could be avoided this way. >>>> >>>> Actually we previously said the thermal_hwmon can be considered as part >>>> of the thermal core code, so we can keep using tz->device. >>>> >>>> I'll drop this change from the series. >>> >>> But it's there in my thermal branch already. >>> >>> Do you want to revert the thermal_hwmon.c part of commit dec07d399cc8? >> >> Oh, right. Fair enough. >> >> I think Rui's patch is fine then. > > I guess you mean the $subject one, that is: > > https://patchwork.kernel.org/project/linux-pm/patch/20230329090055.7537-1-rui.zhang@intel.com Correct > What about the message printed when temp is NULL. Should the original > form of it be restored too? Yes, you are right, for the sake of consistency we should restore also this one.
On Wed, Mar 29, 2023 at 6:03 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 29/03/2023 11:00, Zhang Rui wrote: > > When the hwmon device node of a thermal zone device is not found, > > using hwmon->device causes a kernel NULL pointer dereference. > > > > Reported-by: Preble Adam C <adam.c.preble@intel.com> > > Signed-off-by: Zhang Rui <rui.zhang@intel.com> > > Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org> Applied, thanks! > > --- > > Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > > dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > > I'm not sure if the Fix tag applies to such commit or not. > > --- > > drivers/thermal/thermal_hwmon.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c > > index c59db17dddd6..261743f461be 100644 > > --- a/drivers/thermal/thermal_hwmon.c > > +++ b/drivers/thermal/thermal_hwmon.c > > @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) > > hwmon = thermal_hwmon_lookup_by_type(tz); > > if (unlikely(!hwmon)) { > > /* Should never happen... */ > > - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); > > + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); > > return; > > } > > > > -- > <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs > > Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | > <http://twitter.com/#!/linaroorg> Twitter | > <http://www.linaro.org/linaro-blog/> Blog >
On Wednesday, March 29, 2023 6:18:31 PM CEST Daniel Lezcano wrote: > On 29/03/2023 18:03, Rafael J. Wysocki wrote: > > On Wed, Mar 29, 2023 at 5:59 PM Daniel Lezcano > > <daniel.lezcano@linaro.org> wrote: > >> > >> On 29/03/2023 16:38, Rafael J. Wysocki wrote: > >>> On Wed, Mar 29, 2023 at 4:16 PM Daniel Lezcano > >>> <daniel.lezcano@linaro.org> wrote: > >>>> > >>>> On 29/03/2023 14:06, Rafael J. Wysocki wrote: > >>>>> On Wed, Mar 29, 2023 at 11:57 AM Daniel Lezcano > >>>>> <daniel.lezcano@linaro.org> wrote: > >>>>>> > >>>>>> On 29/03/2023 11:00, Zhang Rui wrote: > >>>>>>> When the hwmon device node of a thermal zone device is not found, > >>>>>>> using hwmon->device causes a kernel NULL pointer dereference. > >>>>>>> > >>>>>>> Reported-by: Preble Adam C <adam.c.preble@intel.com> > >>>>>>> Signed-off-by: Zhang Rui <rui.zhang@intel.com> > >>>>>>> --- > >>>>>>> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") > >>>>>>> dec07d399cc8 is a commit in the linux-next branch of linux-pm repo. > >>>>>>> I'm not sure if the Fix tag applies to such commit or not. > >>>>>> > >>>>>> Actually it reverts the work done to encapsulate the thermal zone device > >>>>>> structure. > >>>>> > >>>>> So maybe instead of the wholesale switch to using "driver-specific" > >>>>> device pointers for printing messages, something like > >>>>> thermal_zone_debug/info/warn/error() taking a thermal zone pointer as > >>>>> the first argument can be defined? > >>>>> > >>>>> At least this particular bug could be avoided this way. > >>>> > >>>> Actually we previously said the thermal_hwmon can be considered as part > >>>> of the thermal core code, so we can keep using tz->device. > >>>> > >>>> I'll drop this change from the series. > >>> > >>> But it's there in my thermal branch already. > >>> > >>> Do you want to revert the thermal_hwmon.c part of commit dec07d399cc8? > >> > >> Oh, right. Fair enough. > >> > >> I think Rui's patch is fine then. > > > > I guess you mean the $subject one, that is: > > > > https://patchwork.kernel.org/project/linux-pm/patch/20230329090055.7537-1-rui.zhang@intel.com > > Correct > > > What about the message printed when temp is NULL. Should the original > > form of it be restored too? > > Yes, you are right, for the sake of consistency we should restore also > this one. So I'm going to apply the appended patch. Please let me know if there are any concerns regarding it. --- From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Subject: [PATCH] thermal: thermal_hwmon: Revert recent message adjustment For the sake of consistency, revert the second part of the thermal_hwmon.c hunk from commit dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field") after the first part of it has been reverted. Link: https://lore.kernel.org/linux-pm/5b084360-898b-aad0-0b8e-33acc585d71d@linaro.org Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> --- drivers/thermal/thermal_hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux-pm/drivers/thermal/thermal_hwmon.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_hwmon.c +++ linux-pm/drivers/thermal/thermal_hwmon.c @@ -236,7 +236,7 @@ void thermal_remove_hwmon_sysfs(struct t temp = thermal_hwmon_lookup_temp(hwmon, tz); if (unlikely(!temp)) { /* Should never happen... */ - dev_dbg(hwmon->device, "temperature input lookup failed!\n"); + dev_dbg(&tz->device, "temperature input lookup failed!\n"); return; }
On 29/03/2023 19:43, Rafael J. Wysocki wrote: [ ... ] >>> What about the message printed when temp is NULL. Should the original >>> form of it be restored too? >> >> Yes, you are right, for the sake of consistency we should restore also >> this one. > > So I'm going to apply the appended patch. > > Please let me know if there are any concerns regarding it. > > --- > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > Subject: [PATCH] thermal: thermal_hwmon: Revert recent message adjustment > > For the sake of consistency, revert the second part of the > thermal_hwmon.c hunk from commit dec07d399cc8 ("thermal: Don't use > 'device' internal thermal zone structure field") after the first > part of it has been reverted. > > Link: https://lore.kernel.org/linux-pm/5b084360-898b-aad0-0b8e-33acc585d71d@linaro.org > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org> > --- > drivers/thermal/thermal_hwmon.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > Index: linux-pm/drivers/thermal/thermal_hwmon.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_hwmon.c > +++ linux-pm/drivers/thermal/thermal_hwmon.c > @@ -236,7 +236,7 @@ void thermal_remove_hwmon_sysfs(struct t > temp = thermal_hwmon_lookup_temp(hwmon, tz); > if (unlikely(!temp)) { > /* Should never happen... */ > - dev_dbg(hwmon->device, "temperature input lookup failed!\n"); > + dev_dbg(&tz->device, "temperature input lookup failed!\n"); > return; > }
diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index c59db17dddd6..261743f461be 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -229,7 +229,7 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) hwmon = thermal_hwmon_lookup_by_type(tz); if (unlikely(!hwmon)) { /* Should never happen... */ - dev_dbg(hwmon->device, "hwmon device lookup failed!\n"); + dev_dbg(&tz->device, "hwmon device lookup failed!\n"); return; }