2018-02-16 19:12:11

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)

--
2.16.1



2018-02-16 19:13:11

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] pata_it821x: Use common error handling code in it821x_firmware_command()

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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/ata/pata_it821x.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 46eacb6b93dd..6470112e5b48 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -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;
}

--
2.16.1


2018-02-16 19:13:31

by SF Markus Elfring

[permalink] [raw]
Subject: [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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/ata/pata_it821x.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 7a21edf89e72..46eacb6b93dd 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -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;
--
2.16.1


2018-02-18 13:28:34

by Tejun Heo

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

On Fri, Feb 16, 2018 at 03:22:18PM +0100, SF Markus Elfring wrote:
> 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.
>
> Signed-off-by: Markus Elfring <[email protected]>

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.

--
tejun