From: Grygorii Strashko <grygorii.strashko@ti.com>
To: Kurt Kanzenbach <kurt@linutronix.de>,
Arnd Bergmann <arnd@kernel.org>,
Richard Cochran <richardcochran@gmail.com>
Cc: Wang Qing <wangqing@vivo.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Samuel Zou <zou_wei@huawei.com>,
Networking <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR
Date: Fri, 6 Nov 2020 16:48:13 +0200 [thread overview]
Message-ID: <1301ecbe-0380-9744-04dc-7d133d598700@ti.com> (raw)
In-Reply-To: <87pn4qmyl1.fsf@kurt>
On 06/11/2020 14:58, Kurt Kanzenbach wrote:
> On Fri Nov 06 2020, Arnd Bergmann wrote:
>> On Fri, Nov 6, 2020 at 12:35 PM Grygorii Strashko
>> <grygorii.strashko@ti.com> wrote:
>>> On 06/11/2020 09:56, Wang Qing wrote:
>>
>>>> +++ b/drivers/net/ethernet/ti/am65-cpts.c
>>>> @@ -1001,8 +1001,7 @@ struct am65_cpts *am65_cpts_create(struct device *dev, void __iomem *regs,
>>>
>>> there is
>>> cpts->ptp_clock = ptp_clock_register(&cpts->ptp_info, cpts->dev);
>>>
>>>
>>>> if (IS_ERR_OR_NULL(cpts->ptp_clock)) {
>>>
>>> And ptp_clock_register() can return NULL only if PTP support is disabled.
>>> In which case, we should not even get here.
>>>
>>> So, I'd propose to s/IS_ERR_OR_NULL/IS_ERR above,
>>> and just assign ret = PTR_ERR(cpts->ptp_clock) here.
>>
>> Right, using IS_ERR_OR_NULL() is almost ever a mistake, either
>> from misunderstanding the interface, or from a badly designed
>> interface that needs to be changed.
>
> The NULL case should be handled differently and it is documented:
>
> /**
> * ptp_clock_register() - register a PTP hardware clock driver
> [...]
> * Returns a valid pointer on success or PTR_ERR on failure. If PHC
> * support is missing at the configuration level, this function
> * returns NULL, and drivers are expected to gracefully handle that
> * case separately.
> */
I think, it's not the first time such question triggered, I've found [1]
I've managed to find 6 drivers which uses IS_ERR_OR_NULL check with ptp_clock_register() and, kinda,
assume to be able to work with !CONFIG_PTP_1588_CLOCK. List below with some comments:
hv
hv_util.c
hv_timesync_init, line 697: hv_ptp_clock = ptp_clock_register(&ptp_hyperv_info, NULL);
net/ethernet
sja1105 (depends on PTP_1588_CLOCK, use IS_ERR())
sja1105_ptp.c
sja1105_ptp_clock_register, line 867: ptp_data->clock = ptp_clock_register(&ptp_data->caps, ds->dev);
net/ethernet
chelsio (can be fixed by adding !IS_ENABLED(CONFIG_PTP_1588_CLOCK))
cxgb4
cxgb4_ptp.c
cxgb4_ptp_init, line 431: adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info,
net/ethernet
octeontx2 (can be fixed by adding !IS_ENABLED(CONFIG_PTP_1588_CLOCK))
nic
otx2_ptp.c
otx2_ptp_init, line 170: ptp_ptr->ptp_clock = ptp_clock_register(&ptp_ptr->ptp_info, pfvf->dev);
net/ethernet
renesas (no checks - will crash if init failed or !PTP), uses imply PTP_1588_CLOCK
ravb_ptp.c
ravb_ptp_init, line 345: priv->ptp.clock = ptp_clock_register(&priv->ptp.info, &pdev->dev);
net/phy
mscc (no checks - will crash if init failed or !PTP, depends on NETWORK_PHY_TIMESTAMPING)
mscc_ptp.c
__vsc8584_init_ptp, line 1495: vsc8531->ptp->ptp_clock = ptp_clock_register(&vsc8531->ptp->caps,
In general, if above updated, the return value for ptp_clock_register() can be changed to ERR_PTR(-EOPNOTSUPP)
for the !CONFIG_PTP_1588_CLOCK and so question resolved.
For hv/sja1105/cxgb4/octeontx2 below diff should solve the case, but I'm not sure about
renesas/ravb_ptp and net/phy/mscc.
For renesas/ravb_ptp - seems strict "depends on PTP_1588_CLOCK" can be the choice
For net/phy/mscc - seems code dependencies need to be changed from CONFIG_NETWORK_PHY_TIMESTAMPING to
CONFIG_PTP_1588_CLOCK.
[1] https://lore.kernel.org/lkml/c04458ed-29ee-1797-3a11-7f3f560553e6@ti.com/
--
Best regards,
grygorii
-------------
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index 05566ecdbe4b..0fa8f6cb2394 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -681,6 +681,11 @@ static struct ptp_clock *hv_ptp_clock;
static int hv_timesync_init(struct hv_util_service *srv)
{
+ int ret = 0;
+
+ if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK))
+ return -EOPNOTSUPP;
+
/* TimeSync requires Hyper-V clocksource. */
if (!hv_read_reference_counter)
return -ENODEV;
@@ -695,13 +700,13 @@ static int hv_timesync_init(struct hv_util_service *srv)
* as it still handles the ICTIMESYNCFLAG_SYNC case.
*/
hv_ptp_clock = ptp_clock_register(&ptp_hyperv_info, NULL);
- if (IS_ERR_OR_NULL(hv_ptp_clock)) {
- pr_err("cannot register PTP clock: %ld\n",
- PTR_ERR(hv_ptp_clock));
+ if (IS_ERR(hv_ptp_clock)) {
+ ret = PTR_ERR(hv_ptp_clock);
+ pr_err("cannot register PTP clock: %ld\n", ret);
hv_ptp_clock = NULL;
}
- return 0;
+ return ret;
}
static void hv_timesync_cancel_work(void)
diff --git a/drivers/net/dsa/sja1105/sja1105_ptp.c b/drivers/net/dsa/sja1105/sja1105_ptp.c
index 1b90570b257b..1e41d491c854 100644
--- a/drivers/net/dsa/sja1105/sja1105_ptp.c
+++ b/drivers/net/dsa/sja1105/sja1105_ptp.c
@@ -865,7 +865,7 @@ int sja1105_ptp_clock_register(struct dsa_switch *ds)
spin_lock_init(&tagger_data->meta_lock);
ptp_data->clock = ptp_clock_register(&ptp_data->caps, ds->dev);
- if (IS_ERR_OR_NULL(ptp_data->clock))
+ if (IS_ERR(ptp_data->clock))
return PTR_ERR(ptp_data->clock);
ptp_data->cmd.corrclk4ts = true;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
index 70dbee89118e..e43a3e73762b 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
@@ -420,6 +420,10 @@ static const struct ptp_clock_info cxgb4_ptp_clock_info = {
void cxgb4_ptp_init(struct adapter *adapter)
{
struct timespec64 now;
+
+ if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK))
+ return;
+
/* no need to create a clock device if we already have one */
if (!IS_ERR_OR_NULL(adapter->ptp_clock))
return;
@@ -430,7 +434,7 @@ void cxgb4_ptp_init(struct adapter *adapter)
adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info,
&adapter->pdev->dev);
- if (IS_ERR_OR_NULL(adapter->ptp_clock)) {
+ if (IS_ERR(adapter->ptp_clock)) {
adapter->ptp_clock = NULL;
dev_err(adapter->pdev_dev,
"PTP %s Clock registration has failed\n", __func__);
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c
index 7bcf5246350f..22b736c2e9d6 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c
@@ -119,6 +119,9 @@ int otx2_ptp_init(struct otx2_nic *pfvf)
struct ptp_req *req;
int err;
+ if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK))
+ return 0;
+
mutex_lock(&pfvf->mbox.lock);
/* check if PTP block is available */
req = otx2_mbox_alloc_msg_ptp_op(&pfvf->mbox);
@@ -168,9 +171,8 @@ int otx2_ptp_init(struct otx2_nic *pfvf)
};
ptp_ptr->ptp_clock = ptp_clock_register(&ptp_ptr->ptp_info, pfvf->dev);
- if (IS_ERR_OR_NULL(ptp_ptr->ptp_clock)) {
- err = ptp_ptr->ptp_clock ?
- PTR_ERR(ptp_ptr->ptp_clock) : -ENODEV;
+ if (IS_ERR(ptp_ptr->ptp_clock)) {
+ err = PTR_ERR(ptp_ptr->ptp_clock);
kfree(ptp_ptr);
goto error;
}
next prev parent reply other threads:[~2020-11-06 14:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-06 7:56 [PATCH] net/ethernet: update ret when ptp_clock is ERROR Wang Qing
2020-11-06 11:34 ` Grygorii Strashko
2020-11-06 12:11 ` Arnd Bergmann
2020-11-06 12:58 ` Kurt Kanzenbach
2020-11-06 14:48 ` Grygorii Strashko [this message]
2020-11-07 15:07 ` Richard Cochran
2020-11-07 15:08 ` Richard Cochran
2020-11-11 13:03 ` Grygorii Strashko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1301ecbe-0380-9744-04dc-7d133d598700@ti.com \
--to=grygorii.strashko@ti.com \
--cc=arnd@kernel.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=kurt@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=wangqing@vivo.com \
--cc=zou_wei@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).