[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAFA6WYNYxiEOjcV7knNSwtHYtmGpuPMt1kAb8KjLBk6Ggj2+sA@mail.gmail.com>
Date: Thu, 17 Nov 2022 15:42:30 +0530
From: Sumit Garg <sumit.garg@...aro.org>
To: ruanjinjie <ruanjinjie@...wei.com>
Cc: jens.wiklander@...aro.org, daniel.thompson@...aro.org,
op-tee@...ts.trustedfirmware.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] tee: optee: fix possible memory leak in optee_register_device()
Hi,
On Thu, 17 Nov 2022 at 08:55, ruanjinjie <ruanjinjie@...wei.com> wrote:
>
> If device_register() returns error in optee_register_device(),
> name of kobject which is allocated in dev_set_name() called in device_add()
> is leaked.
>
> Never directly free @dev after calling device_register(), even
> if it returned an error! Always use put_device() to give up the
> reference initialized.
>
> Fixes: c3fa24af9244 ("tee: optee: add TEE bus device enumeration support")
> Signed-off-by: ruanjinjie <ruanjinjie@...wei.com>
> ---
> drivers/tee/optee/device.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
There's already a prior patch posted to fix this here [1].
[1] https://lists.trustedfirmware.org/archives/list/op-tee@lists.trustedfirmware.org/thread/BMADRGTZ63GP5ORMMISW7RJPMZKINXE7/
-Sumit
> diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
> index f3947be13e2e..64f0e047c23d 100644
> --- a/drivers/tee/optee/device.c
> +++ b/drivers/tee/optee/device.c
> @@ -80,7 +80,7 @@ static int optee_register_device(const uuid_t *device_uuid)
> rc = device_register(&optee_device->dev);
> if (rc) {
> pr_err("device registration failed, err: %d\n", rc);
> - kfree(optee_device);
> + put_device(&optee_device->dev);
> }
>
> return rc;
> --
> 2.25.1
>
Powered by blists - more mailing lists