linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: ab8500_fg.c:  Cleaning up uninitialized variables
@ 2014-06-01 20:03 Rickard Strandqvist
  2014-06-29 23:47 ` Rickard Strandqvist
  0 siblings, 1 reply; 2+ messages in thread
From: Rickard Strandqvist @ 2014-06-01 20:03 UTC (permalink / raw)
  To: Dmitry Eremin-Solenikov, David Woodhouse
  Cc: Rickard Strandqvist, Grant Likely, Rob Herring, linux-kernel, devicetree

In this case the wrong variable is used, which has never been initialized.
This will lead to a serious error.

This was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/power/ab8500_fg.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index 3cb4178..019e33f 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -2969,7 +2969,7 @@ static struct device_attribute ab8505_fg_sysfs_psy_attrs[] = {
 
 static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev)
 {
-	unsigned int i, j;
+	unsigned int j;
 	struct power_supply *psy = dev_get_drvdata(dev);
 	struct ab8500_fg *di;
 
@@ -2986,7 +2986,7 @@ static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev)
 sysfs_psy_create_attrs_failed_ab8505:
 	dev_err(dev, "Failed creating sysfs psy attrs for ab8505.\n");
 	while (j--)
-		device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[i]);
+		device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[j]);
 
 	return -EIO;
 }
-- 
1.7.10.4


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

* Re: [PATCH] power: ab8500_fg.c: Cleaning up uninitialized variables
  2014-06-01 20:03 [PATCH] power: ab8500_fg.c: Cleaning up uninitialized variables Rickard Strandqvist
@ 2014-06-29 23:47 ` Rickard Strandqvist
  0 siblings, 0 replies; 2+ messages in thread
From: Rickard Strandqvist @ 2014-06-29 23:47 UTC (permalink / raw)
  To: Dmitry Eremin-Solenikov, David Woodhouse, Linus Torvalds
  Cc: Rickard Strandqvist, Grant Likely, Rob Herring, linux-kernel, devicetree

Hi

Can someone please check on this!

This will cause an error, and is one of the most obvious ones I've found.
So give it one minute please.

Kind regards
Rickard Strandqvist


2014-06-01 22:03 GMT+02:00 Rickard Strandqvist
<rickard_strandqvist@spectrumdigital.se>:
> In this case the wrong variable is used, which has never been initialized.
> This will lead to a serious error.
>
> This was largely found by using a static code analysis program called cppcheck.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  drivers/power/ab8500_fg.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
> index 3cb4178..019e33f 100644
> --- a/drivers/power/ab8500_fg.c
> +++ b/drivers/power/ab8500_fg.c
> @@ -2969,7 +2969,7 @@ static struct device_attribute ab8505_fg_sysfs_psy_attrs[] = {
>
>  static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev)
>  {
> -       unsigned int i, j;
> +       unsigned int j;
>         struct power_supply *psy = dev_get_drvdata(dev);
>         struct ab8500_fg *di;
>
> @@ -2986,7 +2986,7 @@ static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev)
>  sysfs_psy_create_attrs_failed_ab8505:
>         dev_err(dev, "Failed creating sysfs psy attrs for ab8505.\n");
>         while (j--)
> -               device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[i]);
> +               device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[j]);
>
>         return -EIO;
>  }
> --
> 1.7.10.4
>

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

end of thread, other threads:[~2014-06-29 23:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-01 20:03 [PATCH] power: ab8500_fg.c: Cleaning up uninitialized variables Rickard Strandqvist
2014-06-29 23:47 ` Rickard Strandqvist

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).