From: khali@linux-fr.org (Jean Delvare)
To: Marcelo Tosatti <marcelo.tosatti@cyclades.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
LM Sensors <sensors@Stimpy.netroedge.com>
Subject: [PATCH 2.4] i2c cleanups, third wave (5/8)
Date: Thu, 19 May 2005 06:24:34 +0000 [thread overview]
Message-ID: <20040111160444.660f1bdd.khali@linux-fr.org> (raw)
In-Reply-To: <20040111144214.7a6a4e59.khali@linux-fr.org>
This patch defines I2C_SMBUS_BLOCK_MAX and I2C_SMBUS_I2C_BLOCK_MAX,
those values were previously hardcoded in several places.
Part of the work was done by Ky?sti M?lkki. Original comment follows:
***
Message block size.
***
The patch also fixes an incorrect error message and a potential buffer
overrun.
diff -ru linux-2.4.25-pre4-k4/drivers/i2c/i2c-core.c linux-2.4.25-pre4-k5/drivers/i2c/i2c-core.c
--- linux-2.4.25-pre4-k4/drivers/i2c/i2c-core.c Sat Jan 10 20:27:50 2004
+++ linux-2.4.25-pre4-k5/drivers/i2c/i2c-core.c Sun Jan 11 10:33:12 2004
@@ -1062,8 +1062,8 @@
{
union i2c_smbus_data data;
int i;
- if (length > 32)
- length = 32;
+ if (length > I2C_SMBUS_BLOCK_MAX)
+ length = I2C_SMBUS_BLOCK_MAX;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
@@ -1077,8 +1077,8 @@
{
union i2c_smbus_data data;
int i;
- if (length > 32)
- length = 32;
+ if (length > I2C_SMBUS_I2C_BLOCK_MAX)
+ length = I2C_SMBUS_I2C_BLOCK_MAX;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
@@ -1152,10 +1152,10 @@
return -1;
} else {
msg[0].len = data->block[0] + 2;
- if (msg[0].len > 34) {
+ if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
printk(KERN_ERR "i2c-core.o: smbus_access called with "
"invalid block write size (%d)\n",
- msg[0].len);
+ data->block[0]);
return -1;
}
for (i = 1; i <= msg[0].len; i++)
diff -ru linux-2.4.25-pre4-k4/include/linux/i2c.h linux-2.4.25-pre4-k5/include/linux/i2c.h
--- linux-2.4.25-pre4-k4/include/linux/i2c.h Sat Jan 10 20:27:55 2004
+++ linux-2.4.25-pre4-k5/include/linux/i2c.h Sun Jan 11 10:46:48 2004
@@ -413,10 +413,13 @@
/*
* Data for SMBus Messages
*/
+#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
+#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
union i2c_smbus_data {
__u8 byte;
__u16 word;
- __u8 block[33]; /* block[0] is used for length */
+ __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
+ /* one more for read length in block process call */
};
/* smbus_access read or write markers */
--
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
WARNING: multiple messages have this Message-ID (diff)
From: Jean Delvare <khali@linux-fr.org>
To: Marcelo Tosatti <marcelo.tosatti@cyclades.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
LM Sensors <sensors@Stimpy.netroedge.com>
Subject: [PATCH 2.4] i2c cleanups, third wave (5/8)
Date: Sun, 11 Jan 2004 16:04:44 +0100 [thread overview]
Message-ID: <20040111160444.660f1bdd.khali@linux-fr.org> (raw)
In-Reply-To: <20040111144214.7a6a4e59.khali@linux-fr.org>
This patch defines I2C_SMBUS_BLOCK_MAX and I2C_SMBUS_I2C_BLOCK_MAX,
those values were previously hardcoded in several places.
Part of the work was done by Kyösti Mälkki. Original comment follows:
***
Message block size.
***
The patch also fixes an incorrect error message and a potential buffer
overrun.
diff -ru linux-2.4.25-pre4-k4/drivers/i2c/i2c-core.c linux-2.4.25-pre4-k5/drivers/i2c/i2c-core.c
--- linux-2.4.25-pre4-k4/drivers/i2c/i2c-core.c Sat Jan 10 20:27:50 2004
+++ linux-2.4.25-pre4-k5/drivers/i2c/i2c-core.c Sun Jan 11 10:33:12 2004
@@ -1062,8 +1062,8 @@
{
union i2c_smbus_data data;
int i;
- if (length > 32)
- length = 32;
+ if (length > I2C_SMBUS_BLOCK_MAX)
+ length = I2C_SMBUS_BLOCK_MAX;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
@@ -1077,8 +1077,8 @@
{
union i2c_smbus_data data;
int i;
- if (length > 32)
- length = 32;
+ if (length > I2C_SMBUS_I2C_BLOCK_MAX)
+ length = I2C_SMBUS_I2C_BLOCK_MAX;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
@@ -1152,10 +1152,10 @@
return -1;
} else {
msg[0].len = data->block[0] + 2;
- if (msg[0].len > 34) {
+ if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
printk(KERN_ERR "i2c-core.o: smbus_access called with "
"invalid block write size (%d)\n",
- msg[0].len);
+ data->block[0]);
return -1;
}
for (i = 1; i <= msg[0].len; i++)
diff -ru linux-2.4.25-pre4-k4/include/linux/i2c.h linux-2.4.25-pre4-k5/include/linux/i2c.h
--- linux-2.4.25-pre4-k4/include/linux/i2c.h Sat Jan 10 20:27:55 2004
+++ linux-2.4.25-pre4-k5/include/linux/i2c.h Sun Jan 11 10:46:48 2004
@@ -413,10 +413,13 @@
/*
* Data for SMBus Messages
*/
+#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
+#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
union i2c_smbus_data {
__u8 byte;
__u16 word;
- __u8 block[33]; /* block[0] is used for length */
+ __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
+ /* one more for read length in block process call */
};
/* smbus_access read or write markers */
--
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
next prev parent reply other threads:[~2005-05-19 6:24 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-11 13:42 [PATCH 2.4] i2c cleanups, third wave Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-11 13:51 ` [PATCH 2.4] i2c cleanups, third wave (1/8) Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-11 13:59 ` [PATCH 2.4] i2c cleanups, third wave (2/8) Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-11 14:08 ` [PATCH 2.4] i2c cleanups, third wave (3/8) Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-11 14:50 ` [PATCH 2.4] i2c cleanups, third wave (4/8) Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2005-05-19 6:24 ` Marcelo Tosatti
2005-05-19 6:24 ` Jean Delvare
2004-01-11 15:04 ` Jean Delvare [this message]
2005-05-19 6:24 ` [PATCH 2.4] i2c cleanups, third wave (5/8) Jean Delvare
2004-01-11 15:10 ` [PATCH 2.4] i2c cleanups, third wave (6/8) Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-11 15:20 ` [PATCH 2.4] i2c cleanups, third wave (7/8) Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-11 15:28 ` [PATCH 2.4] i2c cleanups, third wave (8/8) Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-12 1:48 ` [PATCH 2.4] i2c cleanups, third wave Mike Fedyk
2005-05-19 6:24 ` Mike Fedyk
2004-01-14 18:30 ` Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2004-01-14 12:55 ` Marcelo Tosatti
2005-05-19 6:24 ` Marcelo Tosatti
2004-01-14 14:55 ` Jean Delvare
2005-05-19 6:24 ` Jean Delvare
2005-05-19 6:24 ` Mark M. Hoffman
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=20040111160444.660f1bdd.khali@linux-fr.org \
--to=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.tosatti@cyclades.com \
--cc=sensors@Stimpy.netroedge.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.