[PATCH] thermal: int340x: Add Null check for adev

Chenyuan Yang posted 1 patch 11 months ago
drivers/thermal/intel/int340x_thermal/int3402_thermal.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] thermal: int340x: Add Null check for adev
Posted by Chenyuan Yang 11 months ago
Not all devices have an ACPI companion fwnode, so adev might be NULL.
This is similar to the commit cd2fd6eab480
("platform/x86: int3472: Check for adev == NULL").

Add a check for adev not being set and return -ENODEV in that case to
avoid a possible NULL pointer deref in int3402_thermal_probe().

Note, under the same directory, int3400_thermal_probe() has such a
check.

Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
---
 drivers/thermal/intel/int340x_thermal/int3402_thermal.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/thermal/intel/int340x_thermal/int3402_thermal.c b/drivers/thermal/intel/int340x_thermal/int3402_thermal.c
index 543b03960e99..57b90005888a 100644
--- a/drivers/thermal/intel/int340x_thermal/int3402_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3402_thermal.c
@@ -45,6 +45,9 @@ static int int3402_thermal_probe(struct platform_device *pdev)
 	struct int3402_thermal_data *d;
 	int ret;
 
+	if (!adev)
+		return -ENODEV;
+
 	if (!acpi_has_method(adev->handle, "_TMP"))
 		return -ENODEV;
 
-- 
2.34.1
Re: [PATCH] thermal: int340x: Add Null check for adev
Posted by Uwe Kleine-König 11 months ago
Hello,

On Wed, Mar 12, 2025 at 11:36:11PM -0500, Chenyuan Yang wrote:
> Not all devices have an ACPI companion fwnode, so adev might be NULL.
> This is similar to the commit cd2fd6eab480
> ("platform/x86: int3472: Check for adev == NULL").
> 
> Add a check for adev not being set and return -ENODEV in that case to
> avoid a possible NULL pointer deref in int3402_thermal_probe().
> 
> Note, under the same directory, int3400_thermal_probe() has such a
> check.
> 
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>

Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Fixes: 77e337c6e23e ("Thermal: introduce INT3402 thermal driver")

Best regards
Uwe
Re: [PATCH] thermal: int340x: Add Null check for adev
Posted by Rafael J. Wysocki 11 months ago
On Thu, Mar 13, 2025 at 9:37 AM Uwe Kleine-König
<u.kleine-koenig@baylibre.com> wrote:
>
> Hello,
>
> On Wed, Mar 12, 2025 at 11:36:11PM -0500, Chenyuan Yang wrote:
> > Not all devices have an ACPI companion fwnode, so adev might be NULL.
> > This is similar to the commit cd2fd6eab480
> > ("platform/x86: int3472: Check for adev == NULL").
> >
> > Add a check for adev not being set and return -ENODEV in that case to
> > avoid a possible NULL pointer deref in int3402_thermal_probe().
> >
> > Note, under the same directory, int3400_thermal_probe() has such a
> > check.
> >
> > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
>
> Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> Fixes: 77e337c6e23e ("Thermal: introduce INT3402 thermal driver")

Applied as 6.15 material, thanks!