]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: hns3: defer calling ptp_clock_register()
authorJian Shen <shenjian15@huawei.com>
Wed, 30 Apr 2025 09:30:52 +0000 (17:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 May 2025 07:44:02 +0000 (09:44 +0200)
[ Upstream commit 4971394d9d624f91689d766f31ce668d169d9959 ]

Currently the ptp_clock_register() is called before relative
ptp resource ready. It may cause unexpected result when upper
layer called the ptp API during the timewindow. Fix it by
moving the ptp_clock_register() to the function end.

Fixes: 0bf5eb788512 ("net: hns3: add support for PTP")
Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20250430093052.2400464-5-shaojijie@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c

index ddc691424c81634ac7b4dbf509e1806b8fce7a0d..9a806ac727cf5bebc17a553417cf582e782e34da 100644 (file)
@@ -440,6 +440,13 @@ static int hclge_ptp_create_clock(struct hclge_dev *hdev)
        ptp->info.settime64 = hclge_ptp_settime;
 
        ptp->info.n_alarm = 0;
+
+       spin_lock_init(&ptp->lock);
+       ptp->io_base = hdev->hw.hw.io_base + HCLGE_PTP_REG_OFFSET;
+       ptp->ts_cfg.rx_filter = HWTSTAMP_FILTER_NONE;
+       ptp->ts_cfg.tx_type = HWTSTAMP_TX_OFF;
+       hdev->ptp = ptp;
+
        ptp->clock = ptp_clock_register(&ptp->info, &hdev->pdev->dev);
        if (IS_ERR(ptp->clock)) {
                dev_err(&hdev->pdev->dev,
@@ -451,12 +458,6 @@ static int hclge_ptp_create_clock(struct hclge_dev *hdev)
                return -ENODEV;
        }
 
-       spin_lock_init(&ptp->lock);
-       ptp->io_base = hdev->hw.hw.io_base + HCLGE_PTP_REG_OFFSET;
-       ptp->ts_cfg.rx_filter = HWTSTAMP_FILTER_NONE;
-       ptp->ts_cfg.tx_type = HWTSTAMP_TX_OFF;
-       hdev->ptp = ptp;
-
        return 0;
 }