diff mbox series

[v2,1/3] ACPI: PMIC: Use sizeof() instead of hard coded value

Message ID 20220830171155.42962-1-andriy.shevchenko@linux.intel.com
State Superseded
Headers show
Series [v2,1/3] ACPI: PMIC: Use sizeof() instead of hard coded value | expand

Commit Message

Andy Shevchenko Aug. 30, 2022, 5:11 p.m. UTC
It's better to use sizeof() of a given buffer than spreading
a hard coded value.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: updated another driver as well (due to this no tag added)
 drivers/acpi/pmic/intel_pmic_chtdc_ti.c | 2 +-
 drivers/acpi/pmic/intel_pmic_xpower.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Mika Westerberg Aug. 31, 2022, 5:43 a.m. UTC | #1
On Tue, Aug 30, 2022 at 08:11:54PM +0300, Andy Shevchenko wrote:
> -#define VR_MODE_DISABLED        0
> -#define VR_MODE_AUTO            BIT(0)
> -#define VR_MODE_NORMAL          BIT(1)
> -#define VR_MODE_SWITCH          BIT(2)
> -#define VR_MODE_ECO             (BIT(0)|BIT(1))
> +#define PMIC_REG_MASK		GENMASK(11, 0)
> +
> +#define VR_MODE_DISABLED        (0 << 0)
> +#define VR_MODE_AUTO            (1 << 0)
> +#define VR_MODE_NORMAL          (2 << 0)
> +#define VR_MODE_ECO             (3 << 0)
> +#define VR_MODE_SWITCH          (4 << 0)

IMHO this one is worse than what it was.

Anyway, that's just a nitpick. The other parts look good,

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Hans de Goede Aug. 31, 2022, 9:37 a.m. UTC | #2
Hi,

On 8/31/22 11:34, Andy Shevchenko wrote:
> On Wed, Aug 31, 2022 at 08:43:54AM +0300, Mika Westerberg wrote:
>> On Tue, Aug 30, 2022 at 08:11:54PM +0300, Andy Shevchenko wrote:
>>> -#define VR_MODE_DISABLED        0
>>> -#define VR_MODE_AUTO            BIT(0)
>>> -#define VR_MODE_NORMAL          BIT(1)
>>> -#define VR_MODE_SWITCH          BIT(2)
>>> -#define VR_MODE_ECO             (BIT(0)|BIT(1))
>>> +#define PMIC_REG_MASK		GENMASK(11, 0)
>>> +
>>> +#define VR_MODE_DISABLED        (0 << 0)
>>> +#define VR_MODE_AUTO            (1 << 0)
>>> +#define VR_MODE_NORMAL          (2 << 0)
>>> +#define VR_MODE_ECO             (3 << 0)
>>> +#define VR_MODE_SWITCH          (4 << 0)
>>
>> IMHO this one is worse than what it was.
> 
> I'm not sure why. Here is obvious wrong use of BIT() macro against
> plain numbers. I can split it into a separate change with an explanation
> of why it's better. But I think it doesn't worth the churn.

FWIW I'm with Andy here, the VR_MODE_ECO clearly is trying
to just say 3, so this is just a plain enum for values 0-4 and
as such should not use the BIT macros.

Regards,

Hans


>> Anyway, that's just a nitpick. The other parts look good,
>>
>> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> Thanks!
>
David Laight Aug. 31, 2022, 10:06 a.m. UTC | #3
From: Mika Westerberg
> Sent: 31 August 2022 10:49
> 
> On Wed, Aug 31, 2022 at 11:37:21AM +0200, Hans de Goede wrote:
> > Hi,
> >
> > On 8/31/22 11:34, Andy Shevchenko wrote:
> > > On Wed, Aug 31, 2022 at 08:43:54AM +0300, Mika Westerberg wrote:
> > >> On Tue, Aug 30, 2022 at 08:11:54PM +0300, Andy Shevchenko wrote:
> > >>> -#define VR_MODE_DISABLED        0
> > >>> -#define VR_MODE_AUTO            BIT(0)
> > >>> -#define VR_MODE_NORMAL          BIT(1)
> > >>> -#define VR_MODE_SWITCH          BIT(2)
> > >>> -#define VR_MODE_ECO             (BIT(0)|BIT(1))
> > >>> +#define PMIC_REG_MASK		GENMASK(11, 0)
> > >>> +
> > >>> +#define VR_MODE_DISABLED        (0 << 0)
> > >>> +#define VR_MODE_AUTO            (1 << 0)
> > >>> +#define VR_MODE_NORMAL          (2 << 0)
> > >>> +#define VR_MODE_ECO             (3 << 0)
> > >>> +#define VR_MODE_SWITCH          (4 << 0)
> > >>
> > >> IMHO this one is worse than what it was.
> > >
> > > I'm not sure why. Here is obvious wrong use of BIT() macro against
> > > plain numbers. I can split it into a separate change with an explanation
> > > of why it's better. But I think it doesn't worth the churn.
> >
> > FWIW I'm with Andy here, the VR_MODE_ECO clearly is trying
> > to just say 3, so this is just a plain enum for values 0-4 and
> > as such should not use the BIT macros.
> 
> Yeah, enum would look better but the << 0 just makes me confused ;-)

No idea what that code is doing.
The values are all used to initialise a .bit structure member.
So maybe BIT() is right.
The _ECO value isn't used at all.

Deeper analysis may be needed.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Andy Shevchenko Aug. 31, 2022, 10:27 a.m. UTC | #4
On Wed, Aug 31, 2022 at 10:06:09AM +0000, David Laight wrote:
> From: Mika Westerberg
> > Sent: 31 August 2022 10:49
> > On Wed, Aug 31, 2022 at 11:37:21AM +0200, Hans de Goede wrote:
> > > On 8/31/22 11:34, Andy Shevchenko wrote:
> > > > On Wed, Aug 31, 2022 at 08:43:54AM +0300, Mika Westerberg wrote:
> > > >> On Tue, Aug 30, 2022 at 08:11:54PM +0300, Andy Shevchenko wrote:
> > > >>> -#define VR_MODE_DISABLED        0
> > > >>> -#define VR_MODE_AUTO            BIT(0)
> > > >>> -#define VR_MODE_NORMAL          BIT(1)
> > > >>> -#define VR_MODE_SWITCH          BIT(2)
> > > >>> -#define VR_MODE_ECO             (BIT(0)|BIT(1))
> > > >>> +#define PMIC_REG_MASK		GENMASK(11, 0)
> > > >>> +
> > > >>> +#define VR_MODE_DISABLED        (0 << 0)
> > > >>> +#define VR_MODE_AUTO            (1 << 0)
> > > >>> +#define VR_MODE_NORMAL          (2 << 0)
> > > >>> +#define VR_MODE_ECO             (3 << 0)
> > > >>> +#define VR_MODE_SWITCH          (4 << 0)
> > > >>
> > > >> IMHO this one is worse than what it was.
> > > >
> > > > I'm not sure why. Here is obvious wrong use of BIT() macro against
> > > > plain numbers. I can split it into a separate change with an explanation
> > > > of why it's better. But I think it doesn't worth the churn.
> > >
> > > FWIW I'm with Andy here, the VR_MODE_ECO clearly is trying
> > > to just say 3, so this is just a plain enum for values 0-4 and
> > > as such should not use the BIT macros.
> > 
> > Yeah, enum would look better but the << 0 just makes me confused ;-)
> 
> No idea what that code is doing.
> The values are all used to initialise a .bit structure member.
> So maybe BIT() is right.
> The _ECO value isn't used at all.
> 
> Deeper analysis may be needed.

So, can you do that since you already started?
diff mbox series

Patch

diff --git a/drivers/acpi/pmic/intel_pmic_chtdc_ti.c b/drivers/acpi/pmic/intel_pmic_chtdc_ti.c
index 418eec523025..6c2a6da430ed 100644
--- a/drivers/acpi/pmic/intel_pmic_chtdc_ti.c
+++ b/drivers/acpi/pmic/intel_pmic_chtdc_ti.c
@@ -87,7 +87,7 @@  static int chtdc_ti_pmic_get_raw_temp(struct regmap *regmap, int reg)
 {
 	u8 buf[2];
 
-	if (regmap_bulk_read(regmap, reg, buf, 2))
+	if (regmap_bulk_read(regmap, reg, buf, sizeof(buf)))
 		return -EIO;
 
 	/* stored in big-endian */
diff --git a/drivers/acpi/pmic/intel_pmic_xpower.c b/drivers/acpi/pmic/intel_pmic_xpower.c
index 61bbe4c24d87..33c5e85294cd 100644
--- a/drivers/acpi/pmic/intel_pmic_xpower.c
+++ b/drivers/acpi/pmic/intel_pmic_xpower.c
@@ -255,7 +255,7 @@  static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
 	if (ret)
 		return ret;
 
-	ret = regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2);
+	ret = regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, sizeof(buf));
 	if (ret == 0)
 		ret = (buf[0] << 4) + ((buf[1] >> 4) & 0x0f);