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 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | #include <linux/types.h> | 17 | #include <linux/types.h> |
| 18 | #include <linux/io.h> | 18 | #include <linux/io.h> |
| 19 | #include <linux/mm.h> | ||
| 19 | #include "nfit_test.h" | 20 | #include "nfit_test.h" |
| 20 | 21 | ||
| 21 | static LIST_HEAD(iomap_head); | 22 | static LIST_HEAD(iomap_head); |
| @@ -41,7 +42,7 @@ void nfit_test_teardown(void) · 19 unmodified lines | |||
| 41 | } | 42 | } |
| 42 | EXPORT_SYMBOL(nfit_test_teardown); | 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 | struct iomap_ops *ops; | 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 | return NULL; | 52 | return NULL; |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size, | 55 | static struct nfit_test_resource *get_nfit_res(resource_size_t resource) |
| 55 | void __iomem *(*fallback_fn)(resource_size_t, unsigned long)) | ||
| 56 | { | 56 | { |
| 57 | struct nfit_test_resource *nfit_res; | 57 | struct nfit_test_resource *res; |
| 58 | 58 | ||
| 59 | rcu_read_lock(); | 59 | rcu_read_lock(); |
| 60 | nfit_res = get_nfit_res(offset); | 60 | res = __get_nfit_res(resource); |
| 61 | rcu_read_unlock(); | 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 | if (nfit_res) | 71 | if (nfit_res) |
| 63 | return (void __iomem *) nfit_res->buf + offset | 72 | return (void __iomem *) nfit_res->buf + offset |
| 64 | - nfit_res->res->start; | 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 | void __iomem *__wrap_devm_ioremap_nocache(struct device *dev, | 77 | void __iomem *__wrap_devm_ioremap_nocache(struct device *dev, |
| 69 | resource_size_t offset, unsigned long size) | 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 | if (nfit_res) | 82 | if (nfit_res) |
| 77 | return (void __iomem *) nfit_res->buf + offset | 83 | return (void __iomem *) nfit_res->buf + offset |
| 78 | - nfit_res->res->start; | 84 | - nfit_res->res->start; |
| @@ -83,11 +89,8 @@ EXPORT_SYMBOL(__wrap_devm_ioremap_nocache); · 4 unmodified lines | |||
| 83 | void *__wrap_devm_memremap(struct device *dev, resource_size_t offset, | 89 | void *__wrap_devm_memremap(struct device *dev, resource_size_t offset, |
| 84 | size_t size, unsigned long flags) | 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 | if (nfit_res) | 94 | if (nfit_res) |
| 92 | return nfit_res->buf + offset - nfit_res->res->start; | 95 | return nfit_res->buf + offset - nfit_res->res->start; |
| 93 | return devm_memremap(dev, offset, size, flags); | 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 | struct percpu_ref *ref, struct vmem_altmap *altmap) | 105 | struct percpu_ref *ref, struct vmem_altmap *altmap) |
| 103 | { | 106 | { |
| 104 | resource_size_t offset = res->start; | 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 | if (nfit_res) | 110 | if (nfit_res) |
| 111 | return nfit_res->buf + offset - nfit_res->res->start; | 111 | return nfit_res->buf + offset - nfit_res->res->start; |
| 112 | return devm_memremap_pages(dev, res, ref, altmap); | 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 | pfn_t __wrap_phys_to_pfn_t(dma_addr_t addr, unsigned long flags) | 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 | if (nfit_res) | 120 | if (nfit_res) |
| 124 | flags &= ~PFN_MAP; | 121 | flags &= ~PFN_MAP; |
| 125 | return phys_to_pfn_t(addr, flags); | 122 | return phys_to_pfn_t(addr, flags); |
| @@ -130,11 +127,8 @@ EXPORT_SYMBOL(__wrap_phys_to_pfn_t); · 4 unmodified lines | |||
| 130 | void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res) | 127 | void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res) |
| 131 | { | 128 | { |
| 132 | resource_size_t offset = res->start; | 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 | if (nfit_res) | 132 | if (nfit_res) |
| 139 | return nfit_res->buf + offset - nfit_res->res->start; | 133 | return nfit_res->buf + offset - nfit_res->res->start; |
| 140 | return devm_memremap_pages(dev, res); | 134 | return devm_memremap_pages(dev, res); |
| @@ -145,11 +139,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages); · 4 unmodified lines | |||
| 145 | void *__wrap_memremap(resource_size_t offset, size_t size, | 139 | void *__wrap_memremap(resource_size_t offset, size_t size, |
| 146 | unsigned long flags) | 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 | if (nfit_res) | 144 | if (nfit_res) |
| 154 | return nfit_res->buf + offset - nfit_res->res->start; | 145 | return nfit_res->buf + offset - nfit_res->res->start; |
| 155 | return memremap(offset, size, flags); | 146 | return memremap(offset, size, flags); |
| @@ -158,11 +149,8 @@ EXPORT_SYMBOL(__wrap_memremap); · 2 unmodified lines | |||
| 158 | 149 | ||
| 159 | void __wrap_devm_memunmap(struct device *dev, void *addr) | 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 | if (nfit_res) | 154 | if (nfit_res) |
| 167 | return; | 155 | return; |
| 168 | return devm_memunmap(dev, addr); | 156 | return devm_memunmap(dev, addr); |
| @@ -183,11 +171,7 @@ EXPORT_SYMBOL(__wrap_ioremap_wc); · 14 unmodified lines | |||
| 183 | 171 | ||
| 184 | void __wrap_iounmap(volatile void __iomem *addr) | 172 | void __wrap_iounmap(volatile void __iomem *addr) |
| 185 | { | 173 | { |
| 186 | struct nfit_test_resource *nfit_res; | 174 | struct nfit_test_resource *nfit_res = get_nfit_res((long) addr); |
| 187 | |||
| 188 | rcu_read_lock(); | ||
| 189 | nfit_res = get_nfit_res((unsigned long) addr); | ||
| 190 | rcu_read_unlock(); | ||
| 191 | if (nfit_res) | 175 | if (nfit_res) |
| 192 | return; | 176 | return; |
| 193 | return iounmap(addr); | 177 | return iounmap(addr); |
| @@ -196,11 +180,8 @@ EXPORT_SYMBOL(__wrap_iounmap); · 2 unmodified lines | |||
| 196 | 180 | ||
| 197 | void __wrap_memunmap(void *addr) | 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 | if (nfit_res) | 185 | if (nfit_res) |
| 205 | return; | 186 | return; |
| 206 | return memunmap(addr); | 187 | return memunmap(addr); |
| @@ -214,9 +195,7 @@ static struct resource *nfit_test_request_region(struct device *dev, · 7 unmodified lines | |||
| 214 | struct nfit_test_resource *nfit_res; | 195 | struct nfit_test_resource *nfit_res; |
| 215 | 196 | ||
| 216 | if (parent == &iomem_resource) { | 197 | if (parent == &iomem_resource) { |
| 217 | rcu_read_lock(); | ||
| 218 | nfit_res = get_nfit_res(start); | 198 | nfit_res = get_nfit_res(start); |
| 219 | rcu_read_unlock(); | ||
| 220 | if (nfit_res) { | 199 | if (nfit_res) { |
| 221 | struct resource *res = nfit_res->res + 1; | 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 | struct nfit_test_resource *nfit_res; | 245 | struct nfit_test_resource *nfit_res; |
| 267 | 246 | ||
| 268 | if (parent == &iomem_resource) { | 247 | if (parent == &iomem_resource) { |
| 269 | rcu_read_lock(); | ||
| 270 | nfit_res = get_nfit_res(start); | 248 | nfit_res = get_nfit_res(start); |
| 271 | rcu_read_unlock(); | ||
| 272 | if (nfit_res) { | 249 | if (nfit_res) { |
| 273 | struct resource *res = nfit_res->res + 1; | 250 | struct resource *res = nfit_res->res + 1; |
| 274 | 251 | ||