From: Esben Haabendal <esben@geanix.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] rtc: isl12022: Add alarm support
Date: Wed, 11 Sep 2024 12:53:31 +0200 [thread overview]
Message-ID: <87h6am7978.fsf@geanix.com> (raw)
In-Reply-To: <871q1qimah.fsf@prevas.dk> (Rasmus Villemoes's message of "Wed, 11 Sep 2024 11:15:18 +0200")
Rasmus Villemoes <linux@rasmusvillemoes.dk> writes:
> Esben Haabendal <esben@geanix.com> writes:
>
>> Rasmus Villemoes <linux@rasmusvillemoes.dk> writes:
>>
>>> Esben Haabendal <esben@geanix.com> writes:
>>>
>
>>>> + struct isl12022 *isl12022 = dev_get_drvdata(dev);
>>>> + struct regmap *regmap = isl12022->regmap;
>>>> + uint8_t buf[ISL12022_ALARM_SECTION_LEN];
>>>
>>> The kernel normally says u8 (and you do as well in _set_alarm()).
>>
>> Another copy-paste issue. This time it was from _read_time() and
>> _set_time().
>>
>> To avoid inconsistent coding style, I guess I should add a commit
>> changing to u8 in _read_time() and _set_time() as well.
>>
>
> Ah, hadn't noticed that. Yes, please fix that up while in here.
Done.
>>>> + int ret, yr, i;
>>>> +
>>>> + ret = regmap_bulk_read(regmap, ISL12022_ALARM_SECTION,
>>>> + buf, sizeof(buf));
>>>> + if (ret) {
>>>> + dev_err(dev, "%s: reading ALARM registers failed\n",
>>>> + __func__);
>>>> + return ret;
>>>> + }
>>>> +
>>>> + dev_dbg(dev,
>>>> + "%s: sc=%02x, mn=%02x, hr=%02x, dt=%02x, mo=%02x, dw=%02x\n",
>>>> + __func__, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
>>>> +
>>>> + tm->tm_sec = bcd2bin(buf[ISL12022_REG_SCA0 - ISL12022_ALARM_SECTION]
>>>> + & 0x7F);
>>>> + tm->tm_min = bcd2bin(buf[ISL12022_REG_MNA0 - ISL12022_ALARM_SECTION]
>>>> + & 0x7F);
>>>> + tm->tm_hour = bcd2bin(buf[ISL12022_REG_HRA0 - ISL12022_ALARM_SECTION]
>>>> + & 0x3F);
>>>> + tm->tm_mday = bcd2bin(buf[ISL12022_REG_DTA0 - ISL12022_ALARM_SECTION]
>>>> + & 0x3F);
>>>> + tm->tm_mon = bcd2bin(buf[ISL12022_REG_MOA0 - ISL12022_ALARM_SECTION]
>>>> + & 0x1F) - 1;
>>>> + tm->tm_wday = buf[ISL12022_REG_DWA0 - ISL12022_ALARM_SECTION] & 0x07;
>>>> +
>>>
>>> Here I'd also suggest keeping each assignment on one line, it's rather
>>> hard to read this way.
>>
>> I agree, and I will change it here. But if the 80 columns rule is out,
>> what kind of rule for line width is used instead?
>
> See commit bdc48fa11e and the current wording in coding-style.rst. In
> particular I think
>
> +Statements longer than 80 columns should be broken into sensible chunks,
> +unless exceeding 80 columns significantly increases readability and does
> +not hide information.
>
> applies here. I'd even say you could use spaces to align the = and &
> operators (that is, make it '->tm_min = ' and '->tm_hour = ').
>
> So the 80 char limit is still there, just not as strongly enforced as it
> used to, and once you hit 100, there has to be really strong reasons for
> exceeding that. But 85 for avoiding putting '& 0x7F); on its own line?
> Absolutely, do it.
Got it.
>>>> +
>>>> + /* Set non-matching tm_wday to safeguard against early false matching
>>>> + * while setting all the alarm registers (this rtc lacks a general
>>>> + * alarm/irq enable/disable bit).
>>>> + */
>>>
>>> Nit: Don't use network comment style.
>>
>> Ok. I did not know this was network comment style only.
>> So it should be with both '/*' and '*/' on separate lines?
>
> Yes. I wanted to point you at the coding-style part which explains the
> different preferred style for net/ and drivers/net, but then it turns
> out I couldn't because 82b8000c28. Also, see
> https://lore.kernel.org/lkml/CA+55aFyQYJerovMsSoSKS7PessZBr4vNp-3QUUwhqk4A4_jcbg@mail.gmail.com/ .
Haha. You are so out of touch :D
I have changed to the normal kernel style.
>>>> + /* write ALARM registers */
>>>> + ret = regmap_bulk_write(regmap, ISL12022_REG_SCA0,
>>>> + ®s, sizeof(regs));
>>>
>>> Nit: Fits in one line (I think), and you probably want to use the
>>> ISL12022_ALARM_SECTION name here, even if they're of course the same.
>>
>> Using ISL12022_ALARM_SECTION makes the line 85 columns. I must admit I
>> feel a bit uneasy about going over the 80 columns, as I have no idea
>> when to wrap the lines then...
>
> As for the name used, you should at least use the same in all the
> regmap_bulk_*() calls. If you don't want to hardcode that SCA0 is the
> first and thus have a name for the whole region, you could make that
> name a little shorter (_ALARM_REGS maybe?).
I am changing it to _ALARM and _ALARM_LEN. It definitely makes the code
more readable IMHO.
> I think vertical real estate is much more precious than horizontal, so
> I'd prefer to have this be
>
> ret = regmap_bulk_write(regmap, ISL12022_ALARM_SECTION, ®s, sizeof(regs));
>
> regardless of line length (as long as it's not crazy), because then I
> can see more context.
With _ALARM, it even fits within 80 columns.
>>> I see why you do the ! and !! dances to canonicalize boolean values for
>>> comparison, but it's not very pretty. But ->alarm_irq_enable has the
>>> signature it has (that should probably get changed), so to be safe I
>>> guess you do need them. That said, I don't think it's unreasonable to
>>> assume that ->alarm_irq_enable is only ever invoked with the values 0
>>> and 1 for the enabled argument, and e.g. rtc-cpcap.c gets away with that
>>> assumption.
>>
>> The handling in rtc-cpcap.c looks a bit strange IMHO. The comparison is
>> without using !, and then the assignment is done with !!. I think we
>> should either rely on enabled always being either 0 or 1, or handle the
>> cases where it might be something else.
>>
>> I prefer to play it safe for now.
>>
>> But if I explicitly do this first
>>
>> /* Make sure enabled is 0 or 1 */
>> enabled = !!enabled;
>>
>> Then we can leave out the ! and !! below. The code should be more
>> readable, and it will be much clearer for anyone that later on will want
>> to get rid of this.
>
> Yes, that's a good compromise.
Ok, then I am waiting for clarification from Alexandre on how to change
_setup_irq() before sending out v2.
/Esben
next prev parent reply other threads:[~2024-09-11 10:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 10:27 [PATCH 0/2] rtc: isl12022: Add alarm support Esben Haabendal
2024-09-10 10:27 ` [PATCH 1/2] rtc: isl12022: Prepare for extending rtc device drvdata Esben Haabendal
2024-09-10 17:32 ` Rasmus Villemoes
2024-09-10 10:27 ` [PATCH 2/2] rtc: isl12022: Add alarm support Esben Haabendal
2024-09-10 19:13 ` Rasmus Villemoes
2024-09-11 8:11 ` Esben Haabendal
2024-09-11 9:15 ` Rasmus Villemoes
2024-09-11 10:53 ` Esben Haabendal [this message]
2024-09-10 19:39 ` Alexandre Belloni
2024-09-11 8:20 ` Esben Haabendal
2024-09-11 12:24 ` Alexandre Belloni
2024-09-12 7:09 ` Esben Haabendal
2024-09-12 8:21 ` Alexandre Belloni
2024-09-12 8:59 ` Esben Haabendal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h6am7978.fsf@geanix.com \
--to=esben@geanix.com \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.