diff mbox series

[net-next] stmmac: dwmac-intel-plat: remove redundant check dwmac->data in probe

Message ID 20240930183926.2112546-1-mordan@ispras.ru (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] stmmac: dwmac-intel-plat: remove redundant check dwmac->data in probe | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: richardcochran@gmail.com
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 12 this patch: 12
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 77 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Vitalii Mordan Sept. 30, 2024, 6:39 p.m. UTC
The driver’s compatibility with devices is confirmed earlier in
platform_match(). Since reaching probe means the device is valid,
the extra check can be removed to simplify the code.

Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
---
 .../stmicro/stmmac/dwmac-intel-plat.c         | 64 +++++++++----------
 1 file changed, 31 insertions(+), 33 deletions(-)

Comments

Andrew Lunn Sept. 30, 2024, 7:17 p.m. UTC | #1
On Mon, Sep 30, 2024 at 09:39:26PM +0300, Vitalii Mordan wrote:
> The driver’s compatibility with devices is confirmed earlier in
> platform_match(). Since reaching probe means the device is valid,
> the extra check can be removed to simplify the code.
>  
>  	dwmac->data = device_get_match_data(&pdev->dev);
> -	if (dwmac->data) {

You say this cannot fail, but my guess is, there are static code
analysers which cannot determine it cannot fail. As a result, those
developers blindly following bots are going to want to test the return
value from device_get_match_data().

You might want to prevent such patches by adding a comment:

/* This cannot fail because....

   Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
index d68f0c4e7835..9139b2b1bf0b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
@@ -98,46 +98,44 @@  static int intel_eth_plat_probe(struct platform_device *pdev)
 	dwmac->tx_clk = NULL;
 
 	dwmac->data = device_get_match_data(&pdev->dev);
-	if (dwmac->data) {
-		if (dwmac->data->fix_mac_speed)
-			plat_dat->fix_mac_speed = dwmac->data->fix_mac_speed;
-
-		/* Enable TX clock */
-		if (dwmac->data->tx_clk_en) {
-			dwmac->tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
-			if (IS_ERR(dwmac->tx_clk))
-				return PTR_ERR(dwmac->tx_clk);
-
-			clk_prepare_enable(dwmac->tx_clk);
-
-			/* Check and configure TX clock rate */
-			rate = clk_get_rate(dwmac->tx_clk);
-			if (dwmac->data->tx_clk_rate &&
-			    rate != dwmac->data->tx_clk_rate) {
-				rate = dwmac->data->tx_clk_rate;
-				ret = clk_set_rate(dwmac->tx_clk, rate);
-				if (ret) {
-					dev_err(&pdev->dev,
-						"Failed to set tx_clk\n");
-					return ret;
-				}
-			}
-		}
-
-		/* Check and configure PTP ref clock rate */
-		rate = clk_get_rate(plat_dat->clk_ptp_ref);
-		if (dwmac->data->ptp_ref_clk_rate &&
-		    rate != dwmac->data->ptp_ref_clk_rate) {
-			rate = dwmac->data->ptp_ref_clk_rate;
-			ret = clk_set_rate(plat_dat->clk_ptp_ref, rate);
+	if (dwmac->data->fix_mac_speed)
+		plat_dat->fix_mac_speed = dwmac->data->fix_mac_speed;
+
+	/* Enable TX clock */
+	if (dwmac->data->tx_clk_en) {
+		dwmac->tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
+		if (IS_ERR(dwmac->tx_clk))
+			return PTR_ERR(dwmac->tx_clk);
+
+		clk_prepare_enable(dwmac->tx_clk);
+
+		/* Check and configure TX clock rate */
+		rate = clk_get_rate(dwmac->tx_clk);
+		if (dwmac->data->tx_clk_rate &&
+		    rate != dwmac->data->tx_clk_rate) {
+			rate = dwmac->data->tx_clk_rate;
+			ret = clk_set_rate(dwmac->tx_clk, rate);
 			if (ret) {
 				dev_err(&pdev->dev,
-					"Failed to set clk_ptp_ref\n");
+					"Failed to set tx_clk\n");
 				return ret;
 			}
 		}
 	}
 
+	/* Check and configure PTP ref clock rate */
+	rate = clk_get_rate(plat_dat->clk_ptp_ref);
+	if (dwmac->data->ptp_ref_clk_rate &&
+	    rate != dwmac->data->ptp_ref_clk_rate) {
+		rate = dwmac->data->ptp_ref_clk_rate;
+		ret = clk_set_rate(plat_dat->clk_ptp_ref, rate);
+		if (ret) {
+			dev_err(&pdev->dev,
+				"Failed to set clk_ptp_ref\n");
+			return ret;
+		}
+	}
+
 	plat_dat->bsp_priv = dwmac;
 	plat_dat->eee_usecs_rate = plat_dat->clk_ptp_rate;