[2/5] resource: add a not device managed request_free_mem_region variant
diff mbox series

Message ID 20190811081247.22111-3-hch@lst.de
State New
Headers show
Series
  • [1/5] resource: pass a name argument to devm_request_free_mem_region
Related show

Commit Message

Christoph Hellwig Aug. 11, 2019, 8:12 a.m. UTC
Just add a simple macro that passes a NULL dev argument to
dev_request_free_mem_region, and call request_mem_region in the
function for that particular case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/ioport.h | 2 ++
 kernel/resource.c      | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Jason Gunthorpe Aug. 11, 2019, 10:52 p.m. UTC | #1
On Sun, Aug 11, 2019 at 10:12:44AM +0200, Christoph Hellwig wrote:
> Just add a simple macro that passes a NULL dev argument to
> dev_request_free_mem_region, and call request_mem_region in the
> function for that particular case.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
>  include/linux/ioport.h | 2 ++
>  kernel/resource.c      | 5 ++++-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/ioport.h b/include/linux/ioport.h
> index 0dcc48cafa80..528ae6cbb1b4 100644
> +++ b/include/linux/ioport.h
> @@ -297,6 +297,8 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
>  
>  struct resource *devm_request_free_mem_region(struct device *dev,
>  		struct resource *base, unsigned long size, const char *name);
> +#define request_free_mem_region(base, size, name) \
> +	devm_request_free_mem_region(NULL, base, size, name)
>  
>  #endif /* __ASSEMBLY__ */
>  #endif	/* _LINUX_IOPORT_H */
> diff --git a/kernel/resource.c b/kernel/resource.c
> index 0ddc558586a7..3a826b3cc883 100644
> +++ b/kernel/resource.c
> @@ -1671,7 +1671,10 @@ struct resource *devm_request_free_mem_region(struct device *dev,
>  				REGION_DISJOINT)
>  			continue;
>  
> -		res = devm_request_mem_region(dev, addr, size, name);
> +		if (dev)
> +			res = devm_request_mem_region(dev, addr, size, name);
> +		else
> +			res = request_mem_region(addr, size, name);

It is a bit jarring to have something called devm_* that doesn't
actually do the devm_ part on some paths.

Maybe this function should be called __request_free_mem_region() with
another name wrapper macro?

Jason
Christoph Hellwig Aug. 12, 2019, 7:40 a.m. UTC | #2
On Sun, Aug 11, 2019 at 10:52:58PM +0000, Jason Gunthorpe wrote:
> It is a bit jarring to have something called devm_* that doesn't
> actually do the devm_ part on some paths.
> 
> Maybe this function should be called __request_free_mem_region() with
> another name wrapper macro?

Seems like a little more churn than required, but I could do it.

Patch
diff mbox series

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 0dcc48cafa80..528ae6cbb1b4 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -297,6 +297,8 @@  static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
 
 struct resource *devm_request_free_mem_region(struct device *dev,
 		struct resource *base, unsigned long size, const char *name);
+#define request_free_mem_region(base, size, name) \
+	devm_request_free_mem_region(NULL, base, size, name)
 
 #endif /* __ASSEMBLY__ */
 #endif	/* _LINUX_IOPORT_H */
diff --git a/kernel/resource.c b/kernel/resource.c
index 0ddc558586a7..3a826b3cc883 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -1671,7 +1671,10 @@  struct resource *devm_request_free_mem_region(struct device *dev,
 				REGION_DISJOINT)
 			continue;
 
-		res = devm_request_mem_region(dev, addr, size, name);
+		if (dev)
+			res = devm_request_mem_region(dev, addr, size, name);
+		else
+			res = request_mem_region(addr, size, name);
 		if (!res)
 			return ERR_PTR(-ENOMEM);
 		res->desc = IORES_DESC_DEVICE_PRIVATE_MEMORY;