Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 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>

+9 -7
+9 -7
kernel/time/posix-clock.c
··· 129 129 goto out; 130 130 } 131 131 pccontext->clk = clk; 132 - fp->private_data = pccontext; 133 - if (clk->ops.open) 132 + if (clk->ops.open) { 134 133 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 + } 140 138 } 139 + 140 + fp->private_data = pccontext; 141 + get_device(clk->dev); 142 + err = 0; 141 143 out: 142 144 up_read(&clk->rwsem); 143 145 return err;