Push the locking around get_nfit_res() into get_nfit_res().
Showing the changes to tools/testing (1 of 1 file). Show all
Unified · Split
| @@ -16,6 +16,7 @@ · 15 unmodified lines | ||
| 16 | 16 | #include <linux/module.h> |
| 17 | 17 | #include <linux/types.h> |
| 18 | 18 | #include <linux/io.h> |
| 19 | +#include <linux/mm.h> | |
| 19 | 20 | #include "nfit_test.h" |
| 20 | 21 | |
| 21 | 22 | static LIST_HEAD(iomap_head); |
| @@ -41,7 +42,7 @@ void nfit_test_teardown(void) · 19 unmodified lines | ||
| 41 | 42 | } |
| 42 | 43 | EXPORT_SYMBOL(nfit_test_teardown); |
| 43 | 44 | |
| 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) | |
| 45 | 46 | { |
| 46 | 47 | struct iomap_ops *ops; |
| 47 | 48 | |
| @@ -51,14 +52,22 @@ static struct nfit_test_resource *get_nfit_res(resource_size_t resource) · 3 unmodified lines | ||
| 51 | 52 | return NULL; |
| 52 | 53 | } |
| 53 | 54 | |
| 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) | |
| 56 | 56 | { |
| 57 | − struct nfit_test_resource *nfit_res; | |
| 57 | + struct nfit_test_resource *res; | |
| 58 | 58 | |
| 59 | 59 | rcu_read_lock(); |
| 60 | − nfit_res = get_nfit_res(offset); | |
| 60 | + res = __get_nfit_res(resource); | |
| 61 | 61 | 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 | + | |
| 62 | 71 | if (nfit_res) |
| 63 | 72 | return (void __iomem *) nfit_res->buf + offset |
| 64 | 73 | - nfit_res->res->start; |
| @@ -68,11 +77,8 @@ void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size, · 3 unmodified lines | ||
| 68 | 77 | void __iomem *__wrap_devm_ioremap_nocache(struct device *dev, |
| 69 | 78 | resource_size_t offset, unsigned long size) |
| 70 | 79 | { |
| 71 | − struct nfit_test_resource *nfit_res; | |
| 80 | + struct nfit_test_resource *nfit_res = get_nfit_res(offset); | |
| 72 | 81 | |
| 73 | − rcu_read_lock(); | |
| 74 | − nfit_res = get_nfit_res(offset); | |
| 75 | − rcu_read_unlock(); | |
| 76 | 82 | if (nfit_res) |
| 77 | 83 | return (void __iomem *) nfit_res->buf + offset |
| 78 | 84 | - nfit_res->res->start; |
| @@ -83,11 +89,8 @@ EXPORT_SYMBOL(__wrap_devm_ioremap_nocache); · 4 unmodified lines | ||
| 83 | 89 | void *__wrap_devm_memremap(struct device *dev, resource_size_t offset, |
| 84 | 90 | size_t size, unsigned long flags) |
| 85 | 91 | { |
| 86 | − struct nfit_test_resource *nfit_res; | |
| 92 | + struct nfit_test_resource *nfit_res = get_nfit_res(offset); | |
| 87 | 93 | |
| 88 | − rcu_read_lock(); | |
| 89 | − nfit_res = get_nfit_res(offset); | |
| 90 | − rcu_read_unlock(); | |
| 91 | 94 | if (nfit_res) |
| 92 | 95 | return nfit_res->buf + offset - nfit_res->res->start; |
| 93 | 96 | 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 | ||
| 102 | 105 | struct percpu_ref *ref, struct vmem_altmap *altmap) |
| 103 | 106 | { |
| 104 | 107 | resource_size_t offset = res->start; |
| 105 | − struct nfit_test_resource *nfit_res; | |
| 108 | + struct nfit_test_resource *nfit_res = get_nfit_res(offset); | |
| 106 | 109 | |
| 107 | − rcu_read_lock(); | |
| 108 | − nfit_res = get_nfit_res(offset); | |
| 109 | − rcu_read_unlock(); | |
| 110 | 110 | if (nfit_res) |
| 111 | 111 | return nfit_res->buf + offset - nfit_res->res->start; |
| 112 | 112 | return devm_memremap_pages(dev, res, ref, altmap); |
| @@ -115,11 +115,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages); · 2 unmodified lines | ||
| 115 | 115 | |
| 116 | 116 | pfn_t __wrap_phys_to_pfn_t(dma_addr_t addr, unsigned long flags) |
| 117 | 117 | { |
| 118 | − struct nfit_test_resource *nfit_res; | |
| 118 | + struct nfit_test_resource *nfit_res = get_nfit_res(addr); | |
| 119 | 119 | |
| 120 | − rcu_read_lock(); | |
| 121 | − nfit_res = get_nfit_res(addr); | |
| 122 | − rcu_read_unlock(); | |
| 123 | 120 | if (nfit_res) |
| 124 | 121 | flags &= ~PFN_MAP; |
| 125 | 122 | return phys_to_pfn_t(addr, flags); |
| @@ -130,11 +127,8 @@ EXPORT_SYMBOL(__wrap_phys_to_pfn_t); · 4 unmodified lines | ||
| 130 | 127 | void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res) |
| 131 | 128 | { |
| 132 | 129 | resource_size_t offset = res->start; |
| 133 | − struct nfit_test_resource *nfit_res; | |
| 130 | + struct nfit_test_resource *nfit_res = get_nfit_res(offset); | |
| 134 | 131 | |
| 135 | − rcu_read_lock(); | |
| 136 | − nfit_res = get_nfit_res(offset); | |
| 137 | − rcu_read_unlock(); | |
| 138 | 132 | if (nfit_res) |
| 139 | 133 | return nfit_res->buf + offset - nfit_res->res->start; |
| 140 | 134 | return devm_memremap_pages(dev, res); |
| @@ -145,11 +139,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages); · 4 unmodified lines | ||
| 145 | 139 | void *__wrap_memremap(resource_size_t offset, size_t size, |
| 146 | 140 | unsigned long flags) |
| 147 | 141 | { |
| 148 | − struct nfit_test_resource *nfit_res; | |
| 142 | + struct nfit_test_resource *nfit_res = get_nfit_res(offset); | |
| 149 | 143 | |
| 150 | − rcu_read_lock(); | |
| 151 | − nfit_res = get_nfit_res(offset); | |
| 152 | − rcu_read_unlock(); | |
| 153 | 144 | if (nfit_res) |
| 154 | 145 | return nfit_res->buf + offset - nfit_res->res->start; |
| 155 | 146 | return memremap(offset, size, flags); |
| @@ -158,11 +149,8 @@ EXPORT_SYMBOL(__wrap_memremap); · 2 unmodified lines | ||
| 158 | 149 | |
| 159 | 150 | void __wrap_devm_memunmap(struct device *dev, void *addr) |
| 160 | 151 | { |
| 161 | − struct nfit_test_resource *nfit_res; | |
| 152 | + struct nfit_test_resource *nfit_res = get_nfit_res((long) addr); | |
| 162 | 153 | |
| 163 | − rcu_read_lock(); | |
| 164 | − nfit_res = get_nfit_res((unsigned long) addr); | |
| 165 | − rcu_read_unlock(); | |
| 166 | 154 | if (nfit_res) |
| 167 | 155 | return; |
| 168 | 156 | return devm_memunmap(dev, addr); |
| @@ -183,11 +171,7 @@ EXPORT_SYMBOL(__wrap_ioremap_wc); · 14 unmodified lines | ||
| 183 | 171 | |
| 184 | 172 | void __wrap_iounmap(volatile void __iomem *addr) |
| 185 | 173 | { |
| 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); | |
| 191 | 175 | if (nfit_res) |
| 192 | 176 | return; |
| 193 | 177 | return iounmap(addr); |
| @@ -196,11 +180,8 @@ EXPORT_SYMBOL(__wrap_iounmap); · 2 unmodified lines | ||
| 196 | 180 | |
| 197 | 181 | void __wrap_memunmap(void *addr) |
| 198 | 182 | { |
| 199 | − struct nfit_test_resource *nfit_res; | |
| 183 | + struct nfit_test_resource *nfit_res = get_nfit_res((long) addr); | |
| 200 | 184 | |
| 201 | − rcu_read_lock(); | |
| 202 | − nfit_res = get_nfit_res((unsigned long) addr); | |
| 203 | − rcu_read_unlock(); | |
| 204 | 185 | if (nfit_res) |
| 205 | 186 | return; |
| 206 | 187 | return memunmap(addr); |
| @@ -214,9 +195,7 @@ static struct resource *nfit_test_request_region(struct device *dev, · 7 unmodified lines | ||
| 214 | 195 | struct nfit_test_resource *nfit_res; |
| 215 | 196 | |
| 216 | 197 | if (parent == &iomem_resource) { |
| 217 | − rcu_read_lock(); | |
| 218 | 198 | nfit_res = get_nfit_res(start); |
| 219 | − rcu_read_unlock(); | |
| 220 | 199 | if (nfit_res) { |
| 221 | 200 | struct resource *res = nfit_res->res + 1; |
| 222 | 201 | |
| @@ -266,9 +245,7 @@ void __wrap___release_region(struct resource *parent, resource_size_t start, · 43 unmodified lines | ||
| 266 | 245 | struct nfit_test_resource *nfit_res; |
| 267 | 246 | |
| 268 | 247 | if (parent == &iomem_resource) { |
| 269 | − rcu_read_lock(); | |
| 270 | 248 | nfit_res = get_nfit_res(start); |
| 271 | − rcu_read_unlock(); | |
| 272 | 249 | if (nfit_res) { |
| 273 | 250 | struct resource *res = nfit_res->res + 1; |
| 274 | 251 | |