diff mbox series

[2/6] net: ibm: emac: manage emac_irq with devm

Message ID 20240902181530.6852-3-rosenp@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: ibm: emac: some cleanups and devm | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
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: 7 this patch: 7
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
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: 7 this patch: 7
netdev/checkpatch warning WARNING: line length of 85 exceeds 80 columns
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
netdev/contest success net-next-2024-09-03--00-00 (tests: 714)

Commit Message

Rosen Penev Sept. 2, 2024, 6:15 p.m. UTC
It's the last to go in remove. Safe to let devm handle it.

Also move request_irq to probe for clarity. It's removed in _remove not
close.

Use dev_err instead of printk. Handles names automatically.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/ethernet/ibm/emac/core.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

Comments

Andrew Lunn Sept. 2, 2024, 8:06 p.m. UTC | #1
On Mon, Sep 02, 2024 at 11:15:11AM -0700, Rosen Penev wrote:
> It's the last to go in remove. Safe to let devm handle it.
> 
> Also move request_irq to probe for clarity. It's removed in _remove not
> close.
> 
> Use dev_err instead of printk. Handles names automatically.
> 
> +	/* Setup error IRQ handler */
> +	err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC", dev);
> +	if (err) {
> +		dev_err(&ofdev->dev, "failed to request IRQ %d", dev->emac_irq);
> +		goto err_gone;
> +	}

Is this an internal interrupt, or a GPIO? It could be it is done in
open because there is a danger the GPIO controller has not probed
yet. So here you might get an EPROBE_DEFFER, where as the much older
kernel this was written for might not of done, if just gave an error
had gave up. So dev_err_probe() might be better.

	Andrew
Rosen Penev Sept. 2, 2024, 8:26 p.m. UTC | #2
On Mon, Sep 2, 2024 at 1:06 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Mon, Sep 02, 2024 at 11:15:11AM -0700, Rosen Penev wrote:
> > It's the last to go in remove. Safe to let devm handle it.
> >
> > Also move request_irq to probe for clarity. It's removed in _remove not
> > close.
> >
> > Use dev_err instead of printk. Handles names automatically.
> >
> > +     /* Setup error IRQ handler */
> > +     err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC", dev);
> > +     if (err) {
> > +             dev_err(&ofdev->dev, "failed to request IRQ %d", dev->emac_irq);
> > +             goto err_gone;
> > +     }
>
> Is this an internal interrupt, or a GPIO? It could be it is done in
> open because there is a danger the GPIO controller has not probed
> yet. So here you might get an EPROBE_DEFFER, where as the much older
> kernel this was written for might not of done, if just gave an error
> had gave up. So dev_err_probe() might be better.
Good call on that. In my experience, I get these EPROBE_DEFER errors
on OpenWrt's ath79 target (QCA MIPS) but not on PowerPC when trying to
use GPIOs. Nevertheless it seems to be good practice to use
dev_err_probe anyway. Will fix in v2.
>
>         Andrew
Andrew Lunn Sept. 2, 2024, 8:39 p.m. UTC | #3
> > Is this an internal interrupt, or a GPIO? It could be it is done in
> > open because there is a danger the GPIO controller has not probed
> > yet. So here you might get an EPROBE_DEFFER, where as the much older
> > kernel this was written for might not of done, if just gave an error
> > had gave up. So dev_err_probe() might be better.

> Good call on that. In my experience, I get these EPROBE_DEFER errors
> on OpenWrt's ath79 target (QCA MIPS) but not on PowerPC when trying to
> use GPIOs. Nevertheless it seems to be good practice to use
> dev_err_probe anyway. Will fix in v2.

You might want to look at

https://elixir.bootlin.com/linux/v6.10.7/source/drivers/net/ethernet/ibm/emac/core.c#L2418

and then replace it by correctly handling EPROBE_DEFER.

As you said, an old driver, needing some cleanup.

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 348702f462bd..98d1b711969b 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -1228,18 +1228,10 @@  static void emac_print_link_status(struct emac_instance *dev)
 static int emac_open(struct net_device *ndev)
 {
 	struct emac_instance *dev = netdev_priv(ndev);
-	int err, i;
+	int i;
 
 	DBG(dev, "open" NL);
 
-	/* Setup error IRQ handler */
-	err = request_irq(dev->emac_irq, emac_irq, 0, "EMAC", dev);
-	if (err) {
-		printk(KERN_ERR "%s: failed to request IRQ %d\n",
-		       ndev->name, dev->emac_irq);
-		return err;
-	}
-
 	/* Allocate RX ring */
 	for (i = 0; i < NUM_RX_BUFF; ++i)
 		if (emac_alloc_rx_skb(dev, i)) {
@@ -1293,8 +1285,6 @@  static int emac_open(struct net_device *ndev)
 	return 0;
  oom:
 	emac_clean_rx_ring(dev);
-	free_irq(dev->emac_irq, dev);
-
 	return -ENOMEM;
 }
 
@@ -1408,8 +1398,6 @@  static int emac_close(struct net_device *ndev)
 	emac_clean_tx_ring(dev);
 	emac_clean_rx_ring(dev);
 
-	free_irq(dev->emac_irq, dev);
-
 	netif_carrier_off(ndev);
 
 	return 0;
@@ -3082,6 +3070,14 @@  static int emac_probe(struct platform_device *ofdev)
 		err = -ENODEV;
 		goto err_gone;
 	}
+
+	/* Setup error IRQ handler */
+	err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC", dev);
+	if (err) {
+		dev_err(&ofdev->dev, "failed to request IRQ %d", dev->emac_irq);
+		goto err_gone;
+	}
+
 	ndev->irq = dev->emac_irq;
 
 	/* Map EMAC regs */
@@ -3237,8 +3233,6 @@  static int emac_probe(struct platform_device *ofdev)
  err_irq_unmap:
 	if (dev->wol_irq)
 		irq_dispose_mapping(dev->wol_irq);
-	if (dev->emac_irq)
-		irq_dispose_mapping(dev->emac_irq);
  err_gone:
 	/* if we were on the bootlist, remove us as we won't show up and
 	 * wake up all waiters to notify them in case they were waiting
@@ -3284,9 +3278,6 @@  static void emac_remove(struct platform_device *ofdev)
 
 	if (dev->wol_irq)
 		irq_dispose_mapping(dev->wol_irq);
-	if (dev->emac_irq)
-		irq_dispose_mapping(dev->emac_irq);
-
 }
 
 /* XXX Features in here should be replaced by properties... */