From nobody Tue Dec 2 02:05:58 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9A977299954 for ; Thu, 20 Nov 2025 15:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763650951; cv=none; b=En61psXaxA3i9CPojoKEPc/sbVpU4T8sj/xmEogRhrlE9YdgMasMwPreFjZTxBuJYwqnKxBpgokcaLPvwP7tVYg2PaAP4fBLFEOIWHECGPEJVjTNGtGYqJMGbtXba0HmvHFF90GATkc9NOU7A86Dg3EwqcLqWQ6S6kU2SY1Mse8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763650951; c=relaxed/simple; bh=K8bq7BxwaoZ8rczUZuQJCpqWZ0qWt1tBcecaG5TONhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aLGZbDZMqCKsb9TX7L+nVxa5ELBN0wbDKx8uCzcjB8tCxNCXywsf/0U7jL581dqxYzfF2chP3Tv7MXDNvXTHNDvZaA/niZIWAHF0QdItfh9VKiRUrzDfkFza66+2ptpL0Kf4d595MeZwE8AVu+ihLqOV1pzczgwV3xSu9QNlBFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NjerIQXk; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NjerIQXk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763650948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6axCARBEPyTBunhyHubGoBr3+MkoJR3w9iac9LVVfLQ=; b=NjerIQXkNJCoy2dzUZr1Q3x0rowpViITv+2RymYTrbXtpYvVU8spSE8lirSbRpN2L/a9pH 9+DUawQLaD7+zwWApc9NYgGvEEq3xxlYqRKCiBXpFyjNnS7bRuyqhREl5kE+u6co5wJRUK 8ogbP3RsvN6iYO7qtobLZYGSmsjDOfI= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-226-YinBVyWWNPKeaoSBm7YvyQ-1; Thu, 20 Nov 2025 10:02:25 -0500 X-MC-Unique: YinBVyWWNPKeaoSBm7YvyQ-1 X-Mimecast-MFC-AGG-ID: YinBVyWWNPKeaoSBm7YvyQ_1763650943 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 47DA41956060; Thu, 20 Nov 2025 15:02:23 +0000 (UTC) Received: from mrout-thinkpadp16vgen1.punetw6.csb (unknown [10.74.80.121]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EF4C0180049F; Thu, 20 Nov 2025 15:02:20 +0000 (UTC) From: Malaya Kumar Rout To: tglx@linutronix.de Cc: Malaya Kumar Rout , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v2] timekeeping: Fix resource leak in tk_aux_sysfs_init() error paths Date: Thu, 20 Nov 2025 20:32:13 +0530 Message-ID: <20251120150213.246777-1-mrout@redhat.com> In-Reply-To: <87y0o599yd.ffs@tglx> References: <87y0o599yd.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The tk_aux_sysfs_init() function returns immediately on error during the auxiliary clock initialization loop without cleaning up previously allocated kobjects and sysfs groups. If kobject_create_and_add() or sysfs_create_group() fails during loop iteration, the parent kobjects (tko and auxo) and any previously created child kobjects are leaked. Fix this by adding proper error handling with goto labels to ensure all allocated resources are cleaned up on failure. kobject_put() on the parent kobjects will handle cleanup of their children. Signed-off-by: Malaya Kumar Rout --- kernel/time/timekeeping.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 3a4d3b2e3f74..08e0943b54da 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -3060,29 +3060,32 @@ static const struct attribute_group aux_clock_enabl= e_attr_group =3D { static int __init tk_aux_sysfs_init(void) { struct kobject *auxo, *tko =3D kobject_create_and_add("time", kernel_kobj= ); + int ret =3D -ENOMEM; =20 if (!tko) - return -ENOMEM; + return ret; =20 auxo =3D kobject_create_and_add("aux_clocks", tko); - if (!auxo) { - kobject_put(tko); - return -ENOMEM; - } + if (!auxo) + goto err_clean; =20 for (int i =3D 0; i < MAX_AUX_CLOCKS; i++) { char id[2] =3D { [0] =3D '0' + i, }; struct kobject *clk =3D kobject_create_and_add(id, auxo); =20 if (!clk) - return -ENOMEM; - - int ret =3D sysfs_create_group(clk, &aux_clock_enable_attr_group); + goto err_clean; =20 + ret =3D sysfs_create_group(clk, &aux_clock_enable_attr_group); if (ret) - return ret; + goto err_clean; } return 0; + +err_clean: + kobject_put(auxo); + kobject_put(tko); + return ret; } late_initcall(tk_aux_sysfs_init); =20 --=20 2.51.0