lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0i0gN-PnbAMDVxcGyWbWSTN0LCXvDNj_uhzYbSTxH=GGg@mail.gmail.com>
Date:   Wed, 9 Nov 2022 20:12:25 +0100
From:   "Rafael J. Wysocki" <rafael@...nel.org>
To:     Guenter Roeck <linux@...ck-us.net>
Cc:     "Rafael J . Wysocki" <rafael@...nel.org>,
        Daniel Lezcano <daniel.lezcano@...aro.org>,
        Amit Kucheria <amitk@...nel.org>,
        Zhang Rui <rui.zhang@...el.com>, linux-pm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/9] thermal/core: Move parameter validation from
 __thermal_zone_get_temp to thermal_zone_get_temp

On Mon, Oct 17, 2022 at 3:09 PM Guenter Roeck <linux@...ck-us.net> wrote:
>
> All callers of __thermal_zone_get_temp() already validated the
> thermal zone parameters. Move validation to thermal_zone_get_temp()
> where it is actually needed.
>
> Signed-off-by: Guenter Roeck <linux@...ck-us.net>
> ---
>  drivers/thermal/thermal_helpers.c | 26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
> index 3bac0b7a4c62..0161d5fb1cf2 100644
> --- a/drivers/thermal/thermal_helpers.c
> +++ b/drivers/thermal/thermal_helpers.c
> @@ -64,6 +64,20 @@ get_thermal_instance(struct thermal_zone_device *tz,
>  }
>  EXPORT_SYMBOL(get_thermal_instance);
>
> +/**
> + * __thermal_zone_get_temp() - returns the temperature of a thermal zone
> + * @tz: a valid pointer to a struct thermal_zone_device
> + * @temp: a valid pointer to where to store the resulting temperature.
> + *
> + * When a valid thermal zone reference is passed, it will fetch its
> + * temperature and fill @temp.
> + *
> + * Both tz and tz->ops must be valid pointers when calling this function,
> + * and the tz->ops->get_temp callback must be provided.
> + * The function must be called under tz->lock.
> + *
> + * Return: On success returns 0, an error code otherwise
> + */

I would mention adding the kerneldoc in the patch changelog.

>  int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
>         int ret = -EINVAL;
> @@ -73,9 +87,6 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
>
>         lockdep_assert_held(&tz->lock);
>
> -       if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
> -               return -EINVAL;
> -
>         ret = tz->ops->get_temp(tz, temp);
>
>         if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
> @@ -114,7 +125,16 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
>  {
>         int ret;
>
> +       if (!tz || IS_ERR(tz))

IS_ERR_OR_NULL() ?

> +               return -EINVAL;
> +
>         mutex_lock(&tz->lock);
> +
> +       if (!tz->ops->get_temp) {
> +               ret = -EINVAL;
> +               goto unlock;
> +       }
> +
>         if (!device_is_registered(&tz->device)) {
>                 ret = -ENODEV;
>                 goto unlock;
> --

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ