All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Alex Elder <elder@kernel.org>,
	netdev@vger.kernel.org, kernel@pengutronix.de
Subject: [PATCH net-next v2 1/9] net: ipa: Convert to platform remove callback returning void
Date: Mon,  4 Dec 2023 19:30:41 +0100	[thread overview]
Message-ID: <c43193b9a002e88da36b111bb44ce2973ecde722.1701713943.git.u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <cover.1701713943.git.u.kleine-koenig@pengutronix.de>

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.

Link: https://lore.kernel.org/r/20231117095922.876489-3-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/net/ipa/ipa_main.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
index 86884c21e792..00475fd7a205 100644
--- a/drivers/net/ipa/ipa_main.c
+++ b/drivers/net/ipa/ipa_main.c
@@ -943,7 +943,7 @@ static int ipa_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int ipa_remove(struct platform_device *pdev)
+static void ipa_remove(struct platform_device *pdev)
 {
 	struct ipa *ipa = dev_get_drvdata(&pdev->dev);
 	struct ipa_power *power = ipa->power;
@@ -966,8 +966,16 @@ static int ipa_remove(struct platform_device *pdev)
 			usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC);
 			ret = ipa_modem_stop(ipa);
 		}
-		if (ret)
-			return ret;
+		if (ret) {
+			/*
+			 * Not cleaning up here properly might also yield a
+			 * crash later on. As the device is still unregistered
+			 * in this case, this might even yield a crash later on.
+			 */
+			dev_err(dev, "Failed to stop modem (%pe), leaking resources\n",
+				ERR_PTR(ret));
+			return;
+		}
 
 		ipa_teardown(ipa);
 	}
@@ -985,17 +993,6 @@ static int ipa_remove(struct platform_device *pdev)
 	ipa_power_exit(power);
 
 	dev_info(dev, "IPA driver removed");
-
-	return 0;
-}
-
-static void ipa_shutdown(struct platform_device *pdev)
-{
-	int ret;
-
-	ret = ipa_remove(pdev);
-	if (ret)
-		dev_err(&pdev->dev, "shutdown: remove returned %d\n", ret);
 }
 
 static const struct attribute_group *ipa_attribute_groups[] = {
@@ -1008,8 +1005,8 @@ static const struct attribute_group *ipa_attribute_groups[] = {
 
 static struct platform_driver ipa_driver = {
 	.probe		= ipa_probe,
-	.remove		= ipa_remove,
-	.shutdown	= ipa_shutdown,
+	.remove_new	= ipa_remove,
+	.shutdown	= ipa_remove,
 	.driver	= {
 		.name		= "ipa",
 		.pm		= &ipa_pm_ops,
-- 
2.42.0


  reply	other threads:[~2023-12-04 18:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 18:30 [PATCH net-next v2 0/9] net*: Convert to platform remove callback returning void Uwe Kleine-König
2023-12-04 18:30 ` Uwe Kleine-König
2023-12-04 18:30 ` Uwe Kleine-König
2023-12-04 18:30 ` Uwe Kleine-König [this message]
2023-12-04 18:30 ` [PATCH net-next v2 2/9] net: fjes: " Uwe Kleine-König
2023-12-04 18:30 ` [PATCH net-next v2 3/9] net: pcs: rzn1-miic: " Uwe Kleine-König
2023-12-04 22:50   ` Russell King (Oracle)
2023-12-04 18:30 ` [PATCH net-next v2 4/9] net: sfp: " Uwe Kleine-König
2023-12-04 22:49   ` Russell King (Oracle)
2023-12-04 18:30 ` [PATCH net-next v2 5/9] net: wan/fsl_ucc_hdlc: " Uwe Kleine-König
2023-12-04 18:30   ` Uwe Kleine-König
2023-12-04 18:30 ` [PATCH net-next v2 6/9] net: wan/ixp4xx_hss: " Uwe Kleine-König
2023-12-04 18:30   ` Uwe Kleine-König
2023-12-05 22:43   ` Linus Walleij
2023-12-05 22:43     ` Linus Walleij
2023-12-04 18:30 ` [PATCH net-next v2 7/9] net: wwan: qcom_bam_dmux: " Uwe Kleine-König
2023-12-04 18:30 ` [PATCH net-next v2 8/9] ieee802154: fakelb: " Uwe Kleine-König
2023-12-04 18:30 ` [PATCH net-next v2 9/9] ieee802154: hwsim: " Uwe Kleine-König
2023-12-05  6:51 ` [PATCH net-next v2 0/9] net*: " Miquel Raynal
2023-12-05  6:51   ` Miquel Raynal
2023-12-05  6:51   ` Miquel Raynal
2023-12-05  7:39   ` Uwe Kleine-König
2023-12-05  7:39     ` Uwe Kleine-König
2023-12-05  7:39     ` Uwe Kleine-König
2023-12-05  7:50     ` Miquel Raynal
2023-12-05  7:50       ` Miquel Raynal
2023-12-05  7:50       ` Miquel Raynal
2023-12-06  4:00 ` patchwork-bot+netdevbpf
2023-12-06  4:00   ` patchwork-bot+netdevbpf
2023-12-06  4:00   ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c43193b9a002e88da36b111bb44ce2973ecde722.1701713943.git.u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=elder@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.