Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1198565 > unrolled thread

[PATCH] Check return code from pdc20621_i2c_read()

Started byTomer Barletz <barletz@gmail.com>
First post2015-08-03 08:10 +0200
Last post2015-08-03 17:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH] Check return code from pdc20621_i2c_read() Tomer Barletz <barletz@gmail.com> - 2015-08-03 08:10 +0200
    Re: [PATCH] Check return code from pdc20621_i2c_read() Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-08-03 17:50 +0200

#1198565 — [PATCH] Check return code from pdc20621_i2c_read()

FromTomer Barletz <barletz@gmail.com>
Date2015-08-03 08:10 +0200
Subject[PATCH] Check return code from pdc20621_i2c_read()
Message-ID<pTh6F-2Cf-1@gated-at.bofh.it>
The variable spd0 might be used uninitialized when pdc20621_i2c_read()
fails.
This also generates a compilation warning with gcc 5.1.

Signed-off-by: Tomer Barletz <barletz@gmail.com>
---
 drivers/ata/sata_sx4.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index 3a18a8a..070b272 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -1238,8 +1238,11 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_host *host)
 	readl(mmio + PDC_SDRAM_CONTROL);
 
 	/* Turn on for ECC */
-	pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
-			  PDC_DIMM_SPD_TYPE, &spd0);
+	if (!pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
+	                       PDC_DIMM_SPD_TYPE, &spd0)) {
+		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);
+		return 1;
+	}
 	if (spd0 == 0x02) {
 		data |= (0x01 << 16);
 		writel(data, mmio + PDC_SDRAM_CONTROL);
@@ -1380,8 +1383,11 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
 
 	/* ECC initiliazation. */
 
-	pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
-			  PDC_DIMM_SPD_TYPE, &spd0);
+	if (!pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
+	                       PDC_DIMM_SPD_TYPE, &spd0)) {
+		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);
+		return 1;
+	}
 	if (spd0 == 0x02) {
 		void *buf;
 		VPRINTK("Start ECC initialization\n");
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1198979

FromSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Date2015-08-03 17:50 +0200
Message-ID<pTq9Y-7oo-13@gated-at.bofh.it>
In reply to#1198565
Hello.

On 08/03/2015 09:06 AM, Tomer Barletz wrote:

> The variable spd0 might be used uninitialized when pdc20621_i2c_read()
> fails.
> This also generates a compilation warning with gcc 5.1.

> Signed-off-by: Tomer Barletz <barletz@gmail.com>
> ---
>   drivers/ata/sata_sx4.c | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)

> diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
> index 3a18a8a..070b272 100644
> --- a/drivers/ata/sata_sx4.c
> +++ b/drivers/ata/sata_sx4.c
> @@ -1238,8 +1238,11 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_host *host)
>   	readl(mmio + PDC_SDRAM_CONTROL);
>
>   	/* Turn on for ECC */
> -	pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
> -			  PDC_DIMM_SPD_TYPE, &spd0);
> +	if (!pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
> +	                       PDC_DIMM_SPD_TYPE, &spd0)) {
> +		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);
> +		return 1;
> +	}
>   	if (spd0 == 0x02) {
>   		data |= (0x01 << 16);
>   		writel(data, mmio + PDC_SDRAM_CONTROL);
> @@ -1380,8 +1383,11 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
>
>   	/* ECC initiliazation. */
>
> -	pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
> -			  PDC_DIMM_SPD_TYPE, &spd0);
> +	if (!pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
> +	                       PDC_DIMM_SPD_TYPE, &spd0)) {
> +		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);
> +		return 1;
> +	}
>   	if (spd0 == 0x02) {
>   		void *buf;
>   		VPRINTK("Start ECC initialization\n");

$ scripts/checkpatch.pl ~/patches/Check-return-code-from-pdc20621_i2c_read.patch
ERROR: code indent should use tabs where possible
#23: FILE: drivers/ata/sata_sx4.c:1242:
+^I                       PDC_DIMM_SPD_TYPE, &spd0)) {$

WARNING: line over 80 characters
#24: FILE: drivers/ata/sata_sx4.c:1243:
+		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", 
PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);

WARNING: Prefer [subsystem eg: netdev]_err([subsystem]dev, ... then 
dev_err(dev, ... then pr_err(...  to printk(KERN_ERR ...
#24: FILE: drivers/ata/sata_sx4.c:1243:
+		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", 
PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);

ERROR: code indent should use tabs where possible
#37: FILE: drivers/ata/sata_sx4.c:1387:
+^I                       PDC_DIMM_SPD_TYPE, &spd0)) {$

WARNING: line over 80 characters
#38: FILE: drivers/ata/sata_sx4.c:1388:
+		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", 
PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);

WARNING: Prefer [subsystem eg: netdev]_err([subsystem]dev, ... then 
dev_err(dev, ... then pr_err(...  to printk(KERN_ERR ...
#38: FILE: drivers/ata/sata_sx4.c:1388:
+		printk(KERN_ERR "Failed in i2c read: device=%#x, subaddr=%#x\n", 
PDC_DIMM0_SPD_DEV_ADDRESS, PDC_DIMM_SPD_TYPE);

total: 2 errors, 4 warnings, 26 lines checked

NOTE: Whitespace errors detected.
       You may wish to use scripts/cleanpatch or scripts/cleanfile

/home/headless/patches/Check-return-code-from-pdc20621_i2c_read.patch has 
style problems, please review.

NOTE: If any of the errors are false positives, please report
       them to the maintainer, see CHECKPATCH in MAINTAINERS.

MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web