* [PATCH] net: allwinner: Use devm_clk_get_enabled() in emac_probe()
@ 2026-11-24 17:19 Markus Elfring
2026-11-24 20:17 ` Andy Shevchenko
2026-11-25 17:22 ` [PATCH] " sashiko-bot
0 siblings, 2 replies; 4+ messages in thread
From: Markus Elfring @ 2026-11-24 17:19 UTC (permalink / raw)
To: linux-sunxi, linux-arm-kernel, netdev, Andrew Lunn, Arnd Bergmann,
bui duc phuc, Chen-Yu Tsai, David S. Miller, Eric Dumazet,
Frank Li, Hans de Goede, Jakub Kicinski, Jernej Skrabec,
Joe Damato, Julia Lawall, Li Youhong, Maxime Ripard, Paolo Abeni,
Samuel Holland
Cc: LKML, kernel-janitors, Andy Shevchenko, Christophe Jaillet,
Florian Fainelli
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 24 Nov 2026 17:56:11 +0100
* Reuse existing functionality from devm_clk_get_enabled() instead of
keeping duplicate source code.
* Delete a clk_disable_unprepare() call on an error handling path
and in the implementation of the function “emac_remove”.
* Omit the label “out_clk_disable_unprepare”.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/net/ethernet/allwinner/sun4i-emac.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
index d7ee42b2c197..c075356cf6cc 100644
--- a/drivers/net/ethernet/allwinner/sun4i-emac.c
+++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
@@ -1001,22 +1001,16 @@ static int emac_probe(struct platform_device *pdev)
if (emac_configure_dma(db))
netdev_info(ndev, "configure dma failed. disable dma.\n");
- db->clk = devm_clk_get(&pdev->dev, NULL);
+ db->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(db->clk)) {
ret = PTR_ERR(db->clk);
goto out_dispose_mapping;
}
- ret = clk_prepare_enable(db->clk);
- if (ret) {
- dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", ret);
- goto out_dispose_mapping;
- }
-
ret = sunxi_sram_claim(&pdev->dev);
if (ret) {
dev_err(&pdev->dev, "Error couldn't map SRAM to device\n");
- goto out_clk_disable_unprepare;
+ goto out_dispose_mapping;
}
db->phy_node = of_parse_phandle(np, "phy-handle", 0);
@@ -1065,8 +1059,6 @@ static int emac_probe(struct platform_device *pdev)
out_release_sram:
of_node_put(db->phy_node);
sunxi_sram_release(&pdev->dev);
-out_clk_disable_unprepare:
- clk_disable_unprepare(db->clk);
out_dispose_mapping:
irq_dispose_mapping(ndev->irq);
dma_release_channel(db->rx_chan);
@@ -1093,7 +1085,6 @@ static void emac_remove(struct platform_device *pdev)
unregister_netdev(ndev);
of_node_put(db->phy_node);
sunxi_sram_release(&pdev->dev);
- clk_disable_unprepare(db->clk);
irq_dispose_mapping(ndev->irq);
iounmap(db->membase);
free_netdev(ndev);
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: allwinner: Use devm_clk_get_enabled() in emac_probe()
2026-11-24 17:19 [PATCH] net: allwinner: Use devm_clk_get_enabled() in emac_probe() Markus Elfring
@ 2026-11-24 20:17 ` Andy Shevchenko
2026-11-25 12:48 ` Markus Elfring
2026-11-25 17:22 ` [PATCH] " sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-11-24 20:17 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-sunxi, linux-arm-kernel, netdev, Andrew Lunn, Arnd Bergmann,
bui duc phuc, Chen-Yu Tsai, David S. Miller, Eric Dumazet,
Frank Li, Hans de Goede, Jakub Kicinski, Jernej Skrabec,
Joe Damato, Julia Lawall, Li Youhong, Maxime Ripard, Paolo Abeni,
Samuel Holland, LKML, kernel-janitors, Christophe Jaillet,
Florian Fainelli
On Tue, Nov 24, 2026 at 06:19:54PM +0100, Markus Elfring wrote:
>
> * Reuse existing functionality from devm_clk_get_enabled() instead of
> keeping duplicate source code.
>
> * Delete a clk_disable_unprepare() call on an error handling path
> and in the implementation of the function “emac_remove”.
>
> * Omit the label “out_clk_disable_unprepare”.
>
> This issue was detected by using the Coccinelle software.
This breaks the order at remove and probe error path cases.
Note, devm_*() at this case will keep just a clk object, but
the actual enabling is done explicitly. W/o testing on real
HW it's hard to say if this order is strict or not.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: net: allwinner: Use devm_clk_get_enabled() in emac_probe()
2026-11-24 20:17 ` Andy Shevchenko
@ 2026-11-25 12:48 ` Markus Elfring
0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-11-25 12:48 UTC (permalink / raw)
To: Andy Shevchenko, linux-sunxi, linux-arm-kernel, netdev
Cc: Andrew Lunn, Arnd Bergmann, bui duc phuc, Chen-Yu Tsai,
David S. Miller, Eric Dumazet, Frank Li, Hans de Goede,
Jakub Kicinski, Jernej Skrabec, Joe Damato, Julia Lawall,
Li Youhong, Maxime Ripard, Paolo Abeni, Samuel Holland, LKML,
kernel-janitors, Christophe Jaillet, Florian Fainelli
> This breaks the order at remove and probe error path cases.
Would the proposed control flow adjustment be different from a “break”?
> Note, devm_*() at this case will keep just a clk object, but
> the actual enabling is done explicitly.
https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/net/ethernet/allwinner/sun4i-emac.c#L960-L1082
> W/o testing on real
> HW it's hard to say if this order is strict or not.
How will the support refined further also for collateral evolution together with
devres programming interfaces?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: allwinner: Use devm_clk_get_enabled() in emac_probe()
2026-11-24 17:19 [PATCH] net: allwinner: Use devm_clk_get_enabled() in emac_probe() Markus Elfring
2026-11-24 20:17 ` Andy Shevchenko
@ 2026-11-25 17:22 ` sashiko-bot
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-25 17:22 UTC (permalink / raw)
To: Markus Elfring, linux-sunxi
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] net: sun4i-emac: use-after-free in emac_remove() [1]
--
commit c91169d2a4aeb95968164b2a476fe9e5315cf021
Author: Markus Elfring <elfring@users.sourceforge.net>
net: allwinner: Use devm_clk_get_enabled() in emac_probe()
This commit replaces devm_clk_get() and clk_prepare_enable() with
devm_clk_get_enabled() in emac_probe() and drops the explicit
clk_disable_unprepare() calls from the error path and emac_remove().
> diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
> index d7ee42b2c1976..c075356cf6ccd 100644
> --- a/drivers/net/ethernet/allwinner/sun4i-emac.c
> +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
[ ... ]
> @@ -1093,7 +1085,6 @@ static void emac_remove(struct platform_device *pdev)
> unregister_netdev(ndev);
> of_node_put(db->phy_node);
> sunxi_sram_release(&pdev->dev);
> - clk_disable_unprepare(db->clk);
> irq_dispose_mapping(ndev->irq);
> iounmap(db->membase);
> free_netdev(ndev);
[Severity: Critical]
This problem wasn't introduced by this patch, but can releasing
db->rx_chan before unregister_netdev() in emac_remove() cause a
use-after-free [1]?
drivers/net/ethernet/allwinner/sun4i-emac.c:emac_remove() {
...
if (db->rx_chan) {
dmaengine_terminate_all(db->rx_chan);
dma_release_channel(db->rx_chan);
}
unregister_netdev(ndev);
...
}
Until unregister_netdev() shuts down the interface, an incoming packet can
still trigger an RX interrupt and submit DMA on the freed db->rx_chan:
CPU0 CPU1
emac_remove()
dma_release_channel(db->rx_chan)
emac_interrupt()
emac_rx()
emac_dma_inblk_32bit()
dmaengine_prep_slave_single(db->rx_chan, ...)
<-- use-after-free
unregister_netdev(ndev)
[1] https://sashiko.dev/#/bug/linux-bb13c48b-2561-4c90-be1e-ab97f0255c59
--
Sashiko AI review · https://sashiko.dev/#/patchset/780975ed-825f-4f9b-8ac2-67664a7a2a2f@web.de?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 17:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 17:19 [PATCH] net: allwinner: Use devm_clk_get_enabled() in emac_probe() Markus Elfring
2026-11-24 20:17 ` Andy Shevchenko
2026-11-25 12:48 ` Markus Elfring
2026-11-25 17:22 ` [PATCH] " sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox