* [PATCH] net/ethernet: update ret when ptp_clock is ERROR @ 2020-11-06 7:56 Wang Qing 2020-11-06 11:34 ` Grygorii Strashko 2020-11-07 15:08 ` Richard Cochran 0 siblings, 2 replies; 8+ messages in thread From: Wang Qing @ 2020-11-06 7:56 UTC (permalink / raw) To: David S. Miller, Jakub Kicinski, Grygorii Strashko, Samuel Zou, Kurt Kanzenbach, Wang Qing, Ivan Khoronzhuk, netdev, linux-kernel We always have to update the value of ret, otherwise the error value may be the previous one. Signed-off-by: Wang Qing <wangqing@vivo.com> --- drivers/net/ethernet/ti/am65-cpts.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c index 75056c1..b77ff61 --- a/drivers/net/ethernet/ti/am65-cpts.c +++ b/drivers/net/ethernet/ti/am65-cpts.c @@ -1001,8 +1001,7 @@ struct am65_cpts *am65_cpts_create(struct device *dev, void __iomem *regs, if (IS_ERR_OR_NULL(cpts->ptp_clock)) { dev_err(dev, "Failed to register ptp clk %ld\n", PTR_ERR(cpts->ptp_clock)); - if (!cpts->ptp_clock) - ret = -ENODEV; + ret = cpts->ptp_clock ? cpts->ptp_clock : (-ENODEV); goto refclk_disable; } cpts->phc_index = ptp_clock_index(cpts->ptp_clock); -- 2.7.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR 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-07 15:07 ` Richard Cochran 2020-11-07 15:08 ` Richard Cochran 1 sibling, 2 replies; 8+ messages in thread From: Grygorii Strashko @ 2020-11-06 11:34 UTC (permalink / raw) To: Wang Qing, David S. Miller, Jakub Kicinski, Samuel Zou, Kurt Kanzenbach, Richard Cochran, netdev, linux-kernel On 06/11/2020 09:56, Wang Qing wrote: > We always have to update the value of ret, otherwise the > error value may be the previous one. > > Signed-off-by: Wang Qing <wangqing@vivo.com> > --- > drivers/net/ethernet/ti/am65-cpts.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c > index 75056c1..b77ff61 > --- a/drivers/net/ethernet/ti/am65-cpts.c > +++ 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. > dev_err(dev, "Failed to register ptp clk %ld\n", > PTR_ERR(cpts->ptp_clock)); > - if (!cpts->ptp_clock) > - ret = -ENODEV; > + ret = cpts->ptp_clock ? cpts->ptp_clock : (-ENODEV); > goto refclk_disable; > } > cpts->phc_index = ptp_clock_index(cpts->ptp_clock); > -- Best regards, grygorii ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR 2020-11-06 11:34 ` Grygorii Strashko @ 2020-11-06 12:11 ` Arnd Bergmann 2020-11-06 12:58 ` Kurt Kanzenbach 2020-11-07 15:07 ` Richard Cochran 1 sibling, 1 reply; 8+ messages in thread From: Arnd Bergmann @ 2020-11-06 12:11 UTC (permalink / raw) To: Grygorii Strashko Cc: Wang Qing, David S. Miller, Jakub Kicinski, Samuel Zou, Kurt Kanzenbach, Richard Cochran, Networking, linux-kernel 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. Arnd ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR 2020-11-06 12:11 ` Arnd Bergmann @ 2020-11-06 12:58 ` Kurt Kanzenbach 2020-11-06 14:48 ` Grygorii Strashko 0 siblings, 1 reply; 8+ messages in thread From: Kurt Kanzenbach @ 2020-11-06 12:58 UTC (permalink / raw) To: Arnd Bergmann, Grygorii Strashko Cc: Wang Qing, David S. Miller, Jakub Kicinski, Samuel Zou, Richard Cochran, Networking, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1257 bytes --] 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. */ Thanks, Kurt [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 832 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR 2020-11-06 12:58 ` Kurt Kanzenbach @ 2020-11-06 14:48 ` Grygorii Strashko 0 siblings, 0 replies; 8+ messages in thread From: Grygorii Strashko @ 2020-11-06 14:48 UTC (permalink / raw) To: Kurt Kanzenbach, Arnd Bergmann, Richard Cochran Cc: Wang Qing, David S. Miller, Jakub Kicinski, Samuel Zou, Networking, linux-kernel 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; } ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR 2020-11-06 11:34 ` Grygorii Strashko 2020-11-06 12:11 ` Arnd Bergmann @ 2020-11-07 15:07 ` Richard Cochran 1 sibling, 0 replies; 8+ messages in thread From: Richard Cochran @ 2020-11-07 15:07 UTC (permalink / raw) To: Grygorii Strashko Cc: Wang Qing, David S. Miller, Jakub Kicinski, Samuel Zou, Kurt Kanzenbach, netdev, linux-kernel On Fri, Nov 06, 2020 at 01:34:04PM +0200, Grygorii Strashko wrote: > And ptp_clock_register() can return NULL only if PTP support is disabled. Not true in general ... > In which case, we should not even get here. only because the Kconfig uses "depends on" instead of "implies" PTP_1588_CLOCK. > So, I'd propose to s/IS_ERR_OR_NULL/IS_ERR above, > and just assign ret = PTR_ERR(cpts->ptp_clock) here. No, please no -- don't make another bad example for people to copy/paste. Thanks, Richard ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR 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-07 15:08 ` Richard Cochran 2020-11-11 13:03 ` Grygorii Strashko 1 sibling, 1 reply; 8+ messages in thread From: Richard Cochran @ 2020-11-07 15:08 UTC (permalink / raw) To: Wang Qing Cc: David S. Miller, Jakub Kicinski, Grygorii Strashko, Samuel Zou, Kurt Kanzenbach, Ivan Khoronzhuk, netdev, linux-kernel On Fri, Nov 06, 2020 at 03:56:45PM +0800, Wang Qing wrote: > We always have to update the value of ret, otherwise the > error value may be the previous one. > > Signed-off-by: Wang Qing <wangqing@vivo.com> Acked-by: Richard Cochran <richardcochran@gmail.com> > --- > drivers/net/ethernet/ti/am65-cpts.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c > index 75056c1..b77ff61 > --- a/drivers/net/ethernet/ti/am65-cpts.c > +++ b/drivers/net/ethernet/ti/am65-cpts.c > @@ -1001,8 +1001,7 @@ struct am65_cpts *am65_cpts_create(struct device *dev, void __iomem *regs, > if (IS_ERR_OR_NULL(cpts->ptp_clock)) { > dev_err(dev, "Failed to register ptp clk %ld\n", > PTR_ERR(cpts->ptp_clock)); > - if (!cpts->ptp_clock) > - ret = -ENODEV; > + ret = cpts->ptp_clock ? cpts->ptp_clock : (-ENODEV); > goto refclk_disable; > } > cpts->phc_index = ptp_clock_index(cpts->ptp_clock); > -- > 2.7.4 > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net/ethernet: update ret when ptp_clock is ERROR 2020-11-07 15:08 ` Richard Cochran @ 2020-11-11 13:03 ` Grygorii Strashko 0 siblings, 0 replies; 8+ messages in thread From: Grygorii Strashko @ 2020-11-11 13:03 UTC (permalink / raw) To: Richard Cochran, Wang Qing Cc: David S. Miller, Jakub Kicinski, Samuel Zou, Kurt Kanzenbach, Ivan Khoronzhuk, netdev, linux-kernel On 07/11/2020 17:08, Richard Cochran wrote: > On Fri, Nov 06, 2020 at 03:56:45PM +0800, Wang Qing wrote: >> We always have to update the value of ret, otherwise the >> error value may be the previous one. >> >> Signed-off-by: Wang Qing <wangqing@vivo.com> > > Acked-by: Richard Cochran <richardcochran@gmail.com> > Following Richard's comments: Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> > >> --- >> drivers/net/ethernet/ti/am65-cpts.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/drivers/net/ethernet/ti/am65-cpts.c b/drivers/net/ethernet/ti/am65-cpts.c >> index 75056c1..b77ff61 >> --- a/drivers/net/ethernet/ti/am65-cpts.c >> +++ b/drivers/net/ethernet/ti/am65-cpts.c >> @@ -1001,8 +1001,7 @@ struct am65_cpts *am65_cpts_create(struct device *dev, void __iomem *regs, >> if (IS_ERR_OR_NULL(cpts->ptp_clock)) { >> dev_err(dev, "Failed to register ptp clk %ld\n", >> PTR_ERR(cpts->ptp_clock)); >> - if (!cpts->ptp_clock) >> - ret = -ENODEV; >> + ret = cpts->ptp_clock ? cpts->ptp_clock : (-ENODEV); >> goto refclk_disable; >> } >> cpts->phc_index = ptp_clock_index(cpts->ptp_clock); >> -- >> 2.7.4 >> -- Best regards, grygorii ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-11-11 13:04 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2020-11-07 15:07 ` Richard Cochran 2020-11-07 15:08 ` Richard Cochran 2020-11-11 13:03 ` Grygorii Strashko
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).