diff mbox series

[net-next,v2,03/11] net: stmmac: dwmac-qcom-ethqos: Drop an if with an always false condition

Message ID 20230508142637.1449363-4-u.kleine-koenig@pengutronix.de (mailing list archive)
State Accepted
Commit c5f3ffe35cc92cce6292b5304409f3edc9281d66
Delegated to: Netdev Maintainers
Headers show
Series net: stmmac: Convert to platform remove callback returning void | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
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: 8 this patch: 8
netdev/cc_maintainers success CCed 13 of 13 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
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 success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Uwe Kleine-König May 8, 2023, 2:26 p.m. UTC
The remove callback is only ever called after .probe() returned
successfully. After that get_stmmac_bsp_priv() always return non-NULL.

Side note: The early exit would also be a bug because the return value
of qcom_ethqos_remove() is ignored by the device core and the device is
unbound unconditionally. So exiting early resulted in a dangerous
resource leak as all devm allocated resources (some memory and the
register mappings) are freed but the network device stays around.  Using
the network device afterwards probably oopses.

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Michal Kubiak May 8, 2023, 8:26 p.m. UTC | #1
On Mon, May 08, 2023 at 04:26:29PM +0200, Uwe Kleine-König wrote:
> The remove callback is only ever called after .probe() returned
> successfully. After that get_stmmac_bsp_priv() always return non-NULL.

Nitpick: "always returns" or "will always return".

> 
> Side note: The early exit would also be a bug because the return value
> of qcom_ethqos_remove() is ignored by the device core and the device is
> unbound unconditionally. So exiting early resulted in a dangerous
> resource leak as all devm allocated resources (some memory and the
> register mappings) are freed but the network device stays around.  Using
> the network device afterwards probably oopses.
> 
> Reviewed-by: Simon Horman <simon.horman@corigine.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>

Thanks,
Michal
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
index 494c22243259..bf17c6c8f2eb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
@@ -667,11 +667,7 @@  static int qcom_ethqos_probe(struct platform_device *pdev)
 
 static int qcom_ethqos_remove(struct platform_device *pdev)
 {
-	struct qcom_ethqos *ethqos;
-
-	ethqos = get_stmmac_bsp_priv(&pdev->dev);
-	if (!ethqos)
-		return -ENODEV;
+	struct qcom_ethqos *ethqos = get_stmmac_bsp_priv(&pdev->dev);
 
 	stmmac_pltfr_remove(pdev);
 	ethqos_clks_config(ethqos, false);