From 3a5d21649e7cdbcb03f91b9fb374966acede8a1e Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Fri, 26 Nov 2010 10:25:32 +0000 Subject: [PATCH] Use a 20-bit limit for the i2c bus number. Use snprintf for the i2c dev node name. Update copyright years. git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5885 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 8 ++++---- tools/i2cbusses.c | 13 +++++++------ tools/i2cbusses.h | 6 ++++-- tools/i2cdetect.c | 8 ++++---- tools/i2cdump.c | 4 ++-- tools/i2cget.c | 4 ++-- tools/i2cset.c | 4 ++-- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGES b/CHANGES index 8559fe2..64f8d70 100644 --- a/CHANGES +++ b/CHANGES @@ -16,11 +16,11 @@ SVN decode-xeon: Delete eepromer: Fix array initialization overrun i2cdetect: Drop legacy reference to ISA bus - Drop arbitrary limit on I2C bus number - i2cdump: Drop arbitrary limit on I2C bus number - i2cget: Drop arbitrary limit on I2C bus number + Increase limit on I2C bus number + i2cdump: Increase limit on I2C bus number + i2cget: Increase limit on I2C bus number i2cset: Add support for short writes with PEC - Drop arbitrary limit on I2C bus number + Increase limit on I2C bus number i2c-stub-from-dump: Use udev settle to speed up initialization Unload i2c-stub automatically if needed Add support for multiple dumps diff --git a/tools/i2cbusses.c b/tools/i2cbusses.c index f7f3a47..e36ee2d 100644 --- a/tools/i2cbusses.c +++ b/tools/i2cbusses.c @@ -4,7 +4,7 @@ devices. Copyright (c) 1999-2003 Frodo Looijaard and Mark D. Studebaker - Copyright (C) 2008 Jean Delvare + Copyright (C) 2008-2010 Jean Delvare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ MA 02110-1301 USA. */ -/* For strdup */ +/* For strdup and snprintf */ #define _BSD_SOURCE 1 #include @@ -67,7 +67,7 @@ static enum adt i2c_get_funcs(int i2cbus) char filename[20]; enum adt ret; - file = open_i2c_dev(i2cbus, filename, 1); + file = open_i2c_dev(i2cbus, filename, sizeof(filename), 1); if (file < 0) return adt_unknown; @@ -340,7 +340,7 @@ int lookup_i2c_bus(const char *i2cbus_arg) /* Not a number, maybe a name? */ return lookup_i2c_bus_by_name(i2cbus_arg); } - if (i2cbus > INT_MAX) { + if (i2cbus > 0xFFFFF) { fprintf(stderr, "Error: I2C bus out of range!\n"); return -2; } @@ -371,11 +371,12 @@ int parse_i2c_address(const char *address_arg) return address; } -int open_i2c_dev(const int i2cbus, char *filename, const int quiet) +int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet) { int file; - sprintf(filename, "/dev/i2c/%d", i2cbus); + snprintf(filename, size, "/dev/i2c/%d", i2cbus); + filename[size - 1] = '\0'; file = open(filename, O_RDWR); if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) { diff --git a/tools/i2cbusses.h b/tools/i2cbusses.h index b089887..b048b0d 100644 --- a/tools/i2cbusses.h +++ b/tools/i2cbusses.h @@ -1,7 +1,7 @@ /* i2cbusses.h - Part of the i2c-tools package - Copyright (C) 2004-2007 Jean Delvare + Copyright (C) 2004-2010 Jean Delvare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,6 +22,8 @@ #ifndef _I2CBUSSES_H #define _I2CBUSSES_H +#include + struct i2c_adap { int nr; char *name; @@ -34,7 +36,7 @@ void free_adapters(struct i2c_adap *adapters); int lookup_i2c_bus(const char *i2cbus_arg); int parse_i2c_address(const char *address_arg); -int open_i2c_dev(const int i2cbus, char *filename, const int quiet); +int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet); int set_slave_addr(int file, int address, int force); #define MISSING_FUNC_FMT "Error: Adapter does not have %s capability\n" diff --git a/tools/i2cdetect.c b/tools/i2cdetect.c index 38f5e94..fc90869 100644 --- a/tools/i2cdetect.c +++ b/tools/i2cdetect.c @@ -1,8 +1,8 @@ /* i2cdetect.c - a user-space program to scan for I2C devices - Copyright (C) 1999-2004 Frodo Looijaard , - Mark D. Studebaker and - Jean Delvare + Copyright (C) 1999-2004 Frodo Looijaard , and + Mark D. Studebaker + Copyright (C) 2004-2010 Jean Delvare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -295,7 +295,7 @@ int main(int argc, char *argv[]) exit(1); } - file = open_i2c_dev(i2cbus, filename, 0); + file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0); if (file < 0) { exit(1); } diff --git a/tools/i2cdump.c b/tools/i2cdump.c index 84b4bca..9ec7de0 100644 --- a/tools/i2cdump.c +++ b/tools/i2cdump.c @@ -2,7 +2,7 @@ i2cdump.c - a user-space program to dump I2C registers Copyright (C) 2002-2003 Frodo Looijaard , and Mark D. Studebaker - Copyright (C) 2004-2008 Jean Delvare + Copyright (C) 2004-2010 Jean Delvare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -259,7 +259,7 @@ int main(int argc, char *argv[]) } } - file = open_i2c_dev(i2cbus, filename, 0); + file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0); if (file < 0 || check_funcs(file, size, pec) || set_slave_addr(file, address, force)) diff --git a/tools/i2cget.c b/tools/i2cget.c index 32a68e5..350ccfd 100644 --- a/tools/i2cget.c +++ b/tools/i2cget.c @@ -1,6 +1,6 @@ /* i2cget.c - A user-space program to read an I2C register. - Copyright (C) 2005-2008 Jean Delvare + Copyright (C) 2005-2010 Jean Delvare Based on i2cset.c: Copyright (C) 2001-2003 Frodo Looijaard , and @@ -212,7 +212,7 @@ int main(int argc, char *argv[]) pec = argv[flags+4][1] == 'p'; } - file = open_i2c_dev(i2cbus, filename, 0); + file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0); if (file < 0 || check_funcs(file, size, daddress, pec) || set_slave_addr(file, address, force)) diff --git a/tools/i2cset.c b/tools/i2cset.c index ff32a3d..42319df 100644 --- a/tools/i2cset.c +++ b/tools/i2cset.c @@ -2,7 +2,7 @@ i2cset.c - A user-space program to write an I2C register. Copyright (C) 2001-2003 Frodo Looijaard , and Mark D. Studebaker - Copyright (C) 2004-2009 Jean Delvare + Copyright (C) 2004-2010 Jean Delvare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -236,7 +236,7 @@ int main(int argc, char *argv[]) help(); } - file = open_i2c_dev(i2cbus, filename, 0); + file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0); if (file < 0 || check_funcs(file, size, pec) || set_slave_addr(file, address, force))