ptp_clock: future-proofing drivers against PTP subsystem becoming optional
authorNicolas Pitre <nicolas.pitre@linaro.org>
Tue, 20 Sep 2016 23:25:58 +0000 (19:25 -0400)
committerDavid S. Miller <davem@davemloft.net>
Thu, 22 Sep 2016 06:18:33 +0000 (02:18 -0400)
Drivers must be ready to accept NULL from ptp_clock_register() if the
PTP clock subsystem is configured out.

This patch documents that and ensures that all drivers cope well
with a NULL return.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Reviewed-by: Eugenia Emantayev <eugenia@mellanox.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Edward Cree <ecree@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/intel/e1000e/ptp.c
drivers/net/ethernet/intel/i40e/i40e_ptp.c
drivers/net/ethernet/intel/igb/igb_ptp.c
drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
drivers/net/ethernet/mellanox/mlx4/en_clock.c
drivers/net/ethernet/mellanox/mlx5/core/en_clock.c
drivers/net/ethernet/sfc/ptp.c
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
include/linux/ptp_clock_kernel.h

index 2e1b17ad52a3e55984fb8303ab191bb636aa8fc8..ad03763e009ae4d1e6796c78b865a9bdda6b8489 100644 (file)
@@ -334,7 +334,7 @@ void e1000e_ptp_init(struct e1000_adapter *adapter)
        if (IS_ERR(adapter->ptp_clock)) {
                adapter->ptp_clock = NULL;
                e_err("ptp_clock_register failed\n");
-       } else {
+       } else if (adapter->ptp_clock) {
                e_info("registered PHC clock\n");
        }
 }
index ed39cbad24bdd2c728c4d54817f31ac664c13a07..f1feceab758a5235237df685f2b8666a5a9c0ffd 100644 (file)
@@ -669,7 +669,7 @@ void i40e_ptp_init(struct i40e_pf *pf)
                pf->ptp_clock = NULL;
                dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n",
                        __func__);
-       } else {
+       } else if (pf->ptp_clock) {
                struct timespec64 ts;
                u32 regval;
 
index 66dfa2085cc768141b370a3e080ba3931b3aceb3..1dd14e166dc800fb9ccb0f07091c22a7a02e3896 100644 (file)
@@ -1159,7 +1159,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
        if (IS_ERR(adapter->ptp_clock)) {
                adapter->ptp_clock = NULL;
                dev_err(&adapter->pdev->dev, "ptp_clock_register failed\n");
-       } else {
+       } else if (adapter->ptp_clock) {
                dev_info(&adapter->pdev->dev, "added PHC on %s\n",
                         adapter->netdev->name);
                adapter->ptp_flags |= IGB_PTP_ENABLED;
index e5431bfe3339be0214ac58d158544aa9c82d8105..a92277683a649b4bf7f42987a7d0ecdad311f04c 100644 (file)
@@ -1254,7 +1254,7 @@ static long ixgbe_ptp_create_clock(struct ixgbe_adapter *adapter)
                adapter->ptp_clock = NULL;
                e_dev_err("ptp_clock_register failed\n");
                return err;
-       } else
+       } else if (adapter->ptp_clock)
                e_dev_info("registered PHC device on %s\n", netdev->name);
 
        /* set default timestamp mode to disabled here. We do this in
index 1494997c4f7e3bef36141ea439d812ca9bb1a335..08fc5fc56d43b489ab6a8502012b5cad925a0e7b 100644 (file)
@@ -298,7 +298,7 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
        if (IS_ERR(mdev->ptp_clock)) {
                mdev->ptp_clock = NULL;
                mlx4_err(mdev, "ptp_clock_register failed\n");
-       } else {
+       } else if (mdev->ptp_clock) {
                mlx4_info(mdev, "registered PHC clock\n");
        }
 
index 847a8f3ac2b27fda609bd95f0accbfe85d994104..13dc388667b6002c311cac9293d2b8894f9afdf2 100644 (file)
@@ -273,7 +273,7 @@ void mlx5e_timestamp_init(struct mlx5e_priv *priv)
 
        tstamp->ptp = ptp_clock_register(&tstamp->ptp_info,
                                         &priv->mdev->pdev->dev);
-       if (IS_ERR_OR_NULL(tstamp->ptp)) {
+       if (IS_ERR(tstamp->ptp)) {
                mlx5_core_warn(priv->mdev, "ptp_clock_register failed %ld\n",
                               PTR_ERR(tstamp->ptp));
                tstamp->ptp = NULL;
index dd204d9704c6041f74dfe9cb2189115ae173d8ee..77a5364f7a109927aa905f6ec8403cfa3d980136 100644 (file)
@@ -1269,13 +1269,13 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel)
                if (IS_ERR(ptp->phc_clock)) {
                        rc = PTR_ERR(ptp->phc_clock);
                        goto fail3;
-               }
-
-               INIT_WORK(&ptp->pps_work, efx_ptp_pps_worker);
-               ptp->pps_workwq = create_singlethread_workqueue("sfc_pps");
-               if (!ptp->pps_workwq) {
-                       rc = -ENOMEM;
-                       goto fail4;
+               } else if (ptp->phc_clock) {
+                       INIT_WORK(&ptp->pps_work, efx_ptp_pps_worker);
+                       ptp->pps_workwq = create_singlethread_workqueue("sfc_pps");
+                       if (!ptp->pps_workwq) {
+                               rc = -ENOMEM;
+                               goto fail4;
+                       }
                }
        }
        ptp->nic_ts_enabled = false;
index 170a18b61281d5ab406e96ce3231878f08fbad28..6e3b82972ce87e08eea493f4f7a0831e9f080849 100644 (file)
@@ -187,7 +187,7 @@ int stmmac_ptp_register(struct stmmac_priv *priv)
        if (IS_ERR(priv->ptp_clock)) {
                priv->ptp_clock = NULL;
                pr_err("ptp_clock_register() failed on %s\n", priv->dev->name);
-       } else
+       } else if (priv->ptp_clock)
                pr_debug("Added PTP HW clock successfully on %s\n",
                         priv->dev->name);
 
index 6b15e168148a3be73c52c35da6fc4a0f4a5b6ba6..5ad54fc66cf0f589aa9eca3275683e56e7650107 100644 (file)
@@ -127,6 +127,11 @@ struct ptp_clock;
  *
  * @info:   Structure describing the new clock.
  * @parent: Pointer to the parent device of the new clock.
+ *
+ * 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.
  */
 
 extern struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,