2012-05-05 12:53:37

by Anton Vorontsov

[permalink] [raw]
Subject: Re: [PATCH 4/4] power-supply: smb347-charger: convert to regmap API

On Mon, Apr 16, 2012 at 11:48:41AM +0300, Mika Westerberg wrote:
> The smb347-charger driver does a lot of read-modify-write to the device
> registers. Instead of open-coding everything we can take advantage of regmap
> API which provides nice functions to do this kind of things.
>
> In addition there is no need for custom debugfs file for dumping registers as
> this is already provided by the regmap API.
>
> Signed-off-by: Mika Westerberg <[email protected]>
[...]
> static int smb347_set_temp_limits(struct smb347_charger *smb)
> @@ -491,22 +468,13 @@ static int smb347_set_temp_limits(struct smb347_charger *smb)
> val = clamp_val(val, 100, 130) - 100;
> val /= 10;
>
> - ret = smb347_read(smb, CFG_OTG);
> - if (ret < 0)
> - return ret;
> -
> - ret &= ~CFG_OTG_TEMP_THRESHOLD_MASK;
> - ret |= val << CFG_OTG_TEMP_THRESHOLD_SHIFT;
> -
> - ret = smb347_write(smb, CFG_OTG, ret);
> + ret = regmap_update_bits(smb->regmap, CFG_OTG,
> + CFG_OTG_TEMP_THRESHOLD_MASK,
> + val << CFG_OTG_TEMP_THRESHOLD_SHIFT);
> if (ret < 0)
> return ret;
> }
>
> - ret = smb347_read(smb, CFG_TEMP_LIMIT);
> - if (ret < 0)
> - return ret;
> -

FYI, removing these hunks causes the following warning:

CC drivers/power/smb347-charger.o
drivers/power/smb347-charger.c: In function ‘smb347_set_temp_limits’:
drivers/power/smb347-charger.c:462:6: warning: ‘ret’ may be used uninitialized in this function [-Wuninitialized]

I fixed this by the following change:

diff --git a/drivers/power/smb347-charger.c b/drivers/power/smb347-charger.c
index 1f27d21..cf31b31 100644
--- a/drivers/power/smb347-charger.c
+++ b/drivers/power/smb347-charger.c
@@ -459,7 +459,8 @@ static int smb347_set_voltage_limits(struct smb347_charger *smb)
static int smb347_set_temp_limits(struct smb347_charger *smb)
{
bool enable_therm_monitor = false;
- int ret, val;
+ int ret = 0;
+ int val;

if (smb->pdata->chip_temp_threshold) {
val = smb->pdata->chip_temp_threshold;

Please check if that's all OK.

Thanks!

--
Anton Vorontsov
Email: [email protected]


2012-05-06 06:33:45

by Mika Westerberg

[permalink] [raw]
Subject: Re: [PATCH 4/4] power-supply: smb347-charger: convert to regmap API

On Sat, May 05, 2012 at 05:52:11AM -0700, Anton Vorontsov wrote:
>
> I fixed this by the following change:
>
> diff --git a/drivers/power/smb347-charger.c b/drivers/power/smb347-charger.c
> index 1f27d21..cf31b31 100644
> --- a/drivers/power/smb347-charger.c
> +++ b/drivers/power/smb347-charger.c
> @@ -459,7 +459,8 @@ static int smb347_set_voltage_limits(struct smb347_charger *smb)
> static int smb347_set_temp_limits(struct smb347_charger *smb)
> {
> bool enable_therm_monitor = false;
> - int ret, val;
> + int ret = 0;
> + int val;
>
> if (smb->pdata->chip_temp_threshold) {
> val = smb->pdata->chip_temp_threshold;
>
> Please check if that's all OK.

Looks ok to me. Thanks for fixing it.