Skip to content

Commit 334f1a1

Browse files
abelvesagregkh
authored andcommitted
misc: fastrpc: Use fastrpc_map_put in fastrpc_map_create on fail
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>
1 parent 6f18c7e commit 334f1a1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/misc/fastrpc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
735735
return -ENOMEM;
736736

737737
INIT_LIST_HEAD(&map->node);
738+
kref_init(&map->refcount);
739+
738740
map->fl = fl;
739741
map->fd = fd;
740742
map->buf = dma_buf_get(fd);
@@ -761,7 +763,6 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
761763
map->size = len;
762764
map->va = sg_virt(map->table->sgl);
763765
map->len = len;
764-
kref_init(&map->refcount);
765766

766767
if (attr & FASTRPC_ATTR_SECUREMAP) {
767768
/*
@@ -791,7 +792,7 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
791792
attach_err:
792793
dma_buf_put(map->buf);
793794
get_err:
794-
kfree(map);
795+
fastrpc_map_put(map);
795796

796797
return err;
797798
}

0 commit comments

Comments
 (0)