Commit 5b4cdd9c authored by Linus Torvalds's avatar Linus Torvalds

Fix memory leak in posix_clock_open()

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: default avatarRohit Keshri <rkeshri@redhat.com>
Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
Fixes: 60c69466 ("posix-clock: introduce posix_clock_context concept")
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linuxfoundation.org>
parent 7033999e
...@@ -129,15 +129,17 @@ static int posix_clock_open(struct inode *inode, struct file *fp) ...@@ -129,15 +129,17 @@ static int posix_clock_open(struct inode *inode, struct file *fp)
goto out; goto out;
} }
pccontext->clk = clk; pccontext->clk = clk;
fp->private_data = pccontext; if (clk->ops.open) {
if (clk->ops.open)
err = clk->ops.open(pccontext, fp->f_mode); err = clk->ops.open(pccontext, fp->f_mode);
else if (err) {
err = 0; kfree(pccontext);
goto out;
if (!err) { }
get_device(clk->dev);
} }
fp->private_data = pccontext;
get_device(clk->dev);
err = 0;
out: out:
up_read(&clk->rwsem); up_read(&clk->rwsem);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment