linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: peci: Use devm_delayed_work_autocancel() to simplify code
@ 2022-02-13 19:48 Christophe JAILLET
  2022-02-14 14:29 ` Winiarska, Iwona
  2022-04-03 21:46 ` Guenter Roeck
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-02-13 19:48 UTC (permalink / raw)
  To: Iwona Winiarska, Jean Delvare, Guenter Roeck
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-hwmon

Use devm_delayed_work_autocancel() instead of hand writing it. This is
less verbose and saves a few lines of code.

devm_delayed_work_autocancel() uses devm_add_action() instead of
devm_add_action_or_reset(). This is fine, because if the underlying memory
allocation fails, no work has been scheduled yet. So there is nothing to
undo.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/hwmon/peci/dimmtemp.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/hwmon/peci/dimmtemp.c b/drivers/hwmon/peci/dimmtemp.c
index c8222354c005..96b9919db357 100644
--- a/drivers/hwmon/peci/dimmtemp.c
+++ b/drivers/hwmon/peci/dimmtemp.c
@@ -4,6 +4,7 @@
 #include <linux/auxiliary_bus.h>
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
+#include <linux/devm-helpers.h>
 #include <linux/hwmon.h>
 #include <linux/jiffies.h>
 #include <linux/module.h>
@@ -378,13 +379,6 @@ static void create_dimm_temp_info_delayed(struct work_struct *work)
 		dev_err(priv->dev, "Failed to populate DIMM temp info\n");
 }
 
-static void remove_delayed_work(void *_priv)
-{
-	struct peci_dimmtemp *priv = _priv;
-
-	cancel_delayed_work_sync(&priv->detect_work);
-}
-
 static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id)
 {
 	struct device *dev = &adev->dev;
@@ -415,9 +409,8 @@ static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct auxil
 			 "Unexpected PECI revision %#x, some features may be unavailable\n",
 			 peci_dev->info.peci_revision);
 
-	INIT_DELAYED_WORK(&priv->detect_work, create_dimm_temp_info_delayed);
-
-	ret = devm_add_action_or_reset(priv->dev, remove_delayed_work, priv);
+	ret = devm_delayed_work_autocancel(priv->dev, &priv->detect_work,
+					   create_dimm_temp_info_delayed);
 	if (ret)
 		return ret;
 
-- 
2.32.0


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

* Re: [PATCH] hwmon: peci: Use devm_delayed_work_autocancel() to simplify code
  2022-02-13 19:48 [PATCH] hwmon: peci: Use devm_delayed_work_autocancel() to simplify code Christophe JAILLET
@ 2022-02-14 14:29 ` Winiarska, Iwona
  2022-04-03 21:46 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Winiarska, Iwona @ 2022-02-14 14:29 UTC (permalink / raw)
  To: linux, christophe.jaillet, jdelvare
  Cc: linux-hwmon, kernel-janitors, linux-kernel

On Sun, 2022-02-13 at 20:48 +0100, Christophe JAILLET wrote:
> Use devm_delayed_work_autocancel() instead of hand writing it. This is
> less verbose and saves a few lines of code.
> 
> devm_delayed_work_autocancel() uses devm_add_action() instead of
> devm_add_action_or_reset(). This is fine, because if the underlying memory
> allocation fails, no work has been scheduled yet. So there is nothing to
> undo.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Iwona Winiarska <iwona.winiarska@intel.com>

Thanks
-Iwona

> ---
>  drivers/hwmon/peci/dimmtemp.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/hwmon/peci/dimmtemp.c b/drivers/hwmon/peci/dimmtemp.c
> index c8222354c005..96b9919db357 100644
> --- a/drivers/hwmon/peci/dimmtemp.c
> +++ b/drivers/hwmon/peci/dimmtemp.c
> @@ -4,6 +4,7 @@
>  #include <linux/auxiliary_bus.h>
>  #include <linux/bitfield.h>
>  #include <linux/bitops.h>
> +#include <linux/devm-helpers.h>
>  #include <linux/hwmon.h>
>  #include <linux/jiffies.h>
>  #include <linux/module.h>
> @@ -378,13 +379,6 @@ static void create_dimm_temp_info_delayed(struct
> work_struct *work)
>                 dev_err(priv->dev, "Failed to populate DIMM temp info\n");
>  }
>  
> -static void remove_delayed_work(void *_priv)
> -{
> -       struct peci_dimmtemp *priv = _priv;
> -
> -       cancel_delayed_work_sync(&priv->detect_work);
> -}
> -
>  static int peci_dimmtemp_probe(struct auxiliary_device *adev, const struct
> auxiliary_device_id *id)
>  {
>         struct device *dev = &adev->dev;
> @@ -415,9 +409,8 @@ static int peci_dimmtemp_probe(struct auxiliary_device
> *adev, const struct auxil
>                          "Unexpected PECI revision %#x, some features may be
> unavailable\n",
>                          peci_dev->info.peci_revision);
>  
> -       INIT_DELAYED_WORK(&priv->detect_work, create_dimm_temp_info_delayed);
> -
> -       ret = devm_add_action_or_reset(priv->dev, remove_delayed_work, priv);
> +       ret = devm_delayed_work_autocancel(priv->dev, &priv->detect_work,
> +                                          create_dimm_temp_info_delayed);
>         if (ret)
>                 return ret;
>  


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

* Re: [PATCH] hwmon: peci: Use devm_delayed_work_autocancel() to simplify code
  2022-02-13 19:48 [PATCH] hwmon: peci: Use devm_delayed_work_autocancel() to simplify code Christophe JAILLET
  2022-02-14 14:29 ` Winiarska, Iwona
@ 2022-04-03 21:46 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2022-04-03 21:46 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Iwona Winiarska, Jean Delvare, linux-kernel, kernel-janitors,
	linux-hwmon

On Sun, Feb 13, 2022 at 08:48:53PM +0100, Christophe JAILLET wrote:
> Use devm_delayed_work_autocancel() instead of hand writing it. This is
> less verbose and saves a few lines of code.
> 
> devm_delayed_work_autocancel() uses devm_add_action() instead of
> devm_add_action_or_reset(). This is fine, because if the underlying memory
> allocation fails, no work has been scheduled yet. So there is nothing to
> undo.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Reviewed-by: Iwona Winiarska <iwona.winiarska@intel.com>

Aplied to hwmon-next.

Thanks,
Guenter

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

end of thread, other threads:[~2022-04-03 21:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-13 19:48 [PATCH] hwmon: peci: Use devm_delayed_work_autocancel() to simplify code Christophe JAILLET
2022-02-14 14:29 ` Winiarska, Iwona
2022-04-03 21:46 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).