linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] optee: fix kfree NULL pointer
@ 2021-11-04 11:30 cgel.zte
  2021-11-08  5:33 ` Sumit Garg
  0 siblings, 1 reply; 3+ messages in thread
From: cgel.zte @ 2021-11-04 11:30 UTC (permalink / raw)
  To: jens.wiklander; +Cc: sumit.garg, op-tee, linux-kernel, Lv Ruyi, Zeal Robot

From: Lv Ruyi <lv.ruyi@zte.com.cn>

This patch fixes the following Coccinelle error:
drivers/tee/optee/ffa_abi.c: 877: ERROR  optee is NULL but dereferenced.

If memory allocation fails, optee is null pointer. the code will goto err
 and release optee.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
 drivers/tee/optee/ffa_abi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tee/optee/ffa_abi.c b/drivers/tee/optee/ffa_abi.c
index 6defd1ec982a..8d9d189557f9 100644
--- a/drivers/tee/optee/ffa_abi.c
+++ b/drivers/tee/optee/ffa_abi.c
@@ -811,8 +811,7 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
 
 	optee = kzalloc(sizeof(*optee), GFP_KERNEL);
 	if (!optee) {
-		rc = -ENOMEM;
-		goto err;
+		return -ENOMEM;
 	}
 	optee->pool = optee_ffa_config_dyn_shm();
 	if (IS_ERR(optee->pool)) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] optee: fix kfree NULL pointer
  2021-11-04 11:30 [PATCH] optee: fix kfree NULL pointer cgel.zte
@ 2021-11-08  5:33 ` Sumit Garg
  2021-11-15 12:36   ` Jens Wiklander
  0 siblings, 1 reply; 3+ messages in thread
From: Sumit Garg @ 2021-11-08  5:33 UTC (permalink / raw)
  To: cgel.zte; +Cc: jens.wiklander, op-tee, linux-kernel, Lv Ruyi, Zeal Robot

On Thu, 4 Nov 2021 at 17:00, <cgel.zte@gmail.com> wrote:
>
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
>
> This patch fixes the following Coccinelle error:
> drivers/tee/optee/ffa_abi.c: 877: ERROR  optee is NULL but dereferenced.
>
> If memory allocation fails, optee is null pointer. the code will goto err
>  and release optee.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
> ---
>  drivers/tee/optee/ffa_abi.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/tee/optee/ffa_abi.c b/drivers/tee/optee/ffa_abi.c
> index 6defd1ec982a..8d9d189557f9 100644
> --- a/drivers/tee/optee/ffa_abi.c
> +++ b/drivers/tee/optee/ffa_abi.c
> @@ -811,8 +811,7 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
>
>         optee = kzalloc(sizeof(*optee), GFP_KERNEL);
>         if (!optee) {
> -               rc = -ENOMEM;
> -               goto err;
> +               return -ENOMEM;
>         }

So the braces are redundant after this change, hence can be dropped.

With that addressed:

Reviewed-by: Sumit Garg <sumit.garg@linaro.org>

-Sumit

>         optee->pool = optee_ffa_config_dyn_shm();
>         if (IS_ERR(optee->pool)) {
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] optee: fix kfree NULL pointer
  2021-11-08  5:33 ` Sumit Garg
@ 2021-11-15 12:36   ` Jens Wiklander
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Wiklander @ 2021-11-15 12:36 UTC (permalink / raw)
  To: Sumit Garg; +Cc: cgel.zte, op-tee, linux-kernel, Lv Ruyi, Zeal Robot

On Mon, Nov 8, 2021 at 6:34 AM Sumit Garg <sumit.garg@linaro.org> wrote:
>
> On Thu, 4 Nov 2021 at 17:00, <cgel.zte@gmail.com> wrote:
> >
> > From: Lv Ruyi <lv.ruyi@zte.com.cn>
> >
> > This patch fixes the following Coccinelle error:
> > drivers/tee/optee/ffa_abi.c: 877: ERROR  optee is NULL but dereferenced.
> >
> > If memory allocation fails, optee is null pointer. the code will goto err
> >  and release optee.
> >
> > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
> > ---
> >  drivers/tee/optee/ffa_abi.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/tee/optee/ffa_abi.c b/drivers/tee/optee/ffa_abi.c
> > index 6defd1ec982a..8d9d189557f9 100644
> > --- a/drivers/tee/optee/ffa_abi.c
> > +++ b/drivers/tee/optee/ffa_abi.c
> > @@ -811,8 +811,7 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
> >
> >         optee = kzalloc(sizeof(*optee), GFP_KERNEL);
> >         if (!optee) {
> > -               rc = -ENOMEM;
> > -               goto err;
> > +               return -ENOMEM;
> >         }
>
> So the braces are redundant after this change, hence can be dropped.
>
> With that addressed:
>
> Reviewed-by: Sumit Garg <sumit.garg@linaro.org>

I'll fix up the commit and pick it up now.

Thanks,
Jens

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-15 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 11:30 [PATCH] optee: fix kfree NULL pointer cgel.zte
2021-11-08  5:33 ` Sumit Garg
2021-11-15 12:36   ` Jens Wiklander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).