Skip to contentSkip to conversation

ata: pata_octeon_cf: Use common error handling code in octeon_cf_probe()

PATCH In review Markus Elfring 2 participants 4 messages Sep 17, 2024 – Sep 18, 2024 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ata: pata_octeon_cf: Use common error handling code in octeon_cf_probe()

From: Markus Elfring <[email protected]>
Date: Tue, 17 Sep 2024 13:43:24 +0200

Add a label so that a bit of exception handling can be better reused in a subsequent if branch of this function implementation.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_octeon_cf.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/ata/pata_octeon_cf.c +4 -5
index 0bb9607e7348..62289f6aef95 100644
@@ -848,14 +848,13 @@ static int octeon_cf_probe(struct platform_device *pdev)
 				struct resource *res_dma;
 				int i;
 				res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
-				if (!res_dma) {
-					put_device(&dma_dev->dev);
-					of_node_put(dma_node);
-					return -EINVAL;
-				}
+				if (!res_dma)
+					goto put_device;
+
 				cf_port->dma_base = (u64)devm_ioremap(&pdev->dev, res_dma->start,
 									 resource_size(res_dma));
 				if (!cf_port->dma_base) {
+put_device:
 					put_device(&dma_dev->dev);
 					of_node_put(dma_node);
 					return -EINVAL;

--
2.46.0

#1 lore raw
Quoted 4 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 17 Sep 2024 13:43:24 +0200

Add a label so that a bit of exception handling can be better reused

s/exception/error/.

Quoted 19 lines

in a subsequent if branch of this function implementation.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_octeon_cf.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/ata/pata_octeon_cf.c +0 -2
index 0bb9607e7348..62289f6aef95 100644
@@ -848,14 +848,13 @@ static int octeon_cf_probe(struct platform_device *pdev)
 				struct resource *res_dma;
 				int i;
 				res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
-				if (!res_dma) {
-					put_device(&dma_dev->dev);

drivers/ata/pata_octeon_cf.c static int octeon_cf_probe(struct platform_device *pdev) · line 857

Quoted 10 lines
drivers/ata/pata_octeon_cf.c +4 -3
-					of_node_put(dma_node);
-					return -EINVAL;
-				}
+				if (!res_dma)
+					goto put_device;
+
 				cf_port->dma_base = (u64)devm_ioremap(&pdev->dev, res_dma->start,
 									 resource_size(res_dma));
 				if (!cf_port->dma_base) {
+put_device:

Ugh... :-/
Please use the new-fangled *devm_platform_ioremap_resource() instead of those
old-fashioned APIs.

[...]

MBR, Sergey

#2 lore raw
Quoted 32 lines · Sergey Shtylyov
Quoted 4 lines

From: Markus Elfring <[email protected]>
Date: Tue, 17 Sep 2024 13:43:24 +0200

Add a label so that a bit of exception handling can be better reused

s/exception/error/.

Quoted 25 lines

in a subsequent if branch of this function implementation.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_octeon_cf.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/ata/pata_octeon_cf.c +3 -5
index 0bb9607e7348..62289f6aef95 100644
@@ -848,14 +848,13 @@ static int octeon_cf_probe(struct platform_device *pdev)
 				struct resource *res_dma;
 				int i;
 				res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
-				if (!res_dma) {
-					put_device(&dma_dev->dev);
-					of_node_put(dma_node);
-					return -EINVAL;
-				}
+				if (!res_dma)
+					goto put_device;
+
Quoted 8 lines

drivers/ata/pata_octeon_cf.c static int octeon_cf_probe(struct platform_device *pdev) · line 857

Quoted 4 lines
drivers/ata/pata_octeon_cf.c +1 -0
 				cf_port->dma_base = (u64)devm_ioremap(&pdev->dev, res_dma->start,
 									 resource_size(res_dma));
 				if (!cf_port->dma_base) {
+put_device:

Ugh... :-/
Please use the new-fangled *devm_platform_ioremap_resource() instead of those
old-fashioned APIs.

Another option is to place this error patch somewhere at the end
of this function but I think I prefer the new APIs.

[...]

MBR, Sergey

#3 lore raw

On 9/17/24 23:44, Sergey Shtylyov wrote:
[...]

Quoted 31 lines
Quoted 31 lines
Quoted 4 lines

From: Markus Elfring <[email protected]>
Date: Tue, 17 Sep 2024 13:43:24 +0200

Add a label so that a bit of exception handling can be better reused

s/exception/error/.

Quoted 24 lines

in a subsequent if branch of this function implementation.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_octeon_cf.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/ata/pata_octeon_cf.c +2 -5
index 0bb9607e7348..62289f6aef95 100644
@@ -848,14 +848,13 @@ static int octeon_cf_probe(struct platform_device *pdev)
 				struct resource *res_dma;
 				int i;
 				res_dma = platform_get_resource(dma_dev, IORESOURCE_MEM, 0);
-				if (!res_dma) {
-					put_device(&dma_dev->dev);
-					of_node_put(dma_node);
-					return -EINVAL;
-				}
+				if (!res_dma)
+					goto put_device;
Quoted 8 lines
Quoted 8 lines

drivers/ata/pata_octeon_cf.c static int octeon_cf_probe(struct platform_device *pdev) · line 857

Quoted 5 lines
drivers/ata/pata_octeon_cf.c +2 -0
+
 				cf_port->dma_base = (u64)devm_ioremap(&pdev->dev, res_dma->start,
 									 resource_size(res_dma));
 				if (!cf_port->dma_base) {
+put_device:

Ugh... :-/
Please use the new-fangled *devm_platform_ioremap_resource() instead of those

    Ugh, s/*//...
Quoted 3 lines
Quoted 1 line

old-fashioned APIs.

Another option is to place this error patch somewhere at the end

s/patch/path/, of course... :-)

Quoted 1 line

of this function but I think I prefer the new APIs.

[...]

MBR, Sergey