From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 00CC823E334 for ; Thu, 17 Sep 2026 00:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789604363; cv=none; b=uujI96S8PSUo6BZsiyVgNlqRwBjfABq16aazc02HanpAJ5MmsfwofC2K4kAOFT0Lq0PF9CsbcX1UyNSLA28BD1aA2D4zMzEz1kbLlrmxHxM4TF0ZhOPTOWKFFv0DkzSUlciAP+Al7/4FI+5f6JASWFB+htvHPXZgVsaLzLJJcK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789604363; c=relaxed/simple; bh=VYtuxR1u1DpG8BSr7UKIcOk4t1GexC6m1EojmmKDdHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aby9jToK6vspzaaYB856DyWVneQNIFOiQvSq/+JPbTvIxQ90bFGIAoWjqrtkSxznX99yURk+EN7aA5LznHtcN/U8mRVnK9/YPCFz7ZWP9E7qEsNtjYbXQyJsonuYh/zRwfa9k1j2fz/s9c6e+uOJ4ygGKvkacOw/92p8jGb2G6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NFyMLcCh; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NFyMLcCh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3D201F00893; Thu, 17 Sep 2026 00:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789604361; bh=Ade+elf8BZNO72EgEHFtzWV6noKpdiRwL/qOexJMRkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NFyMLcChxPjNaHhpYKQWJ5rPiVb4PgIL+2fo+Q9xTTgz6GZZYietkk+QMpYlWThi3 1NzNyhiti24PG+lHavZ2F39ylXhygOn8wgDvpr+KPNyWcqDLbvJkdHVtscOphNvI7r YL/6iUm0/FPeTJDnXX1pwXHYwP/MrKJOmcDMw997LD9yam3YPdunxp1fuZcj/qOQRp xR8EFdoRIYc+SsvWxzsMiUrunbu+AkK1LnmhYi8dhU5JKhxcS3Q723Y+hLgrPDD/37 FHL56qQkDy4jVKgBn14R62QNnZ+l+bQ6IqjJzENafFGozVZfMoiFdyPxJauIqs7UVt omOTdZB0qiURw== From: Sasha Levin To: stable@vger.kernel.org Cc: Runyu Xiao , =?UTF-8?q?Th=C3=A9o=20Lebrun?= , Vadim Fedorenko , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12.y 4/4] net: macb: initialize PTP state before registering clock Date: Wed, 16 Sep 2026 20:19:17 -0400 Message-ID: <20260917001917.3360958-4-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260917001917.3360958-1-sashal@kernel.org> References: <2026091643-urethane-talon-e5b2@gregkh> <20260917001917.3360958-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Runyu Xiao [ Upstream commit e1406330d70e56dd44fa6fbafc86e77e5c80c122 ] gem_ptp_init() registers the PTP clock before initializing bp->tsu_clk_lock and the TSU hardware. Since ptp_clock_register() publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready. In addition, gem_ptp_init() is called from both the interface open and resume paths. Reinitializing tsu_clk_lock there can reset the lock while timestamp processing is using it. This race is theoretical and has not been observed in practice. Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock. Fixes: ab91f0a9b5f4 ("net: macb: Add hardware PTP support") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/netdev/20260904030439.3994047-1-runyu.xiao@seu.edu.cn/ Reviewed-by: Théo Lebrun Reviewed-by: Vadim Fedorenko Signed-off-by: Runyu Xiao Link: https://patch.msgid.link/20260908103924.607033-1-runyu.xiao@seu.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/cadence/macb_ptp.c | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 3940d15ae8c92..5c8322cb7d2f5 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -5227,6 +5227,7 @@ static int macb_probe(struct platform_device *pdev) } spin_lock_init(&bp->lock); spin_lock_init(&bp->stats_lock); + spin_lock_init(&bp->tsu_clk_lock); /* setup capabilities */ macb_configure_caps(bp, macb_config); diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index 085795e8aae72..d961a5faf355d 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -332,6 +332,7 @@ void gem_ptp_init(struct net_device *netdev) bp->tsu_rate = bp->ptp_info->get_tsu_rate(bp); bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj(); gem_ptp_init_timer(bp); + gem_ptp_init_tsu(bp); bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &netdev->dev); if (IS_ERR(bp->ptp_clock)) { pr_err("ptp clock register failed: %ld\n", @@ -343,10 +344,6 @@ void gem_ptp_init(struct net_device *netdev) return; } - spin_lock_init(&bp->tsu_clk_lock); - - gem_ptp_init_tsu(bp); - dev_info(&bp->pdev->dev, "%s ptp clock registered.\n", GEM_PTP_TIMER_NAME); } -- 2.53.0