Skip to contentSkip to conversation

devres: clean up and move percpu allocator

PATCH In review Andy Shevchenko 3 participants 7 messages Nov 11, 2025 – Nov 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover devres: clean up and move percpu allocator

Clean up and move managed percpu allocator to devres.h.

Changelog v2:
- fixed build error by adding a missed inclusion

v1: <[email protected]>

Andy Shevchenko (2):
devres: Remove unused devm_free_percpu()
devres: Move devm_alloc_percpu() and related to devres.h

 .../driver-api/driver-model/devres.rst        |  1 -
 drivers/base/devres.c                         | 25 -------------------
 include/linux/device.h                        | 19 --------------
 include/linux/device/devres.h                 | 17 +++++++++++++
 4 files changed, 17 insertions(+), 45 deletions(-)
Signature · 1 line
2.50.1
#2 lore raw

PATCH v2 2/2 devres: Move devm_alloc_percpu() and related to devres.h

Move devm_alloc_percpu() and related to devres.h where it belongs,

---
 include/linux/device.h        | 18 ------------------
 include/linux/device/devres.h | 17 +++++++++++++++++
 2 files changed, 17 insertions(+), 18 deletions(-)
include/linux/device.h +0 -18
index 0c6377f6631c..0be95294b6e6 100644
@@ -281,24 +281,6 @@ int __must_check device_create_bin_file(struct device *dev,
 void device_remove_bin_file(struct device *dev,
 			    const struct bin_attribute *attr);
 
-/**
- * devm_alloc_percpu - Resource-managed alloc_percpu
- * @dev: Device to allocate per-cpu memory for
- * @type: Type to allocate per-cpu memory for
- *
- * Managed alloc_percpu. Per-cpu memory allocated with this function is
- * automatically freed on driver detach.
- *
- * RETURNS:
- * Pointer to allocated memory on success, NULL on failure.
- */
-#define devm_alloc_percpu(dev, type)      \
-	((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), \
-						      __alignof__(type)))
-
-void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
-				   size_t align);
-
 struct device_dma_parameters {
 	/*
 	 * a low level driver may set these to teach IOMMU code about
include/linux/device/devres.h +17 -0
index 8c5f57e0d613..9c1e3d643d69 100644
@@ -9,6 +9,7 @@
 #include <linux/stdarg.h>
 #include <linux/types.h>
 #include <asm/bug.h>
+#include <asm/percpu.h>
 
 struct device;
 struct device_node;
@@ -96,6 +97,22 @@ devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap);
 char * __printf(3, 4) __malloc
 devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...);
 
+/**
+ * devm_alloc_percpu - Resource-managed alloc_percpu
+ * @dev: Device to allocate per-cpu memory for
+ * @type: Type to allocate per-cpu memory for
+ *
+ * Managed alloc_percpu. Per-cpu memory allocated with this function is
+ * automatically freed on driver detach.
+ *
+ * RETURNS:
+ * Pointer to allocated memory on success, NULL on failure.
+ */
+#define devm_alloc_percpu(dev, type)      \
+	((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), __alignof__(type)))
+
+void __percpu *__devm_alloc_percpu(struct device *dev, size_t size, size_t align);
+
 unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order);
 void devm_free_pages(struct device *dev, unsigned long addr);
 
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/2 devres: Remove unused devm_free_percpu()

In reply to Andy Shevchenko

Remove unused devm_free_percpu().

By the way, it was never used in the drivers/ from day 1.

---
 .../driver-api/driver-model/devres.rst        |  1 -
 drivers/base/devres.c                         | 25 -------------------
 include/linux/device.h                        |  1 -
 3 files changed, 27 deletions(-)
Documentation/driver-api/driver-model/devres.rst +0 -1
index 2b36ebde9cec..0198ac65e874 100644
@@ -383,7 +383,6 @@ NET
 
 PER-CPU MEM
   devm_alloc_percpu()
-  devm_free_percpu()
 
 PCI
   devm_pci_alloc_host_bridge()  : managed PCI host bridge allocation
drivers/base/devres.c +0 -25
index c948c88d3956..f54db6d138ab 100644
@@ -1222,13 +1222,6 @@ static void devm_percpu_release(struct device *dev, void *pdata)
 	free_percpu(p);
 }
 
-static int devm_percpu_match(struct device *dev, void *data, void *p)
-{
-	struct devres *devr = container_of(data, struct devres, data);
-
-	return *(void **)devr->data == p;
-}
-
 /**
  * __devm_alloc_percpu - Resource-managed alloc_percpu
  * @dev: Device to allocate per-cpu memory for
@@ -1264,21 +1257,3 @@ void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
 	return pcpu;
 }
 EXPORT_SYMBOL_GPL(__devm_alloc_percpu);
-
-/**
- * devm_free_percpu - Resource-managed free_percpu
- * @dev: Device this memory belongs to
- * @pdata: Per-cpu memory to free
- *
- * Free memory allocated with devm_alloc_percpu().
- */
-void devm_free_percpu(struct device *dev, void __percpu *pdata)
-{
-	/*
-	 * Use devres_release() to prevent memory leakage as
-	 * devm_free_pages() does.
-	 */
-	WARN_ON(devres_release(dev, devm_percpu_release, devm_percpu_match,
-			       (void *)(__force unsigned long)pdata));
-}
-EXPORT_SYMBOL_GPL(devm_free_percpu);
include/linux/device.h +0 -1
index b031ff71a5bd..0c6377f6631c 100644
@@ -298,7 +298,6 @@ void device_remove_bin_file(struct device *dev,
 
 void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
 				   size_t align);
-void devm_free_percpu(struct device *dev, void __percpu *pdata);
 
 struct device_dma_parameters {
 	/*
Signature · 1 line
2.50.1
#3 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

Clean up and move managed percpu allocator to devres.h.

Changelog v2:
- fixed build error by adding a missed inclusion

OK, didn't see v2. Documentation/ still missing, though.

But we only send new versions after waiting for >24h, don't we? :]

Greetings,
Philipp

Quoted 13 lines

v1: <[email protected]>

Andy Shevchenko (2):
  devres: Remove unused devm_free_percpu()
  devres: Move devm_alloc_percpu() and related to devres.h

 .../driver-api/driver-model/devres.rst        |  1 - drivers/base/devres.c                         | 25 ------------------- include/linux/device.h                        | 19 -------------- include/linux/device/devres.h                 | 17 +++++++++++++

 4 files changed, 17 insertions(+), 45 deletions(-)
#4 lore raw
Quoted 7 lines · Philipp Stanner
Quoted 4 lines · Andy Shevchenko

Clean up and move managed percpu allocator to devres.h.

Changelog v2:
- fixed build error by adding a missed inclusion

OK, didn't see v2. Documentation/ still missing, though.

No, you are wrong.

Quoted 1 line

But we only send new versions after waiting for >24h, don't we? :]

No need for a new version.

Quoted 1 line
Quoted 1 line

 .../driver-api/driver-model/devres.rst        |  1 -

Again, please read this list carefully.

Quoted 4 lines
Quoted 4 lines

 drivers/base/devres.c                         | 25 ------------------- include/linux/device.h                        | 19 -------------- include/linux/device/devres.h                 | 17 +++++++++++++

 4 files changed, 17 insertions(+), 45 deletions(-)
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
In reply to Andy Shevchenko

On Wed Nov 12, 2025 at 3:49 AM NZDT, Andy Shevchenko wrote:

Applied to driver-core-testing, thanks!

Quoted 3 lines

Andy Shevchenko (2):
devres: Remove unused devm_free_percpu()
devres: Move devm_alloc_percpu() and related to devres.h

[ Fix minor typo in commit message. - Danilo ]

#6 lore raw
Quoted 9 lines · Danilo Krummrich

On Wed Nov 12, 2025 at 3:49 AM NZDT, Andy Shevchenko wrote:

Applied to driver-core-testing, thanks!

Quoted 3 lines

Andy Shevchenko (2):
devres: Remove unused devm_free_percpu()
devres: Move devm_alloc_percpu() and related to devres.h

[ Fix minor typo in commit message. - Danilo ]

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko