Skip to contentSkip to conversation

PATA-Arasan CF: Adjustments for arasan_cf_probe()

PATCH Superseded SF Markus Elfring 3 participants 7 messages Feb 16, 2018 – Feb 19, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover PATA-Arasan CF: Adjustments for arasan_cf_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 16:51:23 +0100

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Delete an error message for a failed memory allocation Delete an unnecessary variable initialisation Move two variable assignments

 drivers/ata/pata_arasan_cf.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
Signature · 1 line
2.16.1
#1 lore raw

PATCH 1/3 pata_arasan_cf: Delete an error message for a failed memory allocation in arasan_cf_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 16:01:12 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_arasan_cf.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/ata/pata_arasan_cf.c +1 -3
index b4d54771c9fe..be5fbcedecbf 100644
@@ -809,10 +809,8 @@ static int arasan_cf_probe(struct platform_device *pdev)
 	}
 
 	acdev = devm_kzalloc(&pdev->dev, sizeof(*acdev), GFP_KERNEL);
-	if (!acdev) {
-		dev_warn(&pdev->dev, "kzalloc fail\n");
+	if (!acdev)
 		return -ENOMEM;
-	}
 
 	if (pdata)
 		quirk = pdata->quirk;
Signature · 1 line
2.16.1
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] pata_arasan_cf: Delete an error message for a failed memory allocation in arasan_cf_probe()

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 16:01:12 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_arasan_cf.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/ata/pata_arasan_cf.c +0 -0
index b4d54771c9fe..be5fbcedecbf 100644
@@ -809,10 +809,8 @@ static int arasan_cf_probe(struct platform_device *pdev)
 	}

drivers/ata/pata_arasan_cf.c static int arasan_cf_probe(struct platform_device *pdev) · line 816

Quoted 10 lines
drivers/ata/pata_arasan_cf.c +1 -3
 
 	acdev = devm_kzalloc(&pdev->dev, sizeof(*acdev), GFP_KERNEL);
-	if (!acdev) {
-		dev_warn(&pdev->dev, "kzalloc fail\n");
+	if (!acdev)
 		return -ENOMEM;
-	}
 
 	if (pdata)
 		quirk = pdata->quirk;
Signature · 1 line
viresh
#3 lore raw

PATCH 2/3 pata_arasan_cf: Delete an unnecessary variable initialisation in arasan_cf_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 16:28:23 +0100

The local variable "ret" will eventually be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/ata/pata_arasan_cf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/pata_arasan_cf.c +1 -1
index be5fbcedecbf..ebecab8c3f36 100644
@@ -796,7 +796,7 @@ static int arasan_cf_probe(struct platform_device *pdev)
 	struct resource *res;
 	u32 quirk;
 	irq_handler_t irq_handler = NULL;
-	int ret = 0;
+	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res)
Signature · 1 line
2.16.1
#4 lore raw

Re: [PATCH 2/3] pata_arasan_cf: Delete an unnecessary variable initialisation in arasan_cf_probe()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 16:28:23 +0100

The local variable "ret" will eventually be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

Applied 1-2 to libata/for-4.17.

Thanks.

Signature · 1 line
tejun
#5 lore raw

PATCH 3/3 pata_arasan_cf: Move two variable assignments in arasan_cf_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 16:42:26 +0100

Move assignments for the local variables "irq_handler" and "pdata" so that their setting will only be performed after a call of the function "devm_kzalloc" succeeded by this function. Thus adjust a corresponding if statement.

---
 drivers/ata/pata_arasan_cf.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/ata/pata_arasan_cf.c +7 -4
index ebecab8c3f36..27f241b1b1b1 100644
@@ -790,12 +790,12 @@ static struct ata_port_operations arasan_cf_ops = {
 static int arasan_cf_probe(struct platform_device *pdev)
 {
 	struct arasan_cf_dev *acdev;
-	struct arasan_cf_pdata *pdata = dev_get_platdata(&pdev->dev);
+	struct arasan_cf_pdata *pdata;
 	struct ata_host *host;
 	struct ata_port *ap;
 	struct resource *res;
 	u32 quirk;
-	irq_handler_t irq_handler = NULL;
+	irq_handler_t irq_handler;
 	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -812,6 +812,7 @@ static int arasan_cf_probe(struct platform_device *pdev)
 	if (!acdev)
 		return -ENOMEM;
 
+	pdata = dev_get_platdata(&pdev->dev);
 	if (pdata)
 		quirk = pdata->quirk;
 	else
@@ -819,10 +820,12 @@ static int arasan_cf_probe(struct platform_device *pdev)
 
 	/* if irq is 0, support only PIO */
 	acdev->irq = platform_get_irq(pdev, 0);
-	if (acdev->irq)
+	if (acdev->irq) {
 		irq_handler = arasan_cf_interrupt;
-	else
+	} else {
 		quirk |= CF_BROKEN_MWDMA | CF_BROKEN_UDMA;
+		irq_handler = NULL;
+	}
 
 	acdev->pbase = res->start;
 	acdev->vbase = devm_ioremap_nocache(&pdev->dev, res->start,
Signature · 1 line
2.16.1
#6 lore raw

Re: [PATCH 3/3] pata_arasan_cf: Move two variable assignments in arasan_cf_probe()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 16:42:26 +0100

Move assignments for the local variables "irq_handler" and "pdata" so that their setting will only be performed after a call of the function "devm_kzalloc" succeeded by this function. Thus adjust a corresponding if statement.

I'm not gonna apply this. If there's something preventing the compiler from optimizing it, the right thing to do is fixing that.

Thanks.

Signature · 1 line
tejun