linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <w.sang@pengutronix.de>
To: devicetree-discuss@ozlabs.org
Cc: linuxppc-dev@ozlabs.org
Subject: [PATCH 2/3] misc: at24: add more sanity checks for parameters
Date: Wed, 17 Nov 2010 13:00:49 +0100	[thread overview]
Message-ID: <1289995250-17927-3-git-send-email-w.sang@pengutronix.de> (raw)
In-Reply-To: <1289995250-17927-1-git-send-email-w.sang@pengutronix.de>

Side-effects happen when passing 0 to either io_limit or page_size. Give
an error in case of this misconfiguration.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/misc/eeprom/at24.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 3a53efc..ab1ad41 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -517,6 +517,11 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	if (!is_power_of_2(chip.byte_len))
 		dev_warn(&client->dev,
 			"byte_len looks suspicious (no power of 2)!\n");
+	if (!chip.page_size) {
+		dev_err(&client->dev, "page_size must not be 0!\n");
+		err = -EINVAL;
+		goto err_out;
+	}
 	if (!is_power_of_2(chip.page_size))
 		dev_warn(&client->dev,
 			"page_size looks suspicious (no power of 2)!\n");
@@ -681,6 +686,11 @@ static struct i2c_driver at24_driver = {
 
 static int __init at24_init(void)
 {
+	if (!io_limit) {
+		pr_err("at24: io_limit must not be 0!\n");
+		return -EINVAL;
+	}
+
 	io_limit = rounddown_pow_of_two(io_limit);
 	return i2c_add_driver(&at24_driver);
 }
-- 
1.7.2.3

  parent reply	other threads:[~2010-11-17 12:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-17 12:00 [PATCH V2 0/3] at24: parse OF-data Wolfram Sang
2010-11-17 12:00 ` [PATCH 1/3] misc: at24: parse OF-data, too Wolfram Sang
2010-11-20 10:54   ` Stijn Devriendt
2010-11-20 12:42     ` Wolfram Sang
2010-11-20 14:07       ` Stijn Devriendt
2010-11-22 16:48       ` Stijn Devriendt
2010-12-24  9:15   ` Grant Likely
2010-11-17 12:00 ` Wolfram Sang [this message]
2010-12-24  9:15   ` [PATCH 2/3] misc: at24: add more sanity checks for parameters Grant Likely
2010-11-17 12:00 ` [PATCH 3/3] powerpc: pcm030/032: add pagesize to dts Wolfram Sang
2010-12-24  9:15   ` Grant Likely

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=1289995250-17927-3-git-send-email-w.sang@pengutronix.de \
    --to=w.sang@pengutronix.de \
    --cc=devicetree-discuss@ozlabs.org \
    --cc=linuxppc-dev@ozlabs.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;
as well as URLs for NNTP newsgroup(s).