The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Eric Piel <eric.piel@tremplin-utc.net>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: [PATCH] lis3lv02d: Avoid zero-division
Date: Thu, 03 Nov 2011 13:09:00 +0100	[thread overview]
Message-ID: <s5hy5vx9zmr.wl%tiwai@suse.de> (raw)

In some weird situation, HP DriveGuard chip can't read ODR value
correctly, and it results in a zero-division Oops in lis3lv02d driver.
This patch fixes the Oops by checking the value appopriately, and skips
if any weird value is read.

Cc: <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/misc/lis3lv02d/lis3lv02d.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
index 8b51cd6..c4eb2f3 100644
--- a/drivers/misc/lis3lv02d/lis3lv02d.c
+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
@@ -228,6 +228,14 @@ static int lis3lv02d_set_odr(int rate)
 	return -EINVAL;
 }
 
+static void lis3lv02d_power_delay(struct lis3lv02d *lis3)
+{
+	int odr = lis3lv02d_get_odr();
+	if (odr <= 0)
+		return;
+	msleep(lis3->pwron_delay / odr);
+}
+
 static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
 {
 	u8 ctlreg, reg;
@@ -266,7 +274,7 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
 
 	lis3->read(lis3, ctlreg, &reg);
 	lis3->write(lis3, ctlreg, (reg | selftest));
-	msleep(lis3->pwron_delay / lis3lv02d_get_odr());
+	lis3lv02d_power_delay(lis3);
 
 	/* Read directly to avoid axis remap */
 	x = lis3->read_data(lis3, OUTX);
@@ -275,7 +283,7 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
 
 	/* back to normal settings */
 	lis3->write(lis3, ctlreg, reg);
-	msleep(lis3->pwron_delay / lis3lv02d_get_odr());
+	lis3lv02d_power_delay(lis3);
 
 	results[0] = x - lis3->read_data(lis3, OUTX);
 	results[1] = y - lis3->read_data(lis3, OUTY);
@@ -385,7 +393,7 @@ void lis3lv02d_poweron(struct lis3lv02d *lis3)
 	}
 
 	/* LIS3 power on delay is quite long */
-	msleep(lis3->pwron_delay / lis3lv02d_get_odr());
+	lis3lv02d_power_delay(lis3);
 
 	if (lis3->reg_ctrl)
 		lis3_context_restore(lis3);
-- 
1.7.7


             reply	other threads:[~2011-11-03 12:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-03 12:09 Takashi Iwai [this message]
2011-11-08  3:57 ` [PATCH] lis3lv02d: Avoid zero-division Éric Piel
2011-11-08  6:19   ` Takashi Iwai
2011-11-11 18:11     ` Éric Piel
2011-11-14 14:59       ` Takashi Iwai

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=s5hy5vx9zmr.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=eric.piel@tremplin-utc.net \
    --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