From: Junrui Luo <[email protected]>

coredump_next_context() returns a spu_context with a reference taken by
get_spu_context(), which the caller must drop.
spufs_coredump_extra_notes_size() does so on all of its exits, but
spufs_coredump_extra_notes_write() never calls put_spu_context(), so
every context dumped through elf_coredump_extra_notes_write() leaks a
reference, including on the success path.

Fix by dropping the reference on each of the three exits of the loop,
mirroring ..._size().

Fixes: 38b407be172d ("powerpc/spufs: Rework fcheck() usage")
Reported-by: Yuhao Jiang <[email protected]>
Cc: [email protected]
Signed-off-by: Junrui Luo <[email protected]>
---
 arch/powerpc/platforms/cell/spufs/coredump.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/cell/spufs/coredump.c 
b/arch/powerpc/platforms/cell/spufs/coredump.c
index 301ee7d8b7df..f5964c9ebb3e 100644
--- a/arch/powerpc/platforms/cell/spufs/coredump.c
+++ b/arch/powerpc/platforms/cell/spufs/coredump.c
@@ -162,13 +162,16 @@ int spufs_coredump_extra_notes_write(struct 
coredump_params *cprm)
        fd = 0;
        while ((ctx = coredump_next_context(&fd)) != NULL) {
                rc = spu_acquire_saved(ctx);
-               if (rc)
+               if (rc) {
+                       put_spu_context(ctx);
                        return rc;
+               }
 
                for (j = 0; spufs_coredump_read[j].name != NULL; j++) {
                        rc = spufs_arch_write_note(ctx, j, cprm, fd);
                        if (rc) {
                                spu_release_saved(ctx);
+                               put_spu_context(ctx);
                                return rc;
                        }
                }
@@ -177,6 +180,7 @@ int spufs_coredump_extra_notes_write(struct coredump_params 
*cprm)
 
                /* start searching the next fd next time */
                fd++;
+               put_spu_context(ctx);
        }
 
        return 0;

-- 
2.51.2



Reply via email to