1 From f7792176d939e79b4f525114a95d0fd8266bef8e Mon Sep 17 00:00:00 2001
2 From: Madalin Bucur <madalin.bucur@freescale.com>
3 Date: Wed, 19 Nov 2014 13:06:54 +0200
4 Subject: [PATCH 18/70] devres: add devm_alloc_percpu()
6 Introduce managed counterparts for alloc_percpu() and free_percpu().
7 Add devm_alloc_percpu() and devm_free_percpu() into the managed
10 Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
12 Change-Id: I93546348e7b0e1974fda8b6c7a3b3710ce45b724
13 Reviewed-on: http://git.am.freescale.net:8181/24140
14 Reviewed-by: Madalin-Cristian Bucur <madalin.bucur@freescale.com>
15 Tested-by: Madalin-Cristian Bucur <madalin.bucur@freescale.com>
18 Documentation/driver-model/devres.txt
24 Documentation/driver-model/devres.txt | 4 +++
25 drivers/base/devres.c | 63 +++++++++++++++++++++++++++++++++
26 include/linux/device.h | 19 ++++++++++
27 3 files changed, 86 insertions(+)
29 --- a/Documentation/driver-model/devres.txt
30 +++ b/Documentation/driver-model/devres.txt
31 @@ -321,6 +321,10 @@ PHY
42 --- a/drivers/base/devres.c
43 +++ b/drivers/base/devres.c
44 @@ -985,3 +985,66 @@ void devm_free_pages(struct device *dev,
47 EXPORT_SYMBOL_GPL(devm_free_pages);
49 +static void devm_percpu_release(struct device *dev, void *pdata)
53 + p = *(void __percpu **)pdata;
57 +static int devm_percpu_match(struct device *dev, void *data, void *p)
59 + struct devres *devr = container_of(data, struct devres, data);
61 + return *(void **)devr->data == p;
65 + * __devm_alloc_percpu - Resource-managed alloc_percpu
66 + * @dev: Device to allocate per-cpu memory for
67 + * @size: Size of per-cpu memory to allocate
68 + * @align: Alignement of per-cpu memory to allocate
70 + * Managed alloc_percpu. Per-cpu memory allocated with this function is
71 + * automatically freed on driver detach.
74 + * Pointer to allocated memory on success, NULL on failure.
76 +void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
80 + void __percpu *pcpu;
82 + pcpu = __alloc_percpu(size, align);
86 + p = devres_alloc(devm_percpu_release, sizeof(void *), GFP_KERNEL);
90 + *(void __percpu **)p = pcpu;
96 +EXPORT_SYMBOL_GPL(__devm_alloc_percpu);
99 + * devm_free_percpu - Resource-managed free_percpu
100 + * @dev: Device this memory belongs to
101 + * @pdata: Per-cpu memory to free
103 + * Free memory allocated with devm_alloc_percpu().
105 +void devm_free_percpu(struct device *dev, void __percpu *pdata)
107 + WARN_ON(devres_destroy(dev, devm_percpu_release, devm_percpu_match,
110 +EXPORT_SYMBOL_GPL(devm_free_percpu);
111 --- a/include/linux/device.h
112 +++ b/include/linux/device.h
113 @@ -683,6 +683,25 @@ void __iomem *devm_ioremap_resource(stru
114 int devm_add_action(struct device *dev, void (*action)(void *), void *data);
115 void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
118 + * devm_alloc_percpu - Resource-managed alloc_percpu
119 + * @dev: Device to allocate per-cpu memory for
120 + * @type: Type to allocate per-cpu memory for
122 + * Managed alloc_percpu. Per-cpu memory allocated with this function is
123 + * automatically freed on driver detach.
126 + * Pointer to allocated memory on success, NULL on failure.
128 +#define devm_alloc_percpu(dev, type) \
129 + (typeof(type) __percpu *)__devm_alloc_percpu(dev, sizeof(type), \
132 +void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
134 +void devm_free_percpu(struct device *dev, void __percpu *pdata);
136 struct device_dma_parameters {
138 * a low level driver may set these to teach IOMMU code about