devres: clean up and move percpu allocator
Subsystems (2)
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
PATCH v2 1/2 devres: Remove unused devm_free_percpu()
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
@@ -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
@@ -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
@@ -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
PATCH v2 2/2 devres: Move devm_alloc_percpu() and related to devres.h
In reply to Andy ShevchenkoMove 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
@@ -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
@@ -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
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 unuseddevm_free_percpu()
devres: Movedevm_alloc_percpu()and related todevres.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(-)
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 inclusionOK, 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
Danilo Krummrich
maintainerOn 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 unuseddevm_free_percpu()
devres: Movedevm_alloc_percpu()and related todevres.h
[ Fix minor typo in commit message. - Danilo ]
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 unuseddevm_free_percpu()
devres: Movedevm_alloc_percpu()and related todevres.h[ Fix minor typo in commit message. - Danilo ]
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko