net: stmmac: platform: provide stmmac_pltfr_init()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 23 Jun 2023 10:04:07 +0000 (12:04 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 24 Jun 2023 22:35:59 +0000 (15:35 -0700)
Provide a helper wrapper around calling the platform's init() callback.
This allows users to skip checking if the callback exists.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Link: https://lore.kernel.org/r/20230623100417.93592-2-brgl@bgdev.pl
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h

index 3c6b55b..41ca4fc 100644 (file)
@@ -702,6 +702,25 @@ int stmmac_get_platform_resources(struct platform_device *pdev,
 EXPORT_SYMBOL_GPL(stmmac_get_platform_resources);
 
 /**
+ * stmmac_pltfr_init
+ * @pdev: pointer to the platform device
+ * @plat: driver data platform structure
+ * Description: Call the platform's init callback (if any) and propagate
+ * the return value.
+ */
+int stmmac_pltfr_init(struct platform_device *pdev,
+                     struct plat_stmmacenet_data *plat)
+{
+       int ret = 0;
+
+       if (plat->init)
+               ret = plat->init(pdev, plat->bsp_priv);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(stmmac_pltfr_init);
+
+/**
  * stmmac_pltfr_remove
  * @pdev: platform device pointer
  * Description: this function calls the main to free the net resources
@@ -755,9 +774,11 @@ static int __maybe_unused stmmac_pltfr_resume(struct device *dev)
        struct net_device *ndev = dev_get_drvdata(dev);
        struct stmmac_priv *priv = netdev_priv(ndev);
        struct platform_device *pdev = to_platform_device(dev);
+       int ret;
 
-       if (priv->plat->init)
-               priv->plat->init(pdev, priv->plat->bsp_priv);
+       ret = stmmac_pltfr_init(pdev, priv->plat->bsp_priv);
+       if (ret)
+               return ret;
 
        return stmmac_resume(dev);
 }
index f7e4579..6a2cd47 100644 (file)
@@ -19,6 +19,9 @@ void stmmac_remove_config_dt(struct platform_device *pdev,
 int stmmac_get_platform_resources(struct platform_device *pdev,
                                  struct stmmac_resources *stmmac_res);
 
+int stmmac_pltfr_init(struct platform_device *pdev,
+                     struct plat_stmmacenet_data *plat);
+
 void stmmac_pltfr_remove(struct platform_device *pdev);
 extern const struct dev_pm_ops stmmac_pltfr_pm_ops;