All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: supply: da9150-fg: Use devm_delayed_work_autocancel()
@ 2022-02-13 17:55 Christophe JAILLET
  2022-02-18 13:13 ` Adam Thomson
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2022-02-13 17:55 UTC (permalink / raw)
  To: Support Opensource, Sebastian Reichel
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-pm

This driver only uses managed resources, except for the delayed work, if
it is used.

Use devm_delayed_work_autocancel() to also manage the delayed work.
The error handling path of the probe and the remove function can both be
removed.

This saves a few lines of code.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/power/supply/da9150-fg.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/power/supply/da9150-fg.c b/drivers/power/supply/da9150-fg.c
index 6e367826aae9..e63fa62d1943 100644
--- a/drivers/power/supply/da9150-fg.c
+++ b/drivers/power/supply/da9150-fg.c
@@ -20,6 +20,7 @@
 #include <asm/div64.h>
 #include <linux/mfd/da9150/core.h>
 #include <linux/mfd/da9150/registers.h>
+#include <linux/devm-helpers.h>
 
 /* Core2Wire */
 #define DA9150_QIF_READ		(0x0 << 7)
@@ -506,7 +507,13 @@ static int da9150_fg_probe(struct platform_device *pdev)
 	 * work for reporting data updates.
 	 */
 	if (fg->interval) {
-		INIT_DELAYED_WORK(&fg->work, da9150_fg_work);
+		ret = devm_delayed_work_autocancel(dev, &fg->work,
+						   da9150_fg_work);
+		if (ret) {
+			dev_err(dev, "Failed to init work\n");
+			return ret;
+		}
+
 		schedule_delayed_work(&fg->work,
 				      msecs_to_jiffies(fg->interval));
 	}
@@ -515,34 +522,17 @@ static int da9150_fg_probe(struct platform_device *pdev)
 	irq = platform_get_irq_byname(pdev, "FG");
 	if (irq < 0) {
 		dev_err(dev, "Failed to get IRQ FG: %d\n", irq);
-		ret = irq;
-		goto irq_fail;
+		return irq;
 	}
 
 	ret = devm_request_threaded_irq(dev, irq, NULL, da9150_fg_irq,
 					IRQF_ONESHOT, "FG", fg);
 	if (ret) {
 		dev_err(dev, "Failed to request IRQ %d: %d\n", irq, ret);
-		goto irq_fail;
+		return ret;
 	}
 
 	return 0;
-
-irq_fail:
-	if (fg->interval)
-		cancel_delayed_work(&fg->work);
-
-	return ret;
-}
-
-static int da9150_fg_remove(struct platform_device *pdev)
-{
-	struct da9150_fg *fg = platform_get_drvdata(pdev);
-
-	if (fg->interval)
-		cancel_delayed_work(&fg->work);
-
-	return 0;
 }
 
 static int da9150_fg_resume(struct platform_device *pdev)
@@ -564,7 +554,6 @@ static struct platform_driver da9150_fg_driver = {
 		.name = "da9150-fuel-gauge",
 	},
 	.probe = da9150_fg_probe,
-	.remove = da9150_fg_remove,
 	.resume = da9150_fg_resume,
 };
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] power: supply: da9150-fg: Use devm_delayed_work_autocancel()
  2022-02-13 17:55 [PATCH] power: supply: da9150-fg: Use devm_delayed_work_autocancel() Christophe JAILLET
@ 2022-02-18 13:13 ` Adam Thomson
  2022-02-24 11:21   ` Sebastian Reichel
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Thomson @ 2022-02-18 13:13 UTC (permalink / raw)
  To: Christophe JAILLET, Support Opensource, Sebastian Reichel
  Cc: linux-kernel, kernel-janitors, linux-pm

On 13 February 2022 17:55, Christophe JAILLET wrote:

> This driver only uses managed resources, except for the delayed work, if
> it is used.
> 
> Use devm_delayed_work_autocancel() to also manage the delayed work.
> The error handling path of the probe and the remove function can both be
> removed.
> 
> This saves a few lines of code.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] power: supply: da9150-fg: Use devm_delayed_work_autocancel()
  2022-02-18 13:13 ` Adam Thomson
@ 2022-02-24 11:21   ` Sebastian Reichel
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2022-02-24 11:21 UTC (permalink / raw)
  To: Adam Thomson
  Cc: Christophe JAILLET, Support Opensource, linux-kernel,
	kernel-janitors, linux-pm

[-- Attachment #1: Type: text/plain, Size: 622 bytes --]

Hi,

On Fri, Feb 18, 2022 at 01:13:10PM +0000, Adam Thomson wrote:
> On 13 February 2022 17:55, Christophe JAILLET wrote:
> 
> > This driver only uses managed resources, except for the delayed work, if
> > it is used.
> > 
> > Use devm_delayed_work_autocancel() to also manage the delayed work.
> > The error handling path of the probe and the remove function can both be
> > removed.
> > 
> > This saves a few lines of code.
> > 
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

Thanks, queued.

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-24 11:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-13 17:55 [PATCH] power: supply: da9150-fg: Use devm_delayed_work_autocancel() Christophe JAILLET
2022-02-18 13:13 ` Adam Thomson
2022-02-24 11:21   ` Sebastian Reichel

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.