From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A10E2BE62B; Wed, 4 Feb 2026 14:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770216298; cv=none; b=U7HohRMoqAAK5OJhUijK6tty+o2nPPp8nnJbetzdW6u1yoajXRtoDGG6c7QfhG2b/ckCwL66LFBl3cSy+kl5GjyEYWKooiK+MfyJITznXU2Z16mJ8KHymgCyDXv0APZCdKwR9DuqZcPQA9KGZS4ha2tUl1QHgnS/LjFALsa5RaA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770216298; c=relaxed/simple; bh=Pn4hgQ8ZgOxseaGui/uogvlTIo+EPmfamA89Ys5uez4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KMZqABvovNW7U/LY8Q0KtNxe585erAsrrJWYiliXJrX2OCuPswwBEKUaH7o5CEyOKtGi1Sj4WLv78kVtRdLdAJhYSVdAF300RNKkw1jQ4h0LNjOPY1uXfruuy+1XSwv2plNQv3ZRyVtRJuWbA/poc9plogyQ3kDqZnu3yIiRTR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JxKZ4ueS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JxKZ4ueS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACEC8C4CEF7; Wed, 4 Feb 2026 14:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1770216298; bh=Pn4hgQ8ZgOxseaGui/uogvlTIo+EPmfamA89Ys5uez4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JxKZ4ueSuVKq50/9rDc5NrDuWytEhAwRRMy89h+7W/9MeA6SpttTr5a/7IrbqL+Ye W3XWtybaMKY32ThVjEs9NjFIM4u9sFsx3d9ENQQIvO4rapQHV64+Y56eLOLMbGufoP YMszjVqpPi0e53zei7fdl9OUcTT+n+27GqWNSCQk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rohit Keshri , Oleg Nesterov , Jakub Kicinski , "David S. Miller" , Thomas Gleixner , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 046/161] Fix memory leak in posix_clock_open() Date: Wed, 4 Feb 2026 15:38:29 +0100 Message-ID: <20260204143853.419896023@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260204143851.755002596@linuxfoundation.org> References: <20260204143851.755002596@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linus Torvalds [ 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 Acked-by: Oleg Nesterov Fixes: 60c6946675fc ("posix-clock: introduce posix_clock_context concept") Cc: Jakub Kicinski Cc: David S. Miller Cc: Thomas Gleixner Signed-off-by: Linus Torvalds Stable-dep-of: e859d375d169 ("posix-clock: Store file pointer in struct posix_clock_context") Signed-off-by: Sasha Levin --- kernel/time/posix-clock.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c index 706559ed75793..a6487a9d60853 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; -- 2.51.0