From: Colin Ian King <colin.king@canonical.com>
To: Daniel Palmer <daniel@0x0f.com>
Cc: Daniel Palmer <daniel@thingy.jp>,
Romain Perier <romain.perier@gmail.com>,
Alessandro Zummo <a.zummo@towertech.it>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Nobuhiro Iwamatsu <iwamatsu@nigauri.org>,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
linux-rtc@vger.kernel.org, kernel-janitors@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH][next] rtc: msc313: Fix unintentional sign extension issue on left shift of a u16
Date: Tue, 28 Sep 2021 14:34:49 +0100 [thread overview]
Message-ID: <8f21ec82-201d-efee-d1db-382a7885d38f@canonical.com> (raw)
In-Reply-To: <CAFr9PXnMXPmuaUnfr-VwaZDX1hY8ZDtp1+UxOau6DKpUP9FdzQ@mail.gmail.com>
On 28/09/2021 14:31, Daniel Palmer wrote:
> Hi Colin,
>
> On Tue, 28 Sept 2021 at 21:39, Colin King <colin.king@canonical.com> wrote:
>> Shifting the u16 value returned by readw by 16 bits to the left
>> will be promoted to a 32 bit signed int and then sign-extended
>> to an unsigned long. If the top bit of the readw is set then
>> the shifted value will be sign extended and the top 32 bits of
>> the result will be set.
>
> Ah,.. C is fun in all the wrong places. :)
> These chips are full of 32bit registers that are split into two 16
> registers 4 bytes apart when seen from the ARM CPU so we probably have
> this same mistake in a few other places.
>
> A similar pattern is used a bit later on in the same file to read the counter:
>
> seconds = readw(priv->rtc_base + REG_RTC_CNT_VAL_L)
> | (readw(priv->rtc_base + REG_RTC_CNT_VAL_H) << 16);
Ah, I missed that one! I'll send a V2.
>
> I guess it works at the moment because the top bit won't be set until 2038.
I hope to be retired by then, but I guess fixing it up before 2038 is a
good idea ;-)
>
> Thanks,
>
> Daniel
>
next prev parent reply other threads:[~2021-09-28 13:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-28 12:39 Colin King
2021-09-28 13:31 ` Daniel Palmer
2021-09-28 13:34 ` Colin Ian King [this message]
2021-09-28 13:54 ` Romain Perier
2021-09-29 12:56 ` Daniel Palmer
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=8f21ec82-201d-efee-d1db-382a7885d38f@canonical.com \
--to=colin.king@canonical.com \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@bootlin.com \
--cc=daniel@0x0f.com \
--cc=daniel@thingy.jp \
--cc=iwamatsu@nigauri.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=romain.perier@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®