diff mbox series

[v2,05/10] misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail

Message ID 20220902154900.3404524-6-abel.vesa@linaro.org
State Superseded
Headers show
Series misc: fastrpc: Add audiopd support | expand

Commit Message

Abel Vesa Sept. 2, 2022, 3:48 p.m. UTC
Move the kref_init right after the allocation so that we can use
fastrpc_map_put on any following error case.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/misc/fastrpc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Srinivas Kandagatla Sept. 6, 2022, 2:10 p.m. UTC | #1
On 02/09/2022 16:48, Abel Vesa wrote:
> Move the kref_init right after the allocation so that we can use
> fastrpc_map_put on any following error case.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---

Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

>   drivers/misc/fastrpc.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 6730aa324e10..5eececd9b6bd 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -745,6 +745,8 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
>   		return -ENOMEM;
>   
>   	INIT_LIST_HEAD(&map->node);
> +	kref_init(&map->refcount);
> +
>   	map->fl = fl;
>   	map->fd = fd;
>   	map->buf = dma_buf_get(fd);
> @@ -771,7 +773,6 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
>   	map->size = len;
>   	map->va = sg_virt(map->table->sgl);
>   	map->len = len;
> -	kref_init(&map->refcount);
>   
>   	if (attr & FASTRPC_ATTR_SECUREMAP) {
>   		/*
> @@ -801,7 +802,7 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
>   attach_err:
>   	dma_buf_put(map->buf);
>   get_err:
> -	kfree(map);
> +	fastrpc_map_put(map);
>   
>   	return err;
>   }
diff mbox series

Patch

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 6730aa324e10..5eececd9b6bd 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -745,6 +745,8 @@  static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 		return -ENOMEM;
 
 	INIT_LIST_HEAD(&map->node);
+	kref_init(&map->refcount);
+
 	map->fl = fl;
 	map->fd = fd;
 	map->buf = dma_buf_get(fd);
@@ -771,7 +773,6 @@  static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 	map->size = len;
 	map->va = sg_virt(map->table->sgl);
 	map->len = len;
-	kref_init(&map->refcount);
 
 	if (attr & FASTRPC_ATTR_SECUREMAP) {
 		/*
@@ -801,7 +802,7 @@  static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
 attach_err:
 	dma_buf_put(map->buf);
 get_err:
-	kfree(map);
+	fastrpc_map_put(map);
 
 	return err;
 }