Merge branch 'thermal-testing'

Merge thermal control testing facility updates for 7.2:

 - Replace sscanf() with kstrtoul() or kstrtoint() in several places in
   the thermal testing code (Ovidiu Panait)

 - Make the thermal testing facility reject missing command arguments to
   avoid NULL pointer dereferences (Samuel Moelius)

* thermal-testing:
  thermal: sysfs: Replace sscanf() with kstrtoul()
  thermal: testing: Replace sscanf() with kstrtoint()
  thermal: testing: reject missing command arguments
This commit is contained in:
Rafael J. Wysocki 2026-06-11 18:21:22 +02:00
commit bc1c872ce0
3 changed files with 21 additions and 11 deletions

View File

@ -116,18 +116,30 @@ static int tt_command_exec(int index, const char *arg)
break;
case TT_CMD_DELTZ:
if (!arg || !*arg)
return -EINVAL;
ret = tt_del_tz(arg);
break;
case TT_CMD_TZADDTRIP:
if (!arg || !*arg)
return -EINVAL;
ret = tt_zone_add_trip(arg);
break;
case TT_CMD_TZREG:
if (!arg || !*arg)
return -EINVAL;
ret = tt_zone_reg(arg);
break;
case TT_CMD_TZUNREG:
if (!arg || !*arg)
return -EINVAL;
ret = tt_zone_unreg(arg);
break;

View File

@ -239,9 +239,9 @@ int tt_del_tz(const char *arg)
int ret;
int id;
ret = sscanf(arg, "%d", &id);
if (ret != 1)
return -EINVAL;
ret = kstrtoint(arg, 10, &id);
if (ret < 0)
return ret;
struct tt_work *tt_work __free(kfree) = kzalloc_obj(*tt_work);
if (!tt_work)
@ -279,9 +279,9 @@ static struct tt_thermal_zone *tt_get_tt_zone(const char *arg)
struct tt_thermal_zone *tt_zone;
int ret, id;
ret = sscanf(arg, "%d", &id);
if (ret != 1)
return ERR_PTR(-EINVAL);
ret = kstrtoint(arg, 10, &id);
if (ret < 0)
return ERR_PTR(ret);
guard(mutex)(&tt_thermal_zones_lock);

View File

@ -536,11 +536,9 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
unsigned long state;
int result;
if (sscanf(buf, "%ld\n", &state) != 1)
return -EINVAL;
if ((long)state < 0)
return -EINVAL;
result = kstrtoul(buf, 10, &state);
if (result < 0)
return result;
/* Requested state should be less than max_state + 1 */
if (state > cdev->max_state)