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 <[email protected]> Acked-by: Oleg Nesterov <[email protected]> Fixes: 60c6946 ("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]>
1 parent 7033999 commit 5b4cdd9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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)