Re: [PATCH 2/3] thermal: testing: Replace sscanf() with kstrtoint()
From: Rafael J. Wysocki
Date: Mon Jun 08 2026 - 10:07:34 EST
On Sat, Jun 6, 2026 at 11:05 PM Ovidiu Panait
<ovidiu.panait.oss@xxxxxxxxx> wrote:
>
> Fix the following checkpatch.pl warnings:
> WARNING: Prefer kstrto<type> to single variable sscanf
> 242: FILE: drivers/thermal/testing/zone.c:242:
> + ret = sscanf(arg, "%d", &id);
>
> WARNING: Prefer kstrto<type> to single variable sscanf
> 282: FILE: drivers/thermal/testing/zone.c:282:
> + ret = sscanf(arg, "%d", &id);
>
> Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@xxxxxxxxx>
> ---
> drivers/thermal/testing/zone.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/thermal/testing/zone.c b/drivers/thermal/testing/zone.c
> index 3c339242f52d..f7f9ca2f1f2c 100644
> --- a/drivers/thermal/testing/zone.c
> +++ b/drivers/thermal/testing/zone.c
> @@ -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);
>
> --
Applied as 7.2 material along with the [2/3].
However, please note that checkpatch.pl warnings regarding the
existing code are irrelevant, so I've rewritten the changelog of this
patch to indicate the preference to use kstrtoint() rather than refer
to the warnings.
Thanks!