misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
authorAbel Vesa <abel.vesa@linaro.org>
Fri, 25 Nov 2022 07:14:00 +0000 (07:14 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Nov 2022 17:45:33 +0000 (18:45 +0100)
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>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20221125071405.148786-6-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/fastrpc.c

index 8b43fe5207fb6c2d64dbfa78eb0c0a8b57d3c668..332626df5d395964a31cb87f7a1acbf527e0ca61 100644 (file)
@@ -735,6 +735,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);
@@ -761,7 +763,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) {
                /*
@@ -791,7 +792,7 @@ map_err:
 attach_err:
        dma_buf_put(map->buf);
 get_err:
-       kfree(map);
+       fastrpc_map_put(map);
 
        return err;
 }