Commit 9bfa8496 authored by Dan Williams's avatar Dan Williams

tools/testing/libnvdimm: cleanup mock resource lookup

Push the locking around get_nfit_res() into get_nfit_res().
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 3fa96268
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/mm.h>
#include "nfit_test.h" #include "nfit_test.h"
static LIST_HEAD(iomap_head); static LIST_HEAD(iomap_head);
...@@ -41,7 +42,7 @@ void nfit_test_teardown(void) ...@@ -41,7 +42,7 @@ void nfit_test_teardown(void)
} }
EXPORT_SYMBOL(nfit_test_teardown); EXPORT_SYMBOL(nfit_test_teardown);
static struct nfit_test_resource *get_nfit_res(resource_size_t resource) static struct nfit_test_resource *__get_nfit_res(resource_size_t resource)
{ {
struct iomap_ops *ops; struct iomap_ops *ops;
...@@ -51,14 +52,22 @@ static struct nfit_test_resource *get_nfit_res(resource_size_t resource) ...@@ -51,14 +52,22 @@ static struct nfit_test_resource *get_nfit_res(resource_size_t resource)
return NULL; return NULL;
} }
void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size, static struct nfit_test_resource *get_nfit_res(resource_size_t resource)
void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *res;
rcu_read_lock(); rcu_read_lock();
nfit_res = get_nfit_res(offset); res = __get_nfit_res(resource);
rcu_read_unlock(); rcu_read_unlock();
return res;
}
void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
{
struct nfit_test_resource *nfit_res = get_nfit_res(offset);
if (nfit_res) if (nfit_res)
return (void __iomem *) nfit_res->buf + offset return (void __iomem *) nfit_res->buf + offset
- nfit_res->res->start; - nfit_res->res->start;
...@@ -68,11 +77,8 @@ void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size, ...@@ -68,11 +77,8 @@ void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
void __iomem *__wrap_devm_ioremap_nocache(struct device *dev, void __iomem *__wrap_devm_ioremap_nocache(struct device *dev,
resource_size_t offset, unsigned long size) resource_size_t offset, unsigned long size)
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res(offset);
rcu_read_lock();
nfit_res = get_nfit_res(offset);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return (void __iomem *) nfit_res->buf + offset return (void __iomem *) nfit_res->buf + offset
- nfit_res->res->start; - nfit_res->res->start;
...@@ -83,11 +89,8 @@ EXPORT_SYMBOL(__wrap_devm_ioremap_nocache); ...@@ -83,11 +89,8 @@ EXPORT_SYMBOL(__wrap_devm_ioremap_nocache);
void *__wrap_devm_memremap(struct device *dev, resource_size_t offset, void *__wrap_devm_memremap(struct device *dev, resource_size_t offset,
size_t size, unsigned long flags) size_t size, unsigned long flags)
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res(offset);
rcu_read_lock();
nfit_res = get_nfit_res(offset);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return nfit_res->buf + offset - nfit_res->res->start; return nfit_res->buf + offset - nfit_res->res->start;
return devm_memremap(dev, offset, size, flags); return devm_memremap(dev, offset, size, flags);
...@@ -102,11 +105,8 @@ void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res, ...@@ -102,11 +105,8 @@ void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res,
struct percpu_ref *ref, struct vmem_altmap *altmap) struct percpu_ref *ref, struct vmem_altmap *altmap)
{ {
resource_size_t offset = res->start; resource_size_t offset = res->start;
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res(offset);
rcu_read_lock();
nfit_res = get_nfit_res(offset);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return nfit_res->buf + offset - nfit_res->res->start; return nfit_res->buf + offset - nfit_res->res->start;
return devm_memremap_pages(dev, res, ref, altmap); return devm_memremap_pages(dev, res, ref, altmap);
...@@ -115,11 +115,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages); ...@@ -115,11 +115,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages);
pfn_t __wrap_phys_to_pfn_t(dma_addr_t addr, unsigned long flags) pfn_t __wrap_phys_to_pfn_t(dma_addr_t addr, unsigned long flags)
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res(addr);
rcu_read_lock();
nfit_res = get_nfit_res(addr);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
flags &= ~PFN_MAP; flags &= ~PFN_MAP;
return phys_to_pfn_t(addr, flags); return phys_to_pfn_t(addr, flags);
...@@ -130,11 +127,8 @@ EXPORT_SYMBOL(__wrap_phys_to_pfn_t); ...@@ -130,11 +127,8 @@ EXPORT_SYMBOL(__wrap_phys_to_pfn_t);
void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res) void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res)
{ {
resource_size_t offset = res->start; resource_size_t offset = res->start;
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res(offset);
rcu_read_lock();
nfit_res = get_nfit_res(offset);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return nfit_res->buf + offset - nfit_res->res->start; return nfit_res->buf + offset - nfit_res->res->start;
return devm_memremap_pages(dev, res); return devm_memremap_pages(dev, res);
...@@ -145,11 +139,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages); ...@@ -145,11 +139,8 @@ EXPORT_SYMBOL(__wrap_devm_memremap_pages);
void *__wrap_memremap(resource_size_t offset, size_t size, void *__wrap_memremap(resource_size_t offset, size_t size,
unsigned long flags) unsigned long flags)
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res(offset);
rcu_read_lock();
nfit_res = get_nfit_res(offset);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return nfit_res->buf + offset - nfit_res->res->start; return nfit_res->buf + offset - nfit_res->res->start;
return memremap(offset, size, flags); return memremap(offset, size, flags);
...@@ -158,11 +149,8 @@ EXPORT_SYMBOL(__wrap_memremap); ...@@ -158,11 +149,8 @@ EXPORT_SYMBOL(__wrap_memremap);
void __wrap_devm_memunmap(struct device *dev, void *addr) void __wrap_devm_memunmap(struct device *dev, void *addr)
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
rcu_read_lock();
nfit_res = get_nfit_res((unsigned long) addr);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return; return;
return devm_memunmap(dev, addr); return devm_memunmap(dev, addr);
...@@ -183,11 +171,7 @@ EXPORT_SYMBOL(__wrap_ioremap_wc); ...@@ -183,11 +171,7 @@ EXPORT_SYMBOL(__wrap_ioremap_wc);
void __wrap_iounmap(volatile void __iomem *addr) void __wrap_iounmap(volatile void __iomem *addr)
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
rcu_read_lock();
nfit_res = get_nfit_res((unsigned long) addr);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return; return;
return iounmap(addr); return iounmap(addr);
...@@ -196,11 +180,8 @@ EXPORT_SYMBOL(__wrap_iounmap); ...@@ -196,11 +180,8 @@ EXPORT_SYMBOL(__wrap_iounmap);
void __wrap_memunmap(void *addr) void __wrap_memunmap(void *addr)
{ {
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
rcu_read_lock();
nfit_res = get_nfit_res((unsigned long) addr);
rcu_read_unlock();
if (nfit_res) if (nfit_res)
return; return;
return memunmap(addr); return memunmap(addr);
...@@ -214,9 +195,7 @@ static struct resource *nfit_test_request_region(struct device *dev, ...@@ -214,9 +195,7 @@ static struct resource *nfit_test_request_region(struct device *dev,
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res;
if (parent == &iomem_resource) { if (parent == &iomem_resource) {
rcu_read_lock();
nfit_res = get_nfit_res(start); nfit_res = get_nfit_res(start);
rcu_read_unlock();
if (nfit_res) { if (nfit_res) {
struct resource *res = nfit_res->res + 1; struct resource *res = nfit_res->res + 1;
...@@ -266,9 +245,7 @@ void __wrap___release_region(struct resource *parent, resource_size_t start, ...@@ -266,9 +245,7 @@ void __wrap___release_region(struct resource *parent, resource_size_t start,
struct nfit_test_resource *nfit_res; struct nfit_test_resource *nfit_res;
if (parent == &iomem_resource) { if (parent == &iomem_resource) {
rcu_read_lock();
nfit_res = get_nfit_res(start); nfit_res = get_nfit_res(start);
rcu_read_unlock();
if (nfit_res) { if (nfit_res) {
struct resource *res = nfit_res->res + 1; struct resource *res = nfit_res->res + 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment