summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2024-03-26 14:59:48 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-02-06 16:41:51 +0100
commit62a5adf57b56ee94075c889abea518b9dc66895d (patch)
tree1ec0b25d99e1845d19525d51f3f80ea40fb07d24 /kernel
parenta006fc4485159dc9bc3c4156f433f62b9c2b709c (diff)
downloadlinux-62a5adf57b56ee94075c889abea518b9dc66895d.tar.gz
linux-62a5adf57b56ee94075c889abea518b9dc66895d.tar.bz2
linux-62a5adf57b56ee94075c889abea518b9dc66895d.zip
Fix memory leak in posix_clock_open()
[ Upstream commit 5b4cdd9c5676559b8a7c944ac5269b914b8c0bb8 ] 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: 60c6946675fc ("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> Stable-dep-of: e859d375d169 ("posix-clock: Store file pointer in struct posix_clock_context") Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/time/posix-clock.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 706559ed7579..a6487a9d6085 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -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;