[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAJZ5v0ija9YPhU-700a+7iDzGP+7ECrgrKim0z+vadS16wONxA@mail.gmail.com>
Date: Fri, 20 Jan 2023 14:58:25 +0100
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Yang Yingliang <yangyingliang@...wei.com>
Cc: linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
rafael@...nel.org, srinivas.pandruvada@...ux.intel.com,
jacob.jun.pan@...ux.intel.com, gregkh@...uxfoundation.org
Subject: Re: [PATCH] powercap: fix possible name leak in powercap_register_zone()
On Tue, Jan 3, 2023 at 1:38 PM Yang Yingliang <yangyingliang@...wei.com> wrote:
>
> In the error path after calling dev_set_name(), the device
> name is leaked. To fix this, calling dev_set_name() before
> device_register(), and call put_device() if it returns error.
> All the resources is released in powercap_release(), so it
> can return from powercap_register_zone() directly.
>
> Fixes: 75d2364ea0ca ("PowerCap: Add class driver")
> Signed-off-by: Yang Yingliang <yangyingliang@...wei.com>
> ---
> drivers/powercap/powercap_sys.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
> index 1f968353d479..e180dee0f83d 100644
> --- a/drivers/powercap/powercap_sys.c
> +++ b/drivers/powercap/powercap_sys.c
> @@ -530,9 +530,6 @@ struct powercap_zone *powercap_register_zone(
> power_zone->name = kstrdup(name, GFP_KERNEL);
> if (!power_zone->name)
> goto err_name_alloc;
> - dev_set_name(&power_zone->dev, "%s:%x",
> - dev_name(power_zone->dev.parent),
> - power_zone->id);
> power_zone->constraints = kcalloc(nr_constraints,
> sizeof(*power_zone->constraints),
> GFP_KERNEL);
> @@ -555,9 +552,16 @@ struct powercap_zone *powercap_register_zone(
> power_zone->dev_attr_groups[0] = &power_zone->dev_zone_attr_group;
> power_zone->dev_attr_groups[1] = NULL;
> power_zone->dev.groups = power_zone->dev_attr_groups;
> + dev_set_name(&power_zone->dev, "%s:%x",
> + dev_name(power_zone->dev.parent),
> + power_zone->id);
> result = device_register(&power_zone->dev);
> - if (result)
> - goto err_dev_ret;
> + if (result) {
> + put_device(&power_zone->dev);
> + mutex_unlock(&control_type->lock);
> +
> + return ERR_PTR(result);
> + }
>
> control_type->nr_zones++;
> mutex_unlock(&control_type->lock);
> --
Applied as 6.3 material, thanks!
Powered by blists - more mailing lists