[PATCH 1/2] i2c: Fix barebox crash when 'count' is not set for i2c_read command

Alexander Shiyan shc_work at mail.ru
Fri May 11 16:17:07 EDT 2012


Running i2c_read without the 'count' setting causes an error and reboots.

barebox at Phytec phyCORE-i.MX27:/ i2c_read -b 1 -a 0x4a -r 0x00
ERROR: out of memory
no stack data available

Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 commands/i2c.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index b3d09dc..39bae35 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -170,7 +170,7 @@ static int do_i2c_read(int argc, char *argv[])
 		}
 	}
 
-	if ((addr < 0) || (reg < 0) || (count == 0) || (addr > 0x7F))
+	if ((addr < 0) || (reg < 0) || (count < 1) || (addr > 0x7F))
 		return COMMAND_ERROR_USAGE;
 
 	adapter = i2c_get_adapter(bus);
-- 
1.7.3.4




More information about the barebox mailing list