Skip to contentSkip to conversation

watchdog: davinci_wdt: update to devm_* API

PATCH Superseded Kumar, Anil 3 participants 8 messages Feb 7, 2013 – Feb 8, 2013 Watchdog device drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: davinci_wdt: update to devm_* API

Update the code to use devm_* API so that driver
core will manage resources.

---
This patch applies on top of v3.8-rc6.

Tested on da850 EVM.

:100644 100644 e8e8724... 6ad76a3... M drivers/watchdog/davinci_wdt.c

 drivers/watchdog/davinci_wdt.c |   34 +++++++++-------------------------
 1 files changed, 9 insertions(+), 25 deletions(-)
drivers/watchdog/davinci_wdt.c +9 -25
index e8e8724..6ad76a3 100644
@@ -69,7 +69,6 @@ static unsigned long wdt_status;
 #define WDT_REGION_INITED 2
 #define WDT_DEVICE_INITED 3
 
-static struct resource	*wdt_mem;
 static void __iomem	*wdt_base;
 struct clk		*wdt_clk;
 
@@ -201,10 +200,10 @@ static struct miscdevice davinci_wdt_miscdev = {
 
 static int davinci_wdt_probe(struct platform_device *pdev)
 {
-	int ret = 0, size;
-	struct device *dev = &pdev->dev;
+	int ret = 0;
+	static struct resource  *wdt_mem;
 
-	wdt_clk = clk_get(dev, NULL);
+	wdt_clk = clk_get(&pdev->dev, NULL);
 	if (WARN_ON(IS_ERR(wdt_clk)))
 		return PTR_ERR(wdt_clk);
 
@@ -213,49 +212,34 @@ static int davinci_wdt_probe(struct platform_device *pdev)
 	if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
 		heartbeat = DEFAULT_HEARTBEAT;
 
-	dev_info(dev, "heartbeat %d sec\n", heartbeat);
+	dev_info(&pdev->dev, "heartbeat %d sec\n", heartbeat);
 
 	wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (wdt_mem == NULL) {
-		dev_err(dev, "failed to get memory region resource\n");
+		dev_err(&pdev->dev, "failed to get memory region resource\n");
 		return -ENOENT;
 	}
 
-	size = resource_size(wdt_mem);
-	if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
-		dev_err(dev, "failed to get memory region\n");
-		return -ENOENT;
-	}
-
-	wdt_base = ioremap(wdt_mem->start, size);
+	wdt_base = devm_request_and_ioremap(&pdev->dev, wdt_mem);
 	if (!wdt_base) {
-		dev_err(dev, "failed to map memory region\n");
-		release_mem_region(wdt_mem->start, size);
-		wdt_mem = NULL;
+		dev_err(&pdev->dev, "ioremap failed\n");
 		return -ENOMEM;
 	}
 
 	ret = misc_register(&davinci_wdt_miscdev);
 	if (ret < 0) {
-		dev_err(dev, "cannot register misc device\n");
-		release_mem_region(wdt_mem->start, size);
-		wdt_mem = NULL;
+		dev_err(&pdev->dev, "cannot register misc device\n");
 	} else {
 		set_bit(WDT_DEVICE_INITED, &wdt_status);
+		return ret;
 	}
 
-	iounmap(wdt_base);
 	return ret;
 }
 
 static int davinci_wdt_remove(struct platform_device *pdev)
 {
 	misc_deregister(&davinci_wdt_miscdev);
-	if (wdt_mem) {
-		release_mem_region(wdt_mem->start, resource_size(wdt_mem));
-		wdt_mem = NULL;
-	}
-
 	clk_disable_unprepare(wdt_clk);
 	clk_put(wdt_clk);
 
Signature · 1 line
1.7.4.1
#1 lore raw

Hello.

Quoted 17 lines · Anil

Update the code to use devm_* API so that driver
core will manage resources.

---
This patch applies on top of v3.8-rc6.

Tested on da850 EVM.

:100644 100644 e8e8724... 6ad76a3... M drivers/watchdog/davinci_wdt.c

  drivers/watchdog/davinci_wdt.c |   34 +++++++++-------------------------
  1 files changed, 9 insertions(+), 25 deletions(-)
drivers/watchdog/davinci_wdt.c +0 -0
index e8e8724..6ad76a3 100644

[...]

Quoted 1 line
drivers/watchdog/davinci_wdt.c +0 -0
@@ -213,49 +212,34 @@ static int davinci_wdt_probe(struct platform_device *pdev)

[...]

Quoted 4 lines
drivers/watchdog/davinci_wdt.c +0 -4
-	size = resource_size(wdt_mem);
-	if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
-		dev_err(dev, "failed to get memory region\n");
-		return -ENOENT;

drivers/watchdog/davinci_wdt.c static int davinci_wdt_probe(struct platform_device *pdev) · line 226

Quoted 10 lines
drivers/watchdog/davinci_wdt.c +2 -6
-	}
-
-	wdt_base = ioremap(wdt_mem->start, size);
+	wdt_base = devm_request_and_ioremap(&pdev->dev, wdt_mem);
  	if (!wdt_base) {
-		dev_err(dev, "failed to map memory region\n");
-		release_mem_region(wdt_mem->start, size);
-		wdt_mem = NULL;
+		dev_err(&pdev->dev, "ioremap failed\n");
  		return -ENOMEM;

Comment to devm_request_and_ioremap() suggest returning -EADDRNOTAVAIL
instead.

WBR, Sergei

#2 lore raw

Hi Sergei

Quoted 33 lines · Sergei Shtylyov

Hello.

Quoted 17 lines · Anil

Update the code to use devm_* API so that driver
core will manage resources.

---
This patch applies on top of v3.8-rc6.

Tested on da850 EVM.

:100644 100644 e8e8724... 6ad76a3... M drivers/watchdog/davinci_wdt.c

  drivers/watchdog/davinci_wdt.c |   34 +++++++++-------------------------
  1 files changed, 9 insertions(+), 25 deletions(-)
drivers/watchdog/davinci_wdt.c +0 -0
index e8e8724..6ad76a3 100644

[...]

Quoted 1 line
drivers/watchdog/davinci_wdt.c +0 -0
@@ -213,49 +212,34 @@ static int davinci_wdt_probe(struct platform_device *pdev)

[...]

Quoted 9 lines
drivers/watchdog/davinci_wdt.c +1 -7
-	size = resource_size(wdt_mem);
-	if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
-		dev_err(dev, "failed to get memory region\n");
-		return -ENOENT;
-	}
-
-	wdt_base = ioremap(wdt_mem->start, size);
+	wdt_base = devm_request_and_ioremap(&pdev->dev, wdt_mem);
  	if (!wdt_base) {
Quoted 8 lines

drivers/watchdog/davinci_wdt.c static int davinci_wdt_probe(struct platform_device *pdev) · line 226

Quoted 5 lines
drivers/watchdog/davinci_wdt.c +1 -3
-		dev_err(dev, "failed to map memory region\n");
-		release_mem_region(wdt_mem->start, size);
-		wdt_mem = NULL;
+		dev_err(&pdev->dev, "ioremap failed\n");
  		return -ENOMEM;

Comment to devm_request_and_ioremap() suggest returning -EADDRNOTAVAIL
instead.

Right.

Thanks,
Anil
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Kumar, Anil
Quoted 26 lines · Anil

Update the code to use devm_* API so that driver
core will manage resources.

---
This patch applies on top of v3.8-rc6.

Tested on da850 EVM.

:100644 100644 e8e8724... 6ad76a3... M drivers/watchdog/davinci_wdt.c

 drivers/watchdog/davinci_wdt.c |   34 +++++++++-------------------------
 1 files changed, 9 insertions(+), 25 deletions(-)
drivers/watchdog/davinci_wdt.c +0 -1
index e8e8724..6ad76a3 100644
@@ -69,7 +69,6 @@ static unsigned long wdt_status;
 #define WDT_REGION_INITED 2
 #define WDT_DEVICE_INITED 3
 
-static struct resource	*wdt_mem;
 static void __iomem	*wdt_base;
 struct clk		*wdt_clk;
 

drivers/watchdog/davinci_wdt.c static struct miscdevice davinci_wdt_miscdev = { · line 205

Quoted 5 lines
drivers/watchdog/davinci_wdt.c +0 -2
@@ -201,10 +200,10 @@ static struct miscdevice davinci_wdt_miscdev = {
 
 static int davinci_wdt_probe(struct platform_device *pdev)
 {
-	int ret = 0, size;
-	struct device *dev = &pdev->dev;

Its not clear why you had to drop use of this variable?

drivers/watchdog/davinci_wdt.c static struct miscdevice davinci_wdt_miscdev = { · line 206

Quoted 5 lines
drivers/watchdog/davinci_wdt.c +3 -1
+	int ret = 0;
+	static struct resource  *wdt_mem;
 
-	wdt_clk = clk_get(dev, NULL);
+	wdt_clk = clk_get(&pdev->dev, NULL);

When you are converting to use devres, why not convert this to devm_clk_get() as well?

Thanks,
Sekhar

#4 lore raw

Hi Sekhar,

Thanks for the review.

Quoted 27 lines · Sekhar
Quoted 25 lines · Anil

Update the code to use devm_* API so that driver
core will manage resources.

---
This patch applies on top of v3.8-rc6.

Tested on da850 EVM.

:100644 100644 e8e8724... 6ad76a3... M drivers/watchdog/davinci_wdt.c

 drivers/watchdog/davinci_wdt.c |   34 +++++++++-------------------------
 1 files changed, 9 insertions(+), 25 deletions(-)
drivers/watchdog/davinci_wdt.c +0 -1
index e8e8724..6ad76a3 100644
@@ -69,7 +69,6 @@ static unsigned long wdt_status;
 #define WDT_REGION_INITED 2
 #define WDT_DEVICE_INITED 3
 
-static struct resource	*wdt_mem;
 static void __iomem	*wdt_base;
 struct clk		*wdt_clk;
 
Quoted 8 lines

drivers/watchdog/davinci_wdt.c static struct miscdevice davinci_wdt_miscdev = { · line 205

Quoted 6 lines
drivers/watchdog/davinci_wdt.c +0 -2
@@ -201,10 +200,10 @@ static struct miscdevice davinci_wdt_miscdev = {
 
 static int davinci_wdt_probe(struct platform_device *pdev)
 {
-	int ret = 0, size;
-	struct device *dev = &pdev->dev;

Its not clear why you had to drop use of this variable?

Actually, I have not found any particular need to take pointer into dev and then use in the code. Rather we can directly use.

Quoted 10 lines

drivers/watchdog/davinci_wdt.c static struct miscdevice davinci_wdt_miscdev = { · line 206

Quoted 6 lines
drivers/watchdog/davinci_wdt.c +3 -1
+	int ret = 0;
+	static struct resource  *wdt_mem;
 
-	wdt_clk = clk_get(dev, NULL);
+	wdt_clk = clk_get(&pdev->dev, NULL);

When you are converting to use devres, why not convert this to devm_clk_get() as well?

Right. I will do it.

Thanks,
Anil

#5 lore raw
Quoted 19 lines · Anil
Quoted 9 lines · Sekhar
Quoted 6 lines · Anil

Update the code to use devm_* API so that driver
core will manage resources.

drivers/watchdog/davinci_wdt.c +0 -0
Quoted 8 lines

drivers/watchdog/davinci_wdt.c static struct miscdevice davinci_wdt_miscdev = { · line 205

Quoted 6 lines
drivers/watchdog/davinci_wdt.c +0 -2
@@ -201,10 +200,10 @@ static struct miscdevice davinci_wdt_miscdev = {
 
 static int davinci_wdt_probe(struct platform_device *pdev)
 {
-	int ret = 0, size;
-	struct device *dev = &pdev->dev;

Its not clear why you had to drop use of this variable?

Quoted 2 lines

Actually, I have not found any particular need to take pointer into dev and then use in the code. Rather we can directly use.

No, it is good enough as-is. It will help rid your patch of unnecessary changes and its not really convenient to to keep reading &pdev->dev all the time.

Thanks,
Sekhar

#6 lore raw
Quoted 20 lines · Sekhar
Quoted 19 lines · Anil
Quoted 17 lines · Sekhar

drivers/watchdog/davinci_wdt.c static struct miscdevice davinci_wdt_miscdev = { · line 205

Quoted 13 lines · Anil

Update the code to use devm_* API so that driver
core will manage resources.

drivers/watchdog/davinci_wdt.c +0 -2
@@ -201,10 +200,10 @@ static struct miscdevice davinci_wdt_miscdev = {
 
 static int davinci_wdt_probe(struct platform_device *pdev)
 {
-	int ret = 0, size;
-	struct device *dev = &pdev->dev;

Its not clear why you had to drop use of this variable?

Quoted 7 lines
Quoted 2 lines

Actually, I have not found any particular need to take pointer into dev and then use in the code. Rather we can directly use.

No, it is good enough as-is. It will help rid your patch of unnecessary changes and its not really convenient to to keep reading &pdev->dev all the time.

Ok

Thanks,
Anil

#7 lore raw
In reply to Kumar, Anil
Quoted 68 lines · Anil

Update the code to use devm_* API so that driver
core will manage resources.

---
This patch applies on top of v3.8-rc6.

Tested on da850 EVM.

:100644 100644 e8e8724... 6ad76a3... M drivers/watchdog/davinci_wdt.c

 drivers/watchdog/davinci_wdt.c |   34 +++++++++-------------------------
 1 files changed, 9 insertions(+), 25 deletions(-)
drivers/watchdog/davinci_wdt.c +7 -16
index e8e8724..6ad76a3 100644
@@ -69,7 +69,6 @@ static unsigned long wdt_status;
 #define WDT_REGION_INITED 2
 #define WDT_DEVICE_INITED 3
 
-static struct resource	*wdt_mem;
 static void __iomem	*wdt_base;
 struct clk		*wdt_clk;
 
@@ -201,10 +200,10 @@ static struct miscdevice davinci_wdt_miscdev = {
 
 static int davinci_wdt_probe(struct platform_device *pdev)
 {
-	int ret = 0, size;
-	struct device *dev = &pdev->dev;
+	int ret = 0;
+	static struct resource  *wdt_mem;
 
-	wdt_clk = clk_get(dev, NULL);
+	wdt_clk = clk_get(&pdev->dev, NULL);
 	if (WARN_ON(IS_ERR(wdt_clk)))
 		return PTR_ERR(wdt_clk);
 
@@ -213,49 +212,34 @@ static int davinci_wdt_probe(struct platform_device *pdev)
 	if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
 		heartbeat = DEFAULT_HEARTBEAT;
 
-	dev_info(dev, "heartbeat %d sec\n", heartbeat);
+	dev_info(&pdev->dev, "heartbeat %d sec\n", heartbeat);
 
 	wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (wdt_mem == NULL) {
-		dev_err(dev, "failed to get memory region resource\n");
+		dev_err(&pdev->dev, "failed to get memory region resource\n");
 		return -ENOENT;
 	}
 
-	size = resource_size(wdt_mem);
-	if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
-		dev_err(dev, "failed to get memory region\n");
-		return -ENOENT;
-	}
-
-	wdt_base = ioremap(wdt_mem->start, size);
+	wdt_base = devm_request_and_ioremap(&pdev->dev, wdt_mem);
 	if (!wdt_base) {
-		dev_err(dev, "failed to map memory region\n");
-		release_mem_region(wdt_mem->start, size);
-		wdt_mem = NULL;
+		dev_err(&pdev->dev, "ioremap failed\n");
 		return -ENOMEM;
 	}

drivers/watchdog/davinci_wdt.c static int davinci_wdt_probe(struct platform_device *pdev) · line 234

Quoted 10 lines
drivers/watchdog/davinci_wdt.c +2 -3
 
 	ret = misc_register(&davinci_wdt_miscdev);
 	if (ret < 0) {
-		dev_err(dev, "cannot register misc device\n");
-		release_mem_region(wdt_mem->start, size);
-		wdt_mem = NULL;
+		dev_err(&pdev->dev, "cannot register misc device\n");
 	} else {
 		set_bit(WDT_DEVICE_INITED, &wdt_status);
+		return ret;

No need of return "ret" as it is retuning "ret" just below. I will fix it in V2.

Quoted 21 lines
drivers/watchdog/davinci_wdt.c +0 -6
 	}
 
-	iounmap(wdt_base);
 	return ret;
 }
 
 static int davinci_wdt_remove(struct platform_device *pdev)
 {
 	misc_deregister(&davinci_wdt_miscdev);
-	if (wdt_mem) {
-		release_mem_region(wdt_mem->start, resource_size(wdt_mem));
-		wdt_mem = NULL;
-	}
-
 	clk_disable_unprepare(wdt_clk);
 	clk_put(wdt_clk);
 
Signature · 1 line
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html