diff mbox series

[v2,10/17] firmware: turris-mox-rwtm: Convert rest to devm_* and get rid of driver .remove()

Message ID 20240613161045.29606-11-kabel@kernel.org (mailing list archive)
State Superseded
Headers show
Series Updates for turris-mox-rwtm driver | expand

Commit Message

Marek Behún June 13, 2024, 4:10 p.m. UTC
Use devm resource management for driver's mailbox. This allows us to get
rid of driver's .remove() method and gotos in .probe().

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/firmware/turris-mox-rwtm.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

Comments

Andy Shevchenko June 13, 2024, 8:39 p.m. UTC | #1
On Thu, Jun 13, 2024 at 6:11 PM Marek Behún <kabel@kernel.org> wrote:
>
> Use devm resource management for driver's mailbox. This allows us to get
> rid of driver's .remove() method and gotos in .probe().

of the driver's

...

> +       ret = devm_add_action_or_reset(dev, rwtm_devm_mbox_release, rwtm->mbox);
> +       if (ret < 0)

Can it return positive codes? If not, why ' < 0'?

> +               return ret;
Marek Behún June 17, 2024, 11:13 a.m. UTC | #2
On Thu, 13 Jun 2024 22:39:33 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Thu, Jun 13, 2024 at 6:11 PM Marek Behún <kabel@kernel.org> wrote:
> >
> > Use devm resource management for driver's mailbox. This allows us to get
> > rid of driver's .remove() method and gotos in .probe().  
> 
> of the driver's
> 
> ...
> 
> > +       ret = devm_add_action_or_reset(dev, rwtm_devm_mbox_release, rwtm->mbox);
> > +       if (ret < 0)  
> 
> Can it return positive codes? If not, why ' < 0'?
>

Right...
diff mbox series

Patch

diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
index a536c9c461a7..3017a8c19005 100644
--- a/drivers/firmware/turris-mox-rwtm.c
+++ b/drivers/firmware/turris-mox-rwtm.c
@@ -425,6 +425,11 @@  static inline void rwtm_register_debugfs(struct mox_rwtm *rwtm)
 }
 #endif
 
+static void rwtm_devm_mbox_release(void *mbox)
+{
+	mbox_free_channel(mbox);
+}
+
 static void rwtm_firmware_symlink_drop(void *)
 {
 	sysfs_remove_link(firmware_kobj, DRIVER_NAME);
@@ -462,6 +467,10 @@  static int turris_mox_rwtm_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(dev, rwtm_devm_mbox_release, rwtm->mbox);
+	if (ret < 0)
+		return ret;
+
 	init_completion(&rwtm->cmd_done);
 
 	ret = mox_get_board_info(rwtm);
@@ -472,7 +481,7 @@  static int turris_mox_rwtm_probe(struct platform_device *pdev)
 	if (ret < 0) {
 		dev_notice(dev,
 			   "Firmware does not support the GET_RANDOM command\n");
-		goto free_channel;
+		return ret;
 	}
 
 	rwtm->hwrng.name = DRIVER_NAME "_hwrng";
@@ -482,7 +491,7 @@  static int turris_mox_rwtm_probe(struct platform_device *pdev)
 	ret = devm_hwrng_register(dev, &rwtm->hwrng);
 	if (ret < 0) {
 		dev_err(dev, "Cannot register HWRNG: %i\n", ret);
-		goto free_channel;
+		return ret;
 	}
 
 	rwtm_register_debugfs(rwtm);
@@ -498,17 +507,6 @@  static int turris_mox_rwtm_probe(struct platform_device *pdev)
 		devm_add_action_or_reset(dev, rwtm_firmware_symlink_drop, NULL);
 
 	return 0;
-
-free_channel:
-	mbox_free_channel(rwtm->mbox);
-	return ret;
-}
-
-static void turris_mox_rwtm_remove(struct platform_device *pdev)
-{
-	struct mox_rwtm *rwtm = platform_get_drvdata(pdev);
-
-	mbox_free_channel(rwtm->mbox);
 }
 
 static const struct of_device_id turris_mox_rwtm_match[] = {
@@ -521,7 +519,6 @@  MODULE_DEVICE_TABLE(of, turris_mox_rwtm_match);
 
 static struct platform_driver turris_mox_rwtm_driver = {
 	.probe	= turris_mox_rwtm_probe,
-	.remove_new = turris_mox_rwtm_remove,
 	.driver	= {
 		.name		= DRIVER_NAME,
 		.of_match_table	= turris_mox_rwtm_match,