public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue
@ 2026-03-05 21:45 Krzysztof Kozlowski
  2026-03-05 21:45 ` [PATCH v2 02/10] power: supply: cw2015: Free allocated workqueue Krzysztof Kozlowski
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2026-03-05 21:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jonathan Corbet, Shuah Khan, Tejun Heo, Lai Jiangshan,
	Tobias Schrammm, Sebastian Reichel, Andy Shevchenko,
	Dan Carpenter, Krzysztof Kozlowski, Lee Jones, Dzmitry Sankouski,
	Matthias Brugger, AngeloGioacchino Del Regno, Benson Leung,
	Tzung-Bi Shih
  Cc: Matti Vaittinen, driver-core, linux-doc, linux-kernel,
	Sebastian Reichel, linux-pm, linux-arm-kernel, linux-mediatek,
	chrome-platform, Krzysztof Kozlowski, stable

Merging / Dependency
====================
All further patches depend on the first one, thus this probably should
go via one tree, e.g. power supply.  The first patch might be needed for
other trees as well, e.g. if more drivers are discovered, so the best if
it is on dedicated branch in case it has to be shared.

Changes in v2:
==============
- See individual patches
- Link to v1: https://patch.msgid.link/20260223-workqueue-devm-v1-0-10b3a6087586@oss.qualcomm.com

Description
===========
Add a Resource-managed version of alloc_workqueue() to fix common
problem of drivers mixing devm() calls with destroy_workqueue.  Such
naive and discouraged driver approach leads to difficult to debug bugs
when the driver:

1. Allocates workqueue in standard way and destroys it in driver
remove() callback,
2. Sets work struct with devm_work_autocancel(),
3. Registers interrupt handler with devm_request_threaded_irq().

Which leads to following unbind/removal path:

1. destroy_workqueue() via driver remove(),
Any interrupt coming now would still execute the interrupt handler,
which queues work on destroyed workqueue.
2. devm_irq_release(),
3. devm_work_drop() -> cancel_work_sync() on destroyed workqueue.

devm_alloc_workqueue() has two benefits:
1. Solves above problem of mix-and-match devres and non-devres code in
driver,
2. Simplify any sane drivers which were correctly using
alloc_workqueue() + devm_add_action_or_reset().

Best regards,
Krzysztof

---
Krzysztof Kozlowski (10):
      workqueue: devres: Add device-managed allocate workqueue
      power: supply: cw2015: Free allocated workqueue
      power: supply: max77705: Drop duplicated IRQ error message
      power: supply: max77705: Free allocated workqueue and fix removal order
      power: supply: mt6370: Simplify with devm_alloc_ordered_workqueue()
      power: supply: ipaq_micro: Simplify with devm
      mfd: ezx-pcap: Drop memory allocation error message
      mfd: ezx-pcap: Return directly instead of empty gotos
      mfd: ezx-pcap: Avoid rescheduling after destroying workqueue
      platform/chrome: cros_usbpd_logger: Simplify with devm

 Documentation/driver-api/driver-model/devres.rst |  4 ++
 drivers/mfd/ezx-pcap.c                           | 27 +++++--------
 drivers/platform/chrome/cros_usbpd_logger.c      | 18 ++++-----
 drivers/power/supply/cw2015_battery.c            |  3 +-
 drivers/power/supply/ipaq_micro_battery.c        | 50 ++++++++----------------
 drivers/power/supply/max77705_charger.c          | 36 ++++++-----------
 drivers/power/supply/mt6370-charger.c            | 13 +-----
 include/linux/workqueue.h                        | 22 +++++++++++
 kernel/workqueue.c                               | 28 +++++++++++++
 9 files changed, 100 insertions(+), 101 deletions(-)
---
base-commit: 9739e59909e70058fab7a131d7bee60d447ab732
change-id: 20260220-workqueue-devm-d9591e5e70eb

Best regards,
-- 
Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>


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

* [PATCH v2 02/10] power: supply: cw2015: Free allocated workqueue
  2026-03-05 21:45 [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Krzysztof Kozlowski
@ 2026-03-05 21:45 ` Krzysztof Kozlowski
  2026-03-06 14:28 ` [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Andy Shevchenko
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2026-03-05 21:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jonathan Corbet, Shuah Khan, Tejun Heo, Lai Jiangshan,
	Tobias Schrammm, Sebastian Reichel, Andy Shevchenko,
	Dan Carpenter, Krzysztof Kozlowski, Lee Jones, Dzmitry Sankouski,
	Matthias Brugger, AngeloGioacchino Del Regno, Benson Leung,
	Tzung-Bi Shih
  Cc: Matti Vaittinen, driver-core, linux-doc, linux-kernel,
	Sebastian Reichel, linux-pm, linux-arm-kernel, linux-mediatek,
	chrome-platform, stable, Krzysztof Kozlowski

Use devm interface so allocated workqueue will be freed during device
removal and error paths, thus fixing a memory leak.

Change is not equivalent in the workqueue itself: use non-legacy API
which does not set (__WQ_LEGACY | WQ_MEM_RECLAIM).  The workqueue is
used to read updated data from the battery, thus there is no point to
run it for memory reclaim.

Cc: <stable@vger.kernel.org>
Fixes: b4c7715c10c1 ("power: supply: add CellWise cw2015 fuel gauge driver")
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>

---

Depends on devm_xxx() from earlier patches.

Changes in v2:
1. Use devm_alloc_ordered_workqueue(), mention this in commit msg
---
 drivers/power/supply/cw2015_battery.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/cw2015_battery.c b/drivers/power/supply/cw2015_battery.c
index a05dcc4a48f2..286524d2318c 100644
--- a/drivers/power/supply/cw2015_battery.c
+++ b/drivers/power/supply/cw2015_battery.c
@@ -694,7 +694,8 @@ static int cw_bat_probe(struct i2c_client *client)
 			 "No monitored battery, some properties will be missing\n");
 	}
 
-	cw_bat->battery_workqueue = create_singlethread_workqueue("rk_battery");
+	cw_bat->battery_workqueue = devm_alloc_ordered_workqueue(&client->dev,
+								 "rk_battery", 0);
 	if (!cw_bat->battery_workqueue)
 		return -ENOMEM;
 

-- 
2.51.0


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

* Re: [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue
  2026-03-05 21:45 [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Krzysztof Kozlowski
  2026-03-05 21:45 ` [PATCH v2 02/10] power: supply: cw2015: Free allocated workqueue Krzysztof Kozlowski
@ 2026-03-06 14:28 ` Andy Shevchenko
  2026-03-11  7:10 ` (subset) " Sebastian Reichel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-03-06 14:28 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jonathan Corbet, Shuah Khan, Tejun Heo, Lai Jiangshan,
	Tobias Schrammm, Sebastian Reichel, Dan Carpenter,
	Krzysztof Kozlowski, Lee Jones, Dzmitry Sankouski,
	Matthias Brugger, AngeloGioacchino Del Regno, Benson Leung,
	Tzung-Bi Shih, Matti Vaittinen, driver-core, linux-doc,
	linux-kernel, Sebastian Reichel, linux-pm, linux-arm-kernel,
	linux-mediatek, chrome-platform, stable

On Thu, Mar 05, 2026 at 10:45:39PM +0100, Krzysztof Kozlowski wrote:
> Merging / Dependency
> ====================
> All further patches depend on the first one, thus this probably should
> go via one tree, e.g. power supply.  The first patch might be needed for
> other trees as well, e.g. if more drivers are discovered, so the best if
> it is on dedicated branch in case it has to be shared.
> 
> Changes in v2:
> ==============
> - See individual patches
> - Link to v1: https://patch.msgid.link/20260223-workqueue-devm-v1-0-10b3a6087586@oss.qualcomm.com
> 
> Description
> ===========
> Add a Resource-managed version of alloc_workqueue() to fix common
> problem of drivers mixing devm() calls with destroy_workqueue.  Such
> naive and discouraged driver approach leads to difficult to debug bugs
> when the driver:
> 
> 1. Allocates workqueue in standard way and destroys it in driver
> remove() callback,
> 2. Sets work struct with devm_work_autocancel(),
> 3. Registers interrupt handler with devm_request_threaded_irq().
> 
> Which leads to following unbind/removal path:
> 
> 1. destroy_workqueue() via driver remove(),
> Any interrupt coming now would still execute the interrupt handler,
> which queues work on destroyed workqueue.
> 2. devm_irq_release(),
> 3. devm_work_drop() -> cancel_work_sync() on destroyed workqueue.
> 
> devm_alloc_workqueue() has two benefits:
> 1. Solves above problem of mix-and-match devres and non-devres code in
> driver,
> 2. Simplify any sane drivers which were correctly using
> alloc_workqueue() + devm_add_action_or_reset().

Thanks, this version LGTM, FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


-- 
With Best Regards,
Andy Shevchenko



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

* Re: (subset) [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue
  2026-03-05 21:45 [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Krzysztof Kozlowski
  2026-03-05 21:45 ` [PATCH v2 02/10] power: supply: cw2015: Free allocated workqueue Krzysztof Kozlowski
  2026-03-06 14:28 ` [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Andy Shevchenko
@ 2026-03-11  7:10 ` Sebastian Reichel
  2026-03-19 16:21 ` Lee Jones
  2026-03-20  3:06 ` Tzung-Bi Shih
  4 siblings, 0 replies; 6+ messages in thread
From: Sebastian Reichel @ 2026-03-11  7:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jonathan Corbet, Shuah Khan, Tejun Heo, Lai Jiangshan,
	Tobias Schrammm, Sebastian Reichel, Andy Shevchenko,
	Dan Carpenter, Krzysztof Kozlowski, Lee Jones, Dzmitry Sankouski,
	Matthias Brugger, AngeloGioacchino Del Regno, Benson Leung,
	Tzung-Bi Shih, Krzysztof Kozlowski
  Cc: Matti Vaittinen, driver-core, linux-doc, linux-kernel, linux-pm,
	linux-arm-kernel, linux-mediatek, chrome-platform, stable


On Thu, 05 Mar 2026 22:45:39 +0100, Krzysztof Kozlowski wrote:
> Merging / Dependency
> ====================
> All further patches depend on the first one, thus this probably should
> go via one tree, e.g. power supply.  The first patch might be needed for
> other trees as well, e.g. if more drivers are discovered, so the best if
> it is on dedicated branch in case it has to be shared.
> 
> [...]

Applied, thanks!

[02/10] power: supply: cw2015: Free allocated workqueue
        commit: db254b0b232358ab1aeadebe8d147c99a3569559
[03/10] power: supply: max77705: Drop duplicated IRQ error message
        commit: 2064c64ceb1996ee02a6bbb1de05fd6e8028e3e4
[04/10] power: supply: max77705: Free allocated workqueue and fix removal order
        commit: 1e668baadefb16e81269dbfebf3ffc2672e3a3bb
[05/10] power: supply: mt6370: Simplify with devm_alloc_ordered_workqueue()
        commit: f23afa01040a41882a048e4957a7acac1426da6f
[06/10] power: supply: ipaq_micro: Simplify with devm
        commit: 2cfc7cac68e19c4acb236b8db6065bbaff5deee8

Best regards,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>


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

* Re: (subset) [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue
  2026-03-05 21:45 [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2026-03-11  7:10 ` (subset) " Sebastian Reichel
@ 2026-03-19 16:21 ` Lee Jones
  2026-03-20  3:06 ` Tzung-Bi Shih
  4 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2026-03-19 16:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jonathan Corbet, Shuah Khan, Tejun Heo, Lai Jiangshan,
	Tobias Schrammm, Sebastian Reichel, Andy Shevchenko,
	Dan Carpenter, Krzysztof Kozlowski, Lee Jones, Dzmitry Sankouski,
	Matthias Brugger, AngeloGioacchino Del Regno, Benson Leung,
	Tzung-Bi Shih, Krzysztof Kozlowski
  Cc: Matti Vaittinen, driver-core, linux-doc, linux-kernel,
	Sebastian Reichel, linux-pm, linux-arm-kernel, linux-mediatek,
	chrome-platform, stable

On Thu, 05 Mar 2026 22:45:39 +0100, Krzysztof Kozlowski wrote:
> Merging / Dependency
> ====================
> All further patches depend on the first one, thus this probably should
> go via one tree, e.g. power supply.  The first patch might be needed for
> other trees as well, e.g. if more drivers are discovered, so the best if
> it is on dedicated branch in case it has to be shared.
> 
> [...]

Applied, thanks!

[07/10] mfd: ezx-pcap: Drop memory allocation error message
        commit: 33e0316783a205625b7c55a78041ddc0d5dce7c7
[08/10] mfd: ezx-pcap: Return directly instead of empty gotos
        commit: 444e11d9d9e56c994da8a253cdf7f33ac2eeb15b
[09/10] mfd: ezx-pcap: Avoid rescheduling after destroying workqueue
        commit: 356ee03f6ae7d04f90d8e2104660193c4f3a071c

--
Lee Jones [李琼斯]


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

* Re: (subset) [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue
  2026-03-05 21:45 [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2026-03-19 16:21 ` Lee Jones
@ 2026-03-20  3:06 ` Tzung-Bi Shih
  4 siblings, 0 replies; 6+ messages in thread
From: Tzung-Bi Shih @ 2026-03-20  3:06 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jonathan Corbet, Shuah Khan, Tejun Heo, Lai Jiangshan,
	Tobias Schrammm, Sebastian Reichel, Andy Shevchenko,
	Dan Carpenter, Krzysztof Kozlowski, Lee Jones, Dzmitry Sankouski,
	Matthias Brugger, AngeloGioacchino Del Regno, Benson Leung,
	Matti Vaittinen, driver-core, linux-doc, linux-kernel,
	Sebastian Reichel, linux-pm, linux-arm-kernel, linux-mediatek,
	chrome-platform, stable

On Thu, Mar 05, 2026 at 10:45:39PM +0100, Krzysztof Kozlowski wrote:
> Merging / Dependency
> ====================
> All further patches depend on the first one, thus this probably should
> go via one tree, e.g. power supply.  The first patch might be needed for
> other trees as well, e.g. if more drivers are discovered, so the best if
> it is on dedicated branch in case it has to be shared.
> 
> [...]

Applied to

    https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

[10/10] platform/chrome: cros_usbpd_logger: Simplify with devm
        commit: 168e4b208ca8c2e04de20cc6cb7e2fb035dc1ec8

Thanks!

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

end of thread, other threads:[~2026-03-20  3:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 21:45 [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Krzysztof Kozlowski
2026-03-05 21:45 ` [PATCH v2 02/10] power: supply: cw2015: Free allocated workqueue Krzysztof Kozlowski
2026-03-06 14:28 ` [PATCH v2 00/10] workqueue / drivers: Add device-managed allocate workqueue Andy Shevchenko
2026-03-11  7:10 ` (subset) " Sebastian Reichel
2026-03-19 16:21 ` Lee Jones
2026-03-20  3:06 ` Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox