Skip to contentSkip to conversation

optee: fix kfree NULL pointer

PATCH In review [email protected] 3 participants 3 messages Nov 4, 2021 – Nov 15, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 optee: fix kfree NULL pointer

From: Lv Ruyi <[email protected]>

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.

---
 drivers/tee/optee/ffa_abi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tee/optee/ffa_abi.c +1 -2
index 6defd1ec982a..8d9d189557f9 100644
@@ -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)) {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · On Thu, 4 Nov 2021 at 17:00, <[email protected]> wrote:

From: Lv Ruyi <[email protected]>

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.

---
 drivers/tee/optee/ffa_abi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tee/optee/ffa_abi.c +0 -0
index 6defd1ec982a..8d9d189557f9 100644

drivers/tee/optee/ffa_abi.c static int optee_ffa_probe(struct ffa_device *ffa_dev) · line 815

Quoted 7 lines
drivers/tee/optee/ffa_abi.c +1 -2
@@ -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:

-Sumit

Quoted 5 lines
drivers/tee/optee/ffa_abi.c +0 -1
        optee->pool = optee_ffa_config_dyn_shm();
        if (IS_ERR(optee->pool)) {
--

2.25.1

#2 lore raw
Quoted 32 lines · Sumit Garg
Quoted 20 lines · On Thu, 4 Nov 2021 at 17:00, <[email protected]> wrote:

From: Lv Ruyi <[email protected]>

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.

---
 drivers/tee/optee/ffa_abi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tee/optee/ffa_abi.c +0 -0
index 6defd1ec982a..8d9d189557f9 100644

drivers/tee/optee/ffa_abi.c static int optee_ffa_probe(struct ffa_device *ffa_dev) · line 815

Quoted 7 lines
drivers/tee/optee/ffa_abi.c +1 -2
@@ -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.

Quoted 3 lines

With that addressed:

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

Thanks,
Jens