linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mtd: plat-ram: use release_mem_region instead of release_resource
@ 2017-08-16 16:22 Anton Vasilyev
  2017-08-17 13:29 ` Boris Brezillon
  0 siblings, 1 reply; 3+ messages in thread
From: Anton Vasilyev @ 2017-08-16 16:22 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Anton Vasilyev, David Woodhouse, Brian Norris, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, linux-mtd, linux-kernel,
	ldv-project

Replace ioremap() and request_mem_region() by devm_ioremap_resource().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
v1: Fix commit based on Boris Brezillon review
---
v2: Change commit by Boris Brezillon solution
---
 drivers/mtd/maps/plat-ram.c | 38 ++++----------------------------------
 1 file changed, 4 insertions(+), 34 deletions(-)

diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 5157289..6d9a4d6 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -43,7 +43,6 @@ struct platram_info {
 	struct device		*dev;
 	struct mtd_info		*mtd;
 	struct map_info		 map;
-	struct resource		*area;
 	struct platdata_mtd_ram	*pdata;
 };
 
@@ -97,16 +96,6 @@ static int platram_remove(struct platform_device *pdev)
 
 	platram_setrw(info, PLATRAM_RO);
 
-	/* release resources */
-
-	if (info->area) {
-		release_resource(info->area);
-		kfree(info->area);
-	}
-
-	if (info->map.virt != NULL)
-		iounmap(info->map.virt);
-
 	kfree(info);
 
 	return 0;
@@ -147,12 +136,11 @@ static int platram_probe(struct platform_device *pdev)
 	info->pdata = pdata;
 
 	/* get the resource for the memory mapping */
-
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-	if (res == NULL) {
-		dev_err(&pdev->dev, "no memory resource specified\n");
-		err = -ENOENT;
+	info->map.virt = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(info->map.virt)) {
+		err = PTR_ERR(info->map.virt);
+		dev_err(&pdev->dev, "failed to ioremap() region\n");
 		goto exit_free;
 	}
 
@@ -167,26 +155,8 @@ static int platram_probe(struct platform_device *pdev)
 			(char *)pdata->mapname : (char *)pdev->name;
 	info->map.bankwidth = pdata->bankwidth;
 
-	/* register our usage of the memory area */
-
-	info->area = request_mem_region(res->start, info->map.size, pdev->name);
-	if (info->area == NULL) {
-		dev_err(&pdev->dev, "failed to request memory region\n");
-		err = -EIO;
-		goto exit_free;
-	}
-
-	/* remap the memory area */
-
-	info->map.virt = ioremap(res->start, info->map.size);
 	dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
 
-	if (info->map.virt == NULL) {
-		dev_err(&pdev->dev, "failed to ioremap() region\n");
-		err = -EIO;
-		goto exit_free;
-	}
-
 	simple_map_init(&info->map);
 
 	dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] mtd: plat-ram: use release_mem_region instead of release_resource
  2017-08-16 16:22 [PATCH v2] mtd: plat-ram: use release_mem_region instead of release_resource Anton Vasilyev
@ 2017-08-17 13:29 ` Boris Brezillon
  2017-08-22 13:24   ` [PATCH v3] mtd: plat-ram: Replace manual resource management by devm Anton Vasilyev
  0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2017-08-17 13:29 UTC (permalink / raw)
  To: Anton Vasilyev
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	Cyrille Pitchen, linux-mtd, linux-kernel, ldv-project

And now the commit title is no longer matching the patch content.

Le Wed, 16 Aug 2017 19:22:17 +0300,
Anton Vasilyev <vasilyev@ispras.ru> a écrit :

> Replace ioremap() and request_mem_region() by devm_ioremap_resource().
> 
> Found by Linux Driver Verification project (linuxtesting.org).

Maybe you should describe in more details what linuxtesting complained
about and why you decided to fix it using devm_ioremap_resource().

> 
> Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
> Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
> v1: Fix commit based on Boris Brezillon review
> ---
> v2: Change commit by Boris Brezillon solution
> ---
>  drivers/mtd/maps/plat-ram.c | 38 ++++----------------------------------
>  1 file changed, 4 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
> index 5157289..6d9a4d6 100644
> --- a/drivers/mtd/maps/plat-ram.c
> +++ b/drivers/mtd/maps/plat-ram.c
> @@ -43,7 +43,6 @@ struct platram_info {
>  	struct device		*dev;
>  	struct mtd_info		*mtd;
>  	struct map_info		 map;
> -	struct resource		*area;
>  	struct platdata_mtd_ram	*pdata;
>  };
>  
> @@ -97,16 +96,6 @@ static int platram_remove(struct platform_device *pdev)
>  
>  	platram_setrw(info, PLATRAM_RO);
>  
> -	/* release resources */
> -
> -	if (info->area) {
> -		release_resource(info->area);
> -		kfree(info->area);
> -	}
> -
> -	if (info->map.virt != NULL)
> -		iounmap(info->map.virt);
> -
>  	kfree(info);
>  
>  	return 0;
> @@ -147,12 +136,11 @@ static int platram_probe(struct platform_device *pdev)
>  	info->pdata = pdata;
>  
>  	/* get the resource for the memory mapping */
> -
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -
> -	if (res == NULL) {
> -		dev_err(&pdev->dev, "no memory resource specified\n");
> -		err = -ENOENT;
> +	info->map.virt = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(info->map.virt)) {
> +		err = PTR_ERR(info->map.virt);
> +		dev_err(&pdev->dev, "failed to ioremap() region\n");
>  		goto exit_free;
>  	}
>  
> @@ -167,26 +155,8 @@ static int platram_probe(struct platform_device *pdev)
>  			(char *)pdata->mapname : (char *)pdev->name;
>  	info->map.bankwidth = pdata->bankwidth;
>  
> -	/* register our usage of the memory area */
> -
> -	info->area = request_mem_region(res->start, info->map.size, pdev->name);
> -	if (info->area == NULL) {
> -		dev_err(&pdev->dev, "failed to request memory region\n");
> -		err = -EIO;
> -		goto exit_free;
> -	}
> -
> -	/* remap the memory area */
> -
> -	info->map.virt = ioremap(res->start, info->map.size);
>  	dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
>  
> -	if (info->map.virt == NULL) {
> -		dev_err(&pdev->dev, "failed to ioremap() region\n");
> -		err = -EIO;
> -		goto exit_free;
> -	}
> -
>  	simple_map_init(&info->map);
>  
>  	dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3] mtd: plat-ram: Replace manual resource management by devm
  2017-08-17 13:29 ` Boris Brezillon
@ 2017-08-22 13:24   ` Anton Vasilyev
  0 siblings, 0 replies; 3+ messages in thread
From: Anton Vasilyev @ 2017-08-22 13:24 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Anton Vasilyev, David Woodhouse, Brian Norris, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, linux-mtd, linux-kernel,
	ldv-project

Driver contains unsuitable request_mem_region() and
release_resource() calls.

The patch switches manual resource management by devm interface for
readability and error-free simplification.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
v1: Fix commit based on Boris Brezillon review
---
v2: Change commit by Boris Brezillon solution
---
v3: Change description with title
---
 drivers/mtd/maps/plat-ram.c | 38 ++++----------------------------------
 1 file changed, 4 insertions(+), 34 deletions(-)

diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 5157289..6d9a4d6 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -43,7 +43,6 @@ struct platram_info {
 	struct device		*dev;
 	struct mtd_info		*mtd;
 	struct map_info		 map;
-	struct resource		*area;
 	struct platdata_mtd_ram	*pdata;
 };
 
@@ -97,16 +96,6 @@ static int platram_remove(struct platform_device *pdev)
 
 	platram_setrw(info, PLATRAM_RO);
 
-	/* release resources */
-
-	if (info->area) {
-		release_resource(info->area);
-		kfree(info->area);
-	}
-
-	if (info->map.virt != NULL)
-		iounmap(info->map.virt);
-
 	kfree(info);
 
 	return 0;
@@ -147,12 +136,11 @@ static int platram_probe(struct platform_device *pdev)
 	info->pdata = pdata;
 
 	/* get the resource for the memory mapping */
-
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-	if (res == NULL) {
-		dev_err(&pdev->dev, "no memory resource specified\n");
-		err = -ENOENT;
+	info->map.virt = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(info->map.virt)) {
+		err = PTR_ERR(info->map.virt);
+		dev_err(&pdev->dev, "failed to ioremap() region\n");
 		goto exit_free;
 	}
 
@@ -167,26 +155,8 @@ static int platram_probe(struct platform_device *pdev)
 			(char *)pdata->mapname : (char *)pdev->name;
 	info->map.bankwidth = pdata->bankwidth;
 
-	/* register our usage of the memory area */
-
-	info->area = request_mem_region(res->start, info->map.size, pdev->name);
-	if (info->area == NULL) {
-		dev_err(&pdev->dev, "failed to request memory region\n");
-		err = -EIO;
-		goto exit_free;
-	}
-
-	/* remap the memory area */
-
-	info->map.virt = ioremap(res->start, info->map.size);
 	dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
 
-	if (info->map.virt == NULL) {
-		dev_err(&pdev->dev, "failed to ioremap() region\n");
-		err = -EIO;
-		goto exit_free;
-	}
-
 	simple_map_init(&info->map);
 
 	dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-22 13:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-16 16:22 [PATCH v2] mtd: plat-ram: use release_mem_region instead of release_resource Anton Vasilyev
2017-08-17 13:29 ` Boris Brezillon
2017-08-22 13:24   ` [PATCH v3] mtd: plat-ram: Replace manual resource management by devm Anton Vasilyev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).