Skip to contentSkip to conversation

thermal/drivers/intel: Use generic trip points int340x

bug report In review Dan Carpenter 3 participants 3 messages Jan 24, 2023 Thermal

lore
Share & tools
lore
#0 lore raw

Hello Daniel Lezcano,

The patch 0d568e144ead: "thermal/drivers/intel: Use generic trip points int340x" from Jan 13, 2023, leads to the following Smatch static checker warning:

	drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:137 int340x_thermal_zone_add()
	error: uninitialized symbol 'trip_cnt'.

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

    127         if (get_temp)
    128                 int34x_thermal_zone->ops->get_temp = get_temp;
    129 
    130         status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt);
    131         if (!ACPI_FAILURE(status)) {
    132                 int34x_thermal_zone->aux_trip_nr = trip_cnt;
    133                 trip_mask = BIT(trip_cnt) - 1;
    134         }

"trip_cnt" not initialized on error path.

    135 
    136         int34x_thermal_zone->trips = kzalloc(sizeof(*int34x_thermal_zone->trips) *
--> 137                                              (INT340X_THERMAL_MAX_TRIP_COUNT + trip_cnt),
                                                                                       ^^^^^^^^

    138                                               GFP_KERNEL);
    139         if (!int34x_thermal_zone->trips) {
    140                 ret = -ENOMEM;
    141                 goto err_trips_alloc;
    142         }
    143 
    144         trip_cnt = int340x_thermal_read_trips(int34x_thermal_zone);
    145 
    146         for (i = 0; i < trip_cnt; ++i)
    147                 int34x_thermal_zone->trips[i].hysteresis = thermal_acpi_trip_gtsh(adev);

regards,
dan carpenter

#1 lore raw

PATCH 1/1 thermal/drivers/int340x: Fix uninitialized trip_cnt variable

The conversion to the generic trip points missed to initializes the extra trip points to zero in case the _PATC method is not found.

Set by default the trip_cnt to zero.

---
 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +1 -1
index 7ff5d9b1c490..c113962a599e 100644
@@ -121,7 +121,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
 {
 	struct int34x_thermal_zone *int34x_thermal_zone;
 	acpi_status status;
-	unsigned long long trip_cnt;
+	unsigned long long trip_cnt = 0;
 	int trip_mask = 0;
 	int i, ret;
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH] thermal/drivers/int340x: Fix uninitialized trip_cnt variable

Quoted 3 lines · Daniel Lezcano

The conversion to the generic trip points missed to initializes the extra trip points to zero in case the _PATC method is not found.

The _PATC name is incorrect.

Quoted 12 lines

Set by default the trip_cnt to zero.

---
 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +0 -0
index 7ff5d9b1c490..c113962a599e 100644

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,

Quoted 9 lines
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +1 -2
@@ -121,7 +121,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
 {
        struct int34x_thermal_zone *int34x_thermal_zone;
        acpi_status status;
-       unsigned long long trip_cnt;
+       unsigned long long trip_cnt = 0;
        int trip_mask = 0;
        int i, ret;
 
--

I've just posted an equivalent fix and I prefer mine.