History

tools/testing/libnvdimm: cleanup mock resource lookup

Push the locking around get_nfit_res() into get_nfit_res().

Dan Williams committed 10 years ago

Commit 9bfa8491 parent 3fa96261 file · +23 −46Browse files

Showing the changes to tools/testing (1 of 1 file). Show all

Unified · Split

tools/testing/nvdimm/test/iomap.c+23−46
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 #include <linux/module.h>
1717 #include <linux/types.h>
1818 #include <linux/io.h>
19+#include <linux/mm.h>
1920 #include "nfit_test.h"
2021
2122 static LIST_HEAD(iomap_head);
@@ -41,7 +42,7 @@ void nfit_test_teardown(void) · 19 unmodified lines
4142 }
4243 EXPORT_SYMBOL(nfit_test_teardown);
4344
44−static struct nfit_test_resource *get_nfit_res(resource_size_t resource)
45+static struct nfit_test_resource *__get_nfit_res(resource_size_t resource)
4546 {
4647 struct iomap_ops *ops;
4748
@@ -51,14 +52,22 @@ static struct nfit_test_resource *get_nfit_res(resource_size_t resource) · 3 unmodified lines
5152 return NULL;
5253 }
5354
54−void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
55− void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
55+static struct nfit_test_resource *get_nfit_res(resource_size_t resource)
5656 {
57− struct nfit_test_resource *nfit_res;
57+ struct nfit_test_resource *res;
5858
5959 rcu_read_lock();
60− nfit_res = get_nfit_res(offset);
60+ res = __get_nfit_res(resource);
6161 rcu_read_unlock();
62+
63+ return res;
64+}
65+
66+void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
67+ void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
68+{
69+ struct nfit_test_resource *nfit_res = get_nfit_res(offset);
70+
6271 if (nfit_res)
6372 return (void __iomem *) nfit_res->buf + offset
6473 - nfit_res->res->start;
@@ -68,11 +77,8 @@ void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size, · 3 unmodified lines
6877 void __iomem *__wrap_devm_ioremap_nocache(struct device *dev,
6978 resource_size_t offset, unsigned long size)
7079 {
71− struct nfit_test_resource *nfit_res;
80+ struct nfit_test_resource *nfit_res = get_nfit_res(offset);
7281
73− rcu_read_lock();
74− nfit_res = get_nfit_res(offset);
75− rcu_read_unlock();
7682 if (nfit_res)
7783 return (void __iomem *) nfit_res->buf + offset
7884 - nfit_res->res->start;
@@ -83,11 +89,8 @@ EXPORT_SYMBOL(__wrap_devm_ioremap_nocache); · 4 unmodified lines
8389 void *__wrap_devm_memremap(struct device *dev, resource_size_t offset,
8490 size_t size, unsigned long flags)
8591 {
86− struct nfit_test_resource *nfit_res;
92+ struct nfit_test_resource *nfit_res = get_nfit_res(offset);
8793
88− rcu_read_lock();
89− nfit_res = get_nfit_res(offset);
90− rcu_read_unlock();
9194 if (nfit_res)
9295 return nfit_res->buf + offset - nfit_res->res->start;
9396 return devm_memremap(dev, offset, size, flags);
@@ -102,11 +105,8 @@ void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res, · 8 unmodified lines
102105 struct percpu_ref *ref, struct vmem_altmap *altmap)
103106 {
104107 resource_size_t offset = res->start;
105− struct nfit_test_resource *nfit_res;
108+ struct nfit_test_resource *nfit_res = get_nfit_res(offset);
106109
107− rcu_read_lock();
108− nfit_res = get_nfit_res(offset);
109− rcu_read_unlock();
110110 if (nfit_res)
111111 return nfit_res->buf + offset - nfit_res->res->start;
112112 return devm_memremap_pages(dev, res, ref, altmap);
@@ -115,11 +115,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages); · 2 unmodified lines
115115
116116 pfn_t __wrap_phys_to_pfn_t(dma_addr_t addr, unsigned long flags)
117117 {
118− struct nfit_test_resource *nfit_res;
118+ struct nfit_test_resource *nfit_res = get_nfit_res(addr);
119119
120− rcu_read_lock();
121− nfit_res = get_nfit_res(addr);
122− rcu_read_unlock();
123120 if (nfit_res)
124121 flags &= ~PFN_MAP;
125122 return phys_to_pfn_t(addr, flags);
@@ -130,11 +127,8 @@ EXPORT_SYMBOL(__wrap_phys_to_pfn_t); · 4 unmodified lines
130127 void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res)
131128 {
132129 resource_size_t offset = res->start;
133− struct nfit_test_resource *nfit_res;
130+ struct nfit_test_resource *nfit_res = get_nfit_res(offset);
134131
135− rcu_read_lock();
136− nfit_res = get_nfit_res(offset);
137− rcu_read_unlock();
138132 if (nfit_res)
139133 return nfit_res->buf + offset - nfit_res->res->start;
140134 return devm_memremap_pages(dev, res);
@@ -145,11 +139,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages); · 4 unmodified lines
145139 void *__wrap_memremap(resource_size_t offset, size_t size,
146140 unsigned long flags)
147141 {
148− struct nfit_test_resource *nfit_res;
142+ struct nfit_test_resource *nfit_res = get_nfit_res(offset);
149143
150− rcu_read_lock();
151− nfit_res = get_nfit_res(offset);
152− rcu_read_unlock();
153144 if (nfit_res)
154145 return nfit_res->buf + offset - nfit_res->res->start;
155146 return memremap(offset, size, flags);
@@ -158,11 +149,8 @@ EXPORT_SYMBOL(__wrap_memremap); · 2 unmodified lines
158149
159150 void __wrap_devm_memunmap(struct device *dev, void *addr)
160151 {
161− struct nfit_test_resource *nfit_res;
152+ struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
162153
163− rcu_read_lock();
164− nfit_res = get_nfit_res((unsigned long) addr);
165− rcu_read_unlock();
166154 if (nfit_res)
167155 return;
168156 return devm_memunmap(dev, addr);
@@ -183,11 +171,7 @@ EXPORT_SYMBOL(__wrap_ioremap_wc); · 14 unmodified lines
183171
184172 void __wrap_iounmap(volatile void __iomem *addr)
185173 {
186− struct nfit_test_resource *nfit_res;
187−
188− rcu_read_lock();
189− nfit_res = get_nfit_res((unsigned long) addr);
190− rcu_read_unlock();
174+ struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
191175 if (nfit_res)
192176 return;
193177 return iounmap(addr);
@@ -196,11 +180,8 @@ EXPORT_SYMBOL(__wrap_iounmap); · 2 unmodified lines
196180
197181 void __wrap_memunmap(void *addr)
198182 {
199− struct nfit_test_resource *nfit_res;
183+ struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
200184
201− rcu_read_lock();
202− nfit_res = get_nfit_res((unsigned long) addr);
203− rcu_read_unlock();
204185 if (nfit_res)
205186 return;
206187 return memunmap(addr);
@@ -214,9 +195,7 @@ static struct resource *nfit_test_request_region(struct device *dev, · 7 unmodified lines
214195 struct nfit_test_resource *nfit_res;
215196
216197 if (parent == &iomem_resource) {
217− rcu_read_lock();
218198 nfit_res = get_nfit_res(start);
219− rcu_read_unlock();
220199 if (nfit_res) {
221200 struct resource *res = nfit_res->res + 1;
222201
@@ -266,9 +245,7 @@ void __wrap___release_region(struct resource *parent, resource_size_t start, · 43 unmodified lines
266245 struct nfit_test_resource *nfit_res;
267246
268247 if (parent == &iomem_resource) {
269− rcu_read_lock();
270248 nfit_res = get_nfit_res(start);
271− rcu_read_unlock();
272249 if (nfit_res) {
273250 struct resource *res = nfit_res->res + 1;
274251

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t