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] [day] [month] [year] [list]
Message-ID: <CAJZ5v0gFTmJY0TzYkPeEWeeUVz+zMccnYEXHyvk-mV2ypWUwRg@mail.gmail.com>
Date:   Fri, 28 Oct 2022 19:42:51 +0200
From:   "Rafael J. Wysocki" <rafael@...nel.org>
To:     Qibo Huang <huangqibo.tech@...il.com>
Cc:     rafael@...nel.org, daniel.lezcano@...aro.org, amitk@...nel.org,
        rui.zhang@...el.com, linux-pm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] thermal/core: cooling device duplicate creation check

On Thu, Oct 27, 2022 at 5:17 AM Qibo Huang <huangqibo.tech@...il.com> wrote:
>
> Because creating a cooling device may have duplicate names.

Why is this a problem?

> When creating, first check thermal_cdev_list whether
> there is a device with the same name. If it has the same name,
> it returns a reference to the cooling device.

Why is this a correct and the best possible solution?

> Signed-off-by: Qibo Huang <huangqibo.tech@...il.com>
> ---
>  drivers/thermal/thermal_core.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 7e669b60a065..f38f9464e9f4 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -844,6 +844,34 @@ static void bind_cdev(struct thermal_cooling_device *cdev)
>         mutex_unlock(&thermal_list_lock);
>  }
>
> +struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name)
> +{
> +       struct thermal_cooling_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
> +       unsigned int found = 0;
> +
> +       if (!name)
> +               goto exit;
> +
> +       mutex_lock(&thermal_list_lock);
> +       list_for_each_entry(pos, &thermal_cdev_list, node)
> +               if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) {
> +                       found++;
> +                       ref = pos;
> +               }
> +       mutex_unlock(&thermal_list_lock);
> +
> +       /* nothing has been found, thus an error code for it */
> +       if (found == 0)
> +               ref = ERR_PTR(-ENODEV);
> +       else if (found > 1)
> +       /* Success only when an unique zone is found */
> +               ref = ERR_PTR(-EEXIST);
> +
> +exit:
> +       return ref;
> +}
> +EXPORT_SYMBOL_GPL(thermal_cdev_get_zone_by_name);
> +
>  /**
>   * __thermal_cooling_device_register() - register a new thermal cooling device
>   * @np:                a pointer to a device tree node.
> @@ -873,6 +901,12 @@ __thermal_cooling_device_register(struct device_node *np,
>             !ops->set_cur_state)
>                 return ERR_PTR(-EINVAL);
>
> +       if (type) {
> +               cdev = thermal_cdev_get_zone_by_name(type);
> +               if (!IS_ERR(cdev))
> +                       return cdev;
> +       }
> +
>         cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
>         if (!cdev)
>                 return ERR_PTR(-ENOMEM);
> --
> 2.37.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ