2023-11-17 09:32:19

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH wifi-next 0/6] wifi: Convert to platform remove callback returning void

Hello,

this series converts the platform drivers below drivers/net/wireless to
make use of .remove_new().

See commit 5c5a7680e67b ("platform: Provide a remove callback that
returns no value") for an extended explanation and the eventual goal.
The TL;DR; is to make it harder for driver authors to leak resources
without noticing.

Best regards
Uwe

Uwe Kleine-König (6):
wifi: ath11k: Convert to platform remove callback returning void
wifi: ath5k: Convert to platform remove callback returning void
wifi: ath9k: Convert to platform remove callback returning void
wifi: wcn36xx: Convert to platform remove callback returning void
wifi: brcmfmac: Convert to platform remove callback returning void
wifi: mt76: Convert to platform remove callback returning void

drivers/net/wireless/ath/ath11k/ahb.c | 6 ++----
drivers/net/wireless/ath/ath5k/ahb.c | 8 +++-----
drivers/net/wireless/ath/ath9k/ahb.c | 6 ++----
drivers/net/wireless/ath/wcn36xx/main.c | 6 ++----
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c | 6 ++----
drivers/net/wireless/mediatek/mt76/mt7603/soc.c | 7 ++-----
drivers/net/wireless/mediatek/mt76/mt7615/soc.c | 6 ++----
drivers/net/wireless/mediatek/mt76/mt7915/soc.c | 6 ++----
8 files changed, 17 insertions(+), 34 deletions(-)

base-commit: eff99d8edbed7918317331ebd1e365d8e955d65e
--
2.42.0


2023-11-17 09:32:29

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH wifi-next 1/6] wifi: ath11k: Convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.

To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new(), which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <[email protected]>
---
drivers/net/wireless/ath/ath11k/ahb.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c
index 235336ef2a7a..f8ae9ba85500 100644
--- a/drivers/net/wireless/ath/ath11k/ahb.c
+++ b/drivers/net/wireless/ath/ath11k/ahb.c
@@ -1251,7 +1251,7 @@ static void ath11k_ahb_free_resources(struct ath11k_base *ab)
platform_set_drvdata(pdev, NULL);
}

-static int ath11k_ahb_remove(struct platform_device *pdev)
+static void ath11k_ahb_remove(struct platform_device *pdev)
{
struct ath11k_base *ab = platform_get_drvdata(pdev);

@@ -1267,8 +1267,6 @@ static int ath11k_ahb_remove(struct platform_device *pdev)

qmi_fail:
ath11k_ahb_free_resources(ab);
-
- return 0;
}

static void ath11k_ahb_shutdown(struct platform_device *pdev)
@@ -1296,7 +1294,7 @@ static struct platform_driver ath11k_ahb_driver = {
.of_match_table = ath11k_ahb_of_match,
},
.probe = ath11k_ahb_probe,
- .remove = ath11k_ahb_remove,
+ .remove_new = ath11k_ahb_remove,
.shutdown = ath11k_ahb_shutdown,
};

--
2.42.0

2023-11-17 09:32:39

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH wifi-next 2/6] wifi: ath5k: Convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.

To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new(), which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <[email protected]>
---
drivers/net/wireless/ath/ath5k/ahb.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/ath/ath5k/ahb.c b/drivers/net/wireless/ath/ath5k/ahb.c
index 08bd5d3b00f1..f27308ccb2f1 100644
--- a/drivers/net/wireless/ath/ath5k/ahb.c
+++ b/drivers/net/wireless/ath/ath5k/ahb.c
@@ -185,7 +185,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
return ret;
}

-static int ath_ahb_remove(struct platform_device *pdev)
+static void ath_ahb_remove(struct platform_device *pdev)
{
struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
struct ieee80211_hw *hw = platform_get_drvdata(pdev);
@@ -193,7 +193,7 @@ static int ath_ahb_remove(struct platform_device *pdev)
u32 reg;

if (!hw)
- return 0;
+ return;

ah = hw->priv;

@@ -215,13 +215,11 @@ static int ath_ahb_remove(struct platform_device *pdev)
ath5k_deinit_ah(ah);
iounmap(ah->iobase);
ieee80211_free_hw(hw);
-
- return 0;
}

static struct platform_driver ath_ahb_driver = {
.probe = ath_ahb_probe,
- .remove = ath_ahb_remove,
+ .remove_new = ath_ahb_remove,
.driver = {
.name = "ar231x-wmac",
},
--
2.42.0

2023-11-17 09:32:44

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH wifi-next 6/6] wifi: mt76: Convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.

To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new(), which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

Trivially convert the three mt76 drivers from always returning zero in
the remove callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <[email protected]>
---
drivers/net/wireless/mediatek/mt76/mt7603/soc.c | 7 ++-----
drivers/net/wireless/mediatek/mt76/mt7615/soc.c | 6 ++----
drivers/net/wireless/mediatek/mt76/mt7915/soc.c | 6 ++----
3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7603/soc.c b/drivers/net/wireless/mediatek/mt76/mt7603/soc.c
index ba927033bbe8..ec02148a7f1f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7603/soc.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7603/soc.c
@@ -52,15 +52,12 @@ mt76_wmac_probe(struct platform_device *pdev)
return ret;
}

-static int
-mt76_wmac_remove(struct platform_device *pdev)
+static void mt76_wmac_remove(struct platform_device *pdev)
{
struct mt76_dev *mdev = platform_get_drvdata(pdev);
struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);

mt7603_unregister_device(dev);
-
- return 0;
}

static const struct of_device_id of_wmac_match[] = {
@@ -74,7 +71,7 @@ MODULE_FIRMWARE(MT7628_FIRMWARE_E2);

struct platform_driver mt76_wmac_driver = {
.probe = mt76_wmac_probe,
- .remove = mt76_wmac_remove,
+ .remove_new = mt76_wmac_remove,
.driver = {
.name = "mt76_wmac",
.of_match_table = of_wmac_match,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/soc.c b/drivers/net/wireless/mediatek/mt76/mt7615/soc.c
index f13d1b418742..12e3e4a91d27 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/soc.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/soc.c
@@ -45,13 +45,11 @@ static int mt7622_wmac_probe(struct platform_device *pdev)
return mt7615_mmio_probe(&pdev->dev, mem_base, irq, mt7615e_reg_map);
}

-static int mt7622_wmac_remove(struct platform_device *pdev)
+static void mt7622_wmac_remove(struct platform_device *pdev)
{
struct mt7615_dev *dev = platform_get_drvdata(pdev);

mt7615_unregister_device(dev);
-
- return 0;
}

static const struct of_device_id mt7622_wmac_of_match[] = {
@@ -65,7 +63,7 @@ struct platform_driver mt7622_wmac_driver = {
.of_match_table = mt7622_wmac_of_match,
},
.probe = mt7622_wmac_probe,
- .remove = mt7622_wmac_remove,
+ .remove_new = mt7622_wmac_remove,
};

MODULE_FIRMWARE(MT7622_FIRMWARE_N9);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/soc.c b/drivers/net/wireless/mediatek/mt76/mt7915/soc.c
index 06e3d9db996c..8b4809703efc 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/soc.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/soc.c
@@ -1282,13 +1282,11 @@ static int mt798x_wmac_probe(struct platform_device *pdev)
return ret;
}

-static int mt798x_wmac_remove(struct platform_device *pdev)
+static void mt798x_wmac_remove(struct platform_device *pdev)
{
struct mt7915_dev *dev = platform_get_drvdata(pdev);

mt7915_unregister_device(dev);
-
- return 0;
}

static const struct of_device_id mt798x_wmac_of_match[] = {
@@ -1305,7 +1303,7 @@ struct platform_driver mt798x_wmac_driver = {
.of_match_table = mt798x_wmac_of_match,
},
.probe = mt798x_wmac_probe,
- .remove = mt798x_wmac_remove,
+ .remove_new = mt798x_wmac_remove,
};

MODULE_FIRMWARE(MT7986_FIRMWARE_WA);
--
2.42.0

2023-11-17 17:23:45

by Jeff Johnson

[permalink] [raw]
Subject: Re: [PATCH wifi-next 1/6] wifi: ath11k: Convert to platform remove callback returning void

On 11/17/2023 1:30 AM, Uwe Kleine-König wrote:
> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>
Acked-by: Jeff Johnson <[email protected]>

2023-11-17 19:19:12

by Jeff Johnson

[permalink] [raw]
Subject: Re: [PATCH wifi-next 2/6] wifi: ath5k: Convert to platform remove callback returning void

On 11/17/2023 1:30 AM, Uwe Kleine-König wrote:
> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>
Reviewed-by: Jeff Johnson <[email protected]>

2023-11-17 19:22:05

by Jeff Johnson

[permalink] [raw]
Subject: Re: [PATCH wifi-next 6/6] wifi: mt76: Convert to platform remove callback returning void

On 11/17/2023 1:31 AM, Uwe Kleine-König wrote:
> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert the three mt76 drivers from always returning zero in
> the remove callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>
not my driver but since it is trivial
Reviewed-by: Jeff Johnson <[email protected]>

2023-11-30 17:15:30

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH wifi-next 1/6] wifi: ath11k: Convert to platform remove callback returning void

Uwe Kleine-König <[email protected]> wrote:

> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>
> Acked-by: Jeff Johnson <[email protected]>
> Signed-off-by: Kalle Valo <[email protected]>

Patch applied to ath-next branch of ath.git, thanks.

62e31362033e wifi: ath11k: Convert to platform remove callback returning void

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


2023-12-01 16:06:53

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH wifi-next 2/6] wifi: ath5k: Convert to platform remove callback returning void

Uwe Kleine-König <[email protected]> wrote:

> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>
> Reviewed-by: Jeff Johnson <[email protected]>
> Signed-off-by: Kalle Valo <[email protected]>

2 patches applied to ath-next branch of ath.git, thanks.

b5418d170b7c wifi: ath5k: Convert to platform remove callback returning void
8cc18a70913f wifi: wcn36xx: Convert to platform remove callback returning void

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches