Message ID | 20180910083904.sdjreuxjxtd2puc4@kili.mountain (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | power: supply: ab8500_fg: silence uninitialized variable warnings | expand |
Hi, On Mon, Sep 10, 2018 at 11:39:04AM +0300, Dan Carpenter wrote: > If kstrtoul() fails then we print "charge_full" when it's uninitialized. > The debug printk doesn't add anything so I deleted it and cleaned these > two functions up a bit. > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> > Thanks, queued. -- Sebastian > diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c > index 2bdadb58bcc6..776102c31305 100644 > --- a/drivers/power/supply/ab8500_fg.c > +++ b/drivers/power/supply/ab8500_fg.c > @@ -2433,17 +2433,14 @@ static ssize_t charge_full_store(struct ab8500_fg *di, const char *buf, > size_t count) > { > unsigned long charge_full; > - ssize_t ret; > + int ret; > > ret = kstrtoul(buf, 10, &charge_full); > + if (ret) > + return ret; > > - dev_dbg(di->dev, "Ret %zd charge_full %lu", ret, charge_full); > - > - if (!ret) { > - di->bat_cap.max_mah = (int) charge_full; > - ret = count; > - } > - return ret; > + di->bat_cap.max_mah = (int) charge_full; > + return count; > } > > static ssize_t charge_now_show(struct ab8500_fg *di, char *buf) > @@ -2455,20 +2452,16 @@ static ssize_t charge_now_store(struct ab8500_fg *di, const char *buf, > size_t count) > { > unsigned long charge_now; > - ssize_t ret; > + int ret; > > ret = kstrtoul(buf, 10, &charge_now); > + if (ret) > + return ret; > > - dev_dbg(di->dev, "Ret %zd charge_now %lu was %d", > - ret, charge_now, di->bat_cap.prev_mah); > - > - if (!ret) { > - di->bat_cap.user_mah = (int) charge_now; > - di->flags.user_cap = true; > - ret = count; > - queue_delayed_work(di->fg_wq, &di->fg_periodic_work, 0); > - } > - return ret; > + di->bat_cap.user_mah = (int) charge_now; > + di->flags.user_cap = true; > + queue_delayed_work(di->fg_wq, &di->fg_periodic_work, 0); > + return count; > } > > static struct ab8500_fg_sysfs_entry charge_full_attr =
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 2bdadb58bcc6..776102c31305 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -2433,17 +2433,14 @@ static ssize_t charge_full_store(struct ab8500_fg *di, const char *buf, size_t count) { unsigned long charge_full; - ssize_t ret; + int ret; ret = kstrtoul(buf, 10, &charge_full); + if (ret) + return ret; - dev_dbg(di->dev, "Ret %zd charge_full %lu", ret, charge_full); - - if (!ret) { - di->bat_cap.max_mah = (int) charge_full; - ret = count; - } - return ret; + di->bat_cap.max_mah = (int) charge_full; + return count; } static ssize_t charge_now_show(struct ab8500_fg *di, char *buf) @@ -2455,20 +2452,16 @@ static ssize_t charge_now_store(struct ab8500_fg *di, const char *buf, size_t count) { unsigned long charge_now; - ssize_t ret; + int ret; ret = kstrtoul(buf, 10, &charge_now); + if (ret) + return ret; - dev_dbg(di->dev, "Ret %zd charge_now %lu was %d", - ret, charge_now, di->bat_cap.prev_mah); - - if (!ret) { - di->bat_cap.user_mah = (int) charge_now; - di->flags.user_cap = true; - ret = count; - queue_delayed_work(di->fg_wq, &di->fg_periodic_work, 0); - } - return ret; + di->bat_cap.user_mah = (int) charge_now; + di->flags.user_cap = true; + queue_delayed_work(di->fg_wq, &di->fg_periodic_work, 0); + return count; } static struct ab8500_fg_sysfs_entry charge_full_attr =
If kstrtoul() fails then we print "charge_full" when it's uninitialized. The debug printk doesn't add anything so I deleted it and cleaned these two functions up a bit. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>