linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] PATA-IT821x: Adjustments for it821x_firmware_command()
@ 2018-02-16 14:20 SF Markus Elfring
  2018-02-16 14:22 ` [PATCH 1/2] pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command() SF Markus Elfring
  2018-02-16 14:23 ` [PATCH 2/2] pata_it821x: Use common error handling code " SF Markus Elfring
  0 siblings, 2 replies; 4+ messages in thread
From: SF Markus Elfring @ 2018-02-16 14:20 UTC (permalink / raw)
  To: linux-ide, Bartlomiej Zolnierkiewicz, Tejun Heo; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command()
  2018-02-16 14:20 [PATCH 0/2] PATA-IT821x: Adjustments for it821x_firmware_command() SF Markus Elfring
@ 2018-02-16 14:22 ` SF Markus Elfring
  2018-02-18 13:27   ` Tejun Heo
  2018-02-16 14:23 ` [PATCH 2/2] pata_it821x: Use common error handling code " SF Markus Elfring
  1 sibling, 1 reply; 4+ messages in thread
From: SF Markus Elfring @ 2018-02-16 14:22 UTC (permalink / raw)
  To: linux-ide, Bartlomiej Zolnierkiewicz, Tejun Heo; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] pata_it821x: Use common error handling code in it821x_firmware_command()
  2018-02-16 14:20 [PATCH 0/2] PATA-IT821x: Adjustments for it821x_firmware_command() SF Markus Elfring
  2018-02-16 14:22 ` [PATCH 1/2] pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command() SF Markus Elfring
@ 2018-02-16 14:23 ` SF Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2018-02-16 14:23 UTC (permalink / raw)
  To: linux-ide, Bartlomiej Zolnierkiewicz, Tejun Heo; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command()
  2018-02-16 14:22 ` [PATCH 1/2] pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command() SF Markus Elfring
@ 2018-02-18 13:27   ` Tejun Heo
  0 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2018-02-18 13:27 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-ide, Bartlomiej Zolnierkiewicz, LKML, kernel-janitors

On Fri, Feb 16, 2018 at 03:22:18PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-18 13:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-16 14:20 [PATCH 0/2] PATA-IT821x: Adjustments for it821x_firmware_command() SF Markus Elfring
2018-02-16 14:22 ` [PATCH 1/2] pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command() SF Markus Elfring
2018-02-18 13:27   ` Tejun Heo
2018-02-16 14:23 ` [PATCH 2/2] pata_it821x: Use common error handling code " SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).