From: "Éric Piel" <Eric.Piel@tremplin-utc.net>
To: Christian Lamparter <chunkeey@googlemail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC v2] lis3lv02d: avoid divide by zero due to unchecked register read
Date: Tue, 17 May 2011 23:46:00 +0200 [thread overview]
Message-ID: <4DD2EC98.5080901@tremplin-utc.net> (raw)
In-Reply-To: <201105162336.05306.chunkeey@googlemail.com>
Op 16-05-11 23:36, Christian Lamparter schreef:
> On Monday 16 May 2011 13:16:46 Éric Piel wrote:
>> Op 16-05-11 00:46, Christian Lamparter schreef:
>>> From my POV, it looks like the hardware is not working as expected
>>> and returns a bogus data rate. The driver doesn't check the result
>>> and directly uses it as some sort of divisor in some places:
>>>
>>> msleep(lis3->pwron_delay / lis3lv02d_get_odr());
>>>
>>> Under this circumstances, this could very well cause the
>>> "divide by zero" exception from above.
>>>
>> However, I'd fix it a bit differently: let lis3lv02d_get_odr() return
>> the raw data, and create a special function
>> lis3lv02d_get_pwron_delay_ms() which does the "lis3->pwron_delay /
>> lis3lv02d_get_odr()" with special handling for 0 (returning a large
>> value and also sending a printk_once() ).
> Do you know how "volatile" this data rate is? If it never changes
> [at least it doesn't here?] then why not read it once in init_device
> and store it in the device context?
It is not normally changing, normally it is set just at init/unsuspend
(where the bios can also interfere sometimes) and when the user changes
it. So definitely within the same function it's not going to suddenly
change. We could avoid calculating/checking it twice in
lis3lv02d_selftest(). Care to do a third version with this little clean up?
>
> Anyway, I updated the code... But instead of returning a "large value"
> I went for the -ENXIO to bail-out early, so now we won't continue if
> something went bad [after resume for instance?].
Sounds even better than using a conservative value!
>
>> As you have noted, we might want to check other parts of the driver to
>> validate the data from the device. So far, all the code considers that
>> the device is flawless :-S
> well:
> CHECK drivers/misc/lis3lv02d/lis3lv02d.c
> drivers/misc/lis3lv02d/lis3lv02d.c:170:52: warning: cast to restricted __le16
This is not introduced by your patch, right? So it's fine for now :-)
Thanks,
Eric
next prev parent reply other threads:[~2011-05-17 21:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-15 22:46 [PATCH] lis3lv02d: avoid divide by zero due to unchecked register read Christian Lamparter
2011-05-16 11:16 ` Éric Piel
2011-05-16 21:36 ` [RFC v2] " Christian Lamparter
2011-05-17 21:46 ` Éric Piel [this message]
2011-05-18 15:47 ` Christian Lamparter
2011-05-18 15:56 ` Éric Piel
2011-05-18 16:03 ` Christian Lamparter
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=4DD2EC98.5080901@tremplin-utc.net \
--to=eric.piel@tremplin-utc.net \
--cc=chunkeey@googlemail.com \
--cc=linux-kernel@vger.kernel.org \
/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