]> Git Repo - linux.git/commitdiff
Fix memory leak in posix_clock_open()
authorLinus Torvalds <[email protected]>
Tue, 26 Mar 2024 21:59:48 +0000 (14:59 -0700)
committerLinus Torvalds <[email protected]>
Wed, 27 Mar 2024 16:03:22 +0000 (09:03 -0700)
If the clk ops.open() function returns an error, we don't release the
pccontext we allocated for this clock.

Re-organize the code slightly to make it all more obvious.

Reported-by: Rohit Keshri <[email protected]>
Acked-by: Oleg Nesterov <[email protected]>
Fixes: 60c6946675fc ("posix-clock: introduce posix_clock_context concept")
Cc: Jakub Kicinski <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/time/posix-clock.c

index 9de66bbbb3d1555603ad169fad883af1c55b9d85..4782edcbe7b9b445e932897ce97d799d73762154 100644 (file)
@@ -129,15 +129,17 @@ static int posix_clock_open(struct inode *inode, struct file *fp)
                goto out;
        }
        pccontext->clk = clk;
-       fp->private_data = pccontext;
-       if (clk->ops.open)
+       if (clk->ops.open) {
                err = clk->ops.open(pccontext, fp->f_mode);
-       else
-               err = 0;
-
-       if (!err) {
-               get_device(clk->dev);
+               if (err) {
+                       kfree(pccontext);
+                       goto out;
+               }
        }
+
+       fp->private_data = pccontext;
+       get_device(clk->dev);
+       err = 0;
 out:
        up_read(&clk->rwsem);
        return err;
This page took 0.052446 seconds and 4 git commands to generate.