public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [bug report] thermal/x86_pkg_temp_thermal: Add support for handling dynamic tjmax
@ 2023-03-07 15:27 Dan Carpenter
  2023-03-08  3:15 ` Zhang, Rui
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2023-03-07 15:27 UTC (permalink / raw)
  To: rui.zhang; +Cc: linux-pm

Hello Zhang Rui,

The patch 58374a3970a0: "thermal/x86_pkg_temp_thermal: Add support
for handling dynamic tjmax" from Dec 19, 2022, leads to the following
Smatch static checker warning:

	drivers/thermal/intel/x86_pkg_temp_thermal.c:159 sys_set_trip_temp()
	warn: no lower bound on 'temp'

drivers/thermal/intel/x86_pkg_temp_thermal.c
    122 static int
    123 sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
    124 {
    125         struct zone_device *zonedev = tzd->devdata;
    126         u32 l, h, mask, shift, intr;
    127         int tj_max, ret;
    128 
    129         tj_max = intel_tcc_get_tjmax(zonedev->cpu);
    130         if (tj_max < 0)
    131                 return tj_max;
    132         tj_max *= 1000;
    133 
    134         if (trip >= MAX_NUMBER_OF_TRIPS || temp >= tj_max)

There is an upper bound on temp, but no lower bound.  The "temp"
variable comes from sysfs via the call tree:

  trip_point_temp_store()
  -> thermal_zone_set_trip()
     -> sys_set_trip_temp()

    135                 return -EINVAL;
    136 
    137         ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
    138                            &l, &h);
    139         if (ret < 0)
    140                 return ret;
    141 
    142         if (trip) {
    143                 mask = THERM_MASK_THRESHOLD1;
    144                 shift = THERM_SHIFT_THRESHOLD1;
    145                 intr = THERM_INT_THRESHOLD1_ENABLE;
    146         } else {
    147                 mask = THERM_MASK_THRESHOLD0;
    148                 shift = THERM_SHIFT_THRESHOLD0;
    149                 intr = THERM_INT_THRESHOLD0_ENABLE;
    150         }
    151         l &= ~mask;
    152         /*
    153         * When users space sets a trip temperature == 0, which is indication
    154         * that, it is no longer interested in receiving notifications.
    155         */
    156         if (!temp) {
    157                 l &= ~intr;
    158         } else {
--> 159                 l |= (tj_max - temp)/1000 << shift;
    160                 l |= intr;
    161         }
    162 
    163         return wrmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
    164                         l, h);
    165 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-08  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-07 15:27 [bug report] thermal/x86_pkg_temp_thermal: Add support for handling dynamic tjmax Dan Carpenter
2023-03-08  3:15 ` Zhang, Rui
2023-03-08  7:41   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox