From: Guenter Roeck <linux@roeck-us.net>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: clang-built-linux <clang-built-linux@googlegroups.com>,
jdelvare@suse.com, "Tomasz Paweł Gajc" <tpgxyz@gmail.com>,
"Nathan Chancellor" <natechancellor@gmail.com>,
"Henrik Rydberg" <rydberg@bitmath.org>,
linux-hwmon@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] hwmon: (applesmc) fix UB and udelay overflow
Date: Wed, 2 Oct 2019 18:17:40 -0700 [thread overview]
Message-ID: <bde955d5-bfd4-3e0c-ac45-b999ad1cc96b@roeck-us.net> (raw)
In-Reply-To: <CAKwvOdnG6tTHHx5aL8oA3ta_mW24aZ37JX+=HQ9YphearL4DOg@mail.gmail.com>
On 10/2/19 2:43 PM, Nick Desaulniers wrote:
> On Mon, Sep 30, 2019 at 5:01 PM Guenter Roeck <linux@roeck-us.net> wrote:
>>
>> Again, I fail to understand why waiting for a multiple of 20 seconds
>> under any circumstances would make any sense. Maybe the idea was
>> to divide us by 1000 before entering the second loop ?
>
> Yes, that's very clearly a mistake of mine.
>
>>
>> Looking into the code, there is no need to use udelay() in the first
>> place. It should be possible to replace the longer waits with
>> usleep_range(). Something like
>>
>> if (us < some_low_value) // eg. 0x80
>> delay(us)
>
> Did you mean udelay here?
>
Yes
>> else
>> usleep_range(us, us * 2);
>>
>> should do, and at the same time prevent the system from turning
>> into a space heater.
>
> The issue would persist with the above if udelay remains in a loop
> that gets fully unrolled. That's while I "peel" the loop into two
> loops over different ranges with different bodies.
>
Sorry, you lost me. If calls to udelay() with even small delay
parameters for some compiler-related reason no longer work, trying
to fix the problem with some odd driver code is most definitely not
a real solution.
> I think I should iterate in the first loop until the number of `us` is
> greater than 1000 (us per ms)(which is less of a magical constant and
> doesn't expose internal implementation details of udelay), then start
> the second loop (dividing us by 1000). What do you think, Guenter?
>
We should have no second loop, period.
Again, a hot delay loop of 128 ms (actually, more like 245 ms,
adding all delays together) is clearly wrong. Those udelay() calls
in the driver should really be replaced with usleep_range().
Guenter
prev parent reply other threads:[~2019-10-03 1:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-24 17:37 [PATCH] hwmon: (applesmc) fix UB and udelay overflow Nick Desaulniers
2019-09-24 17:42 ` Nick Desaulniers
2019-09-24 17:47 ` [PATCH v2] " Nick Desaulniers
2019-09-24 18:38 ` Nathan Chancellor
2019-09-24 19:36 ` Nick Desaulniers
2019-09-24 19:41 ` Nathan Chancellor
2019-09-30 21:46 ` Cengiz Can
2019-10-01 0:01 ` Guenter Roeck
2019-10-02 21:43 ` Nick Desaulniers
2019-10-03 1:17 ` Guenter Roeck [this message]
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=bde955d5-bfd4-3e0c-ac45-b999ad1cc96b@roeck-us.net \
--to=linux@roeck-us.net \
--cc=clang-built-linux@googlegroups.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--cc=rydberg@bitmath.org \
--cc=tpgxyz@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;
as well as URLs for NNTP newsgroup(s).