Skip to content

Commit 5b4cdd9

Browse files
committed
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: Rohit Keshri <rkeshri@redhat.com> Acked-by: Oleg Nesterov <oleg@redhat.com> Fixes: 60c6946 ("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: Linus Torvalds <torvalds@linuxfoundation.org>
1 parent 7033999 commit 5b4cdd9

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

kernel/time/posix-clock.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,17 @@ static int posix_clock_open(struct inode *inode, struct file *fp)
129129
goto out;
130130
}
131131
pccontext->clk = clk;
132-
fp->private_data = pccontext;
133-
if (clk->ops.open)
132+
if (clk->ops.open) {
134133
err = clk->ops.open(pccontext, fp->f_mode);
135-
else
136-
err = 0;
137-
138-
if (!err) {
139-
get_device(clk->dev);
134+
if (err) {
135+
kfree(pccontext);
136+
goto out;
137+
}
140138
}
139+
140+
fp->private_data = pccontext;
141+
get_device(clk->dev);
142+
err = 0;
141143
out:
142144
up_read(&clk->rwsem);
143145
return err;

0 commit comments

Comments
 (0)