Skip to contentSkip to conversation

PATA-IT821x: Adjustments for it821x_firmware_command()

PATCH In review SF Markus Elfring 2 participants 4 messages Feb 16, 2018 – Feb 18, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover PATA-IT821x: Adjustments for it821x_firmware_command()

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 15:03:45 +0100

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

Markus Elfring (2):
Delete an error message for a failed memory allocation Use common error handling code

 drivers/ata/pata_it821x.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.16.1
#1 lore raw

PATCH 1/2 pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command()

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 14:04:49 +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_it821x.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/ata/pata_it821x.c +3 -3
index 7a21edf89e72..46eacb6b93dd 100644
@@ -658,10 +658,10 @@ static u8 *it821x_firmware_command(struct ata_port *ap, u8 cmd, int len)
 	u8 status;
 	int n = 0;
 	u16 *buf = kmalloc(len, GFP_KERNEL);
-	if (buf = NULL) {
-		printk(KERN_ERR "it821x_firmware_command: Out of memory\n");
+
+	if (!buf)
 		return NULL;
-	}
+
 	/* This isn't quite a normal ATA command as we are talking to the
 	   firmware not the drives */
 	ap->ctl |= ATA_NIEN;
Signature · 1 line
2.16.1
#2 lore raw

Re: [PATCH 1/2] pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command()

Quoted 8 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 16 Feb 2018 14:04:49 +0100

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

This issue was detected by using the Coccinelle software.

Applying this one to libata/for-4.17 but skipping the next one. There's no point in making these trivial changes. It's just churn without actual benefits but only risks.

Thanks.

Signature · 1 line
tejun
#3 lore raw

PATCH 2/2 pata_it821x: Use common error handling code in it821x_firmware_command()

In reply to SF Markus Elfring

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

Add a jump target so that a bit of exception handling can be better reused at the end of this function.

Reorder three function calls.

---
 drivers/ata/pata_it821x.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/ata/pata_it821x.c +4 -3
index 46eacb6b93dd..6470112e5b48 100644
@@ -675,9 +675,8 @@ static u8 *it821x_firmware_command(struct ata_port *ap, u8 cmd, int len)
 	while(n++ < 10) {
 		status = ioread8(ap->ioaddr.status_addr);
 		if (status & ATA_ERR) {
-			kfree(buf);
 			printk(KERN_ERR "it821x_firmware_command: rejected\n");
-			return NULL;
+			goto free_buffer;
 		}
 		if (status & ATA_DRQ) {
 			ioread16_rep(ap->ioaddr.data_addr, buf, len/2);
@@ -687,6 +686,8 @@ static u8 *it821x_firmware_command(struct ata_port *ap, u8 cmd, int len)
 	}
-	kfree(buf);
+
 	printk(KERN_ERR "it821x_firmware_command: timeout\n");
+free_buffer:
+	kfree(buf);
 	return NULL;
 }
 
Signature · 1 line
2.16.1