Re: [PATCH v3 4/8] rtc: isl12022: add support for trip level DT binding

From: Rasmus Villemoes
Date: Mon Jun 19 2023 - 03:27:32 EST


On 15/06/2023 13.11, Andy Shevchenko wrote:
> On Thu, Jun 15, 2023 at 12:58:22PM +0200, Rasmus Villemoes wrote:

>> +static void isl12022_set_trip_levels(struct device *dev)
>> +{
>> + struct regmap *regmap = dev_get_drvdata(dev);
>> + u32 levels[2] = {0, 0};
>
> A nit, 0, 0 is not needed, {} will do the job.

So? I'm not code-golfing, and here I really want to initialize to 0 (or
any value lower than the first entries in the trip_levels[] arrays so
that, lacking the DT property, the code ends up using what are the chip
reset defaults).

>> + int ret, i, j, x[2];
>> + u8 val, mask;
>
> BUILD_BUG_ON(ARRAY_SIZE(x) != ARRAY_SIZE(levels)) ?

BUILD_BUG_ON doesn't make sense when these things are declared within a
few lines of each other _and_ since they're sized based on properties of
the hardware we're dealing with, nobody would ever have a reason to
change either. So no, that would IMO make it harder to read, because one
would stop and think "why is this obvious thing asserted?".

>> + device_property_read_u32_array(dev, "isil,battery-trip-levels-microvolt",
>> + levels, 2);
>
> A nit, ARRAY_SIZE(levels) ?
>
>> + for (i = 0; i < 2; i++) {
>
> ARRAY_SIZE(x) ?

I considered that, but really didn't think it improved readability. I'll
defer to Alexandre on whether to change this.

Rasmus