aboutsummaryrefslogtreecommitdiff
path: root/miscutils/i2c_tools.c
diff options
context:
space:
mode:
authorJames Byrne <james.byrne@origamienergy.com>2019-07-02 11:35:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /miscutils/i2c_tools.c
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/i2c_tools.c')
-rw-r--r--miscutils/i2c_tools.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index 7a2e8534a..82a559f74 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -344,7 +344,7 @@ static void get_funcs_matrix(int fd, unsigned long *funcs)
static void check_funcs_test_end(int funcs, int pec, const char *err)
{
if (pec && !(funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C)))
- bb_error_msg("warning: adapter does not support PEC");
+ bb_simple_error_msg("warning: adapter does not support PEC");
if (err)
bb_error_msg_and_die(
@@ -392,7 +392,7 @@ static void check_read_funcs(int fd, int mode, int data_addr, int pec)
break;
#endif /* ENABLE_I2CDUMP */
default:
- bb_error_msg_and_die("internal error");
+ bb_simple_error_msg_and_die("internal error");
}
check_funcs_test_end(funcs, pec, err);
}
@@ -438,7 +438,7 @@ static void confirm_or_abort(void)
{
fprintf(stderr, "Continue? [y/N] ");
if (!bb_ask_y_confirmation())
- bb_error_msg_and_die("aborting");
+ bb_simple_error_msg_and_die("aborting");
}
/*
@@ -449,20 +449,20 @@ static void confirm_or_abort(void)
*/
static void confirm_action(int bus_addr, int mode, int data_addr, int pec)
{
- bb_error_msg("WARNING! This program can confuse your I2C bus");
+ bb_simple_error_msg("WARNING! This program can confuse your I2C bus");
/* Don't let the user break his/her EEPROMs */
if (bus_addr >= 0x50 && bus_addr <= 0x57 && pec) {
- bb_error_msg_and_die("this is I2C not smbus - using PEC on I2C "
+ bb_simple_error_msg_and_die("this is I2C not smbus - using PEC on I2C "
"devices may result in data loss, aborting");
}
if (mode == I2C_SMBUS_BYTE && data_addr >= 0 && pec)
- bb_error_msg("WARNING! May interpret a write byte command "
+ bb_simple_error_msg("WARNING! May interpret a write byte command "
"with PEC as a write byte data command");
if (pec)
- bb_error_msg("PEC checking enabled");
+ bb_simple_error_msg("PEC checking enabled");
confirm_or_abort();
}
@@ -507,7 +507,7 @@ int i2cget_main(int argc UNUSED_PARAM, char **argv)
case 'w': mode = I2C_SMBUS_WORD_DATA; break;
case 'c': mode = I2C_SMBUS_BYTE; break;
default:
- bb_error_msg("invalid mode");
+ bb_simple_error_msg("invalid mode");
bb_show_usage();
}
pec = argv[3][1] == 'p';
@@ -529,7 +529,7 @@ int i2cget_main(int argc UNUSED_PARAM, char **argv)
if (data_addr >= 0) {
status = i2c_smbus_write_byte(fd, data_addr);
if (status < 0)
- bb_error_msg("warning - write failed");
+ bb_simple_error_msg("warning - write failed");
}
status = i2c_smbus_read_byte(fd);
break;
@@ -542,7 +542,7 @@ int i2cget_main(int argc UNUSED_PARAM, char **argv)
close(fd);
if (status < 0)
- bb_perror_msg_and_die("read failed");
+ bb_simple_perror_msg_and_die("read failed");
printf("0x%0*x\n", mode == I2C_SMBUS_WORD_DATA ? 4 : 2, status);
@@ -611,7 +611,7 @@ int i2cset_main(int argc, char **argv)
case 'i': mode = I2C_SMBUS_I2C_BLOCK_DATA;
break;
default:
- bb_error_msg("invalid mode");
+ bb_simple_error_msg("invalid mode");
bb_show_usage();
}
@@ -620,11 +620,11 @@ int i2cset_main(int argc, char **argv)
|| mode == I2C_SMBUS_I2C_BLOCK_DATA
) {
if (pec && mode == I2C_SMBUS_I2C_BLOCK_DATA)
- bb_error_msg_and_die(
+ bb_simple_error_msg_and_die(
"PEC not supported for I2C "
"block writes");
if (opts & opt_m)
- bb_error_msg_and_die(
+ bb_simple_error_msg_and_die(
"mask not supported for block "
"writes");
}
@@ -685,7 +685,7 @@ int i2cset_main(int argc, char **argv)
}
if (tmpval < 0)
- bb_perror_msg_and_die("can't read old value");
+ bb_simple_perror_msg_and_die("can't read old value");
val = (val & mask) | (tmpval & ~mask);
@@ -724,7 +724,7 @@ int i2cset_main(int argc, char **argv)
break;
}
if (status < 0)
- bb_perror_msg_and_die("write failed");
+ bb_simple_perror_msg_and_die("write failed");
if (pec)
i2c_set_pec(fd, 0); /* Clear PEC. */
@@ -978,12 +978,12 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv)
case 's': mode = I2C_SMBUS_BLOCK_DATA; break;
case 'i': mode = I2C_SMBUS_I2C_BLOCK_DATA; break;
default:
- bb_error_msg_and_die("invalid mode");
+ bb_simple_error_msg_and_die("invalid mode");
}
if (argv[2][1] == 'p') {
if (argv[2][0] == 'W' || argv[2][0] == 'i') {
- bb_error_msg_and_die(
+ bb_simple_error_msg_and_die(
"pec not supported for -W and -i");
} else {
pec = 1;
@@ -994,7 +994,7 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv)
if (opts & opt_r) {
first = strtol(opt_r_str, &dash, 0);
if (dash == opt_r_str || *dash != '-' || first > 0xff)
- bb_error_msg_and_die("invalid range");
+ bb_simple_error_msg_and_die("invalid range");
last = xstrtou_range(++dash, 0, first, 0xff);
/* Range is not available for every mode. */
@@ -1007,7 +1007,7 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv)
break;
/* Fall through */
default:
- bb_error_msg_and_die(
+ bb_simple_error_msg_and_die(
"range not compatible with selected mode");
}
}
@@ -1032,7 +1032,7 @@ int i2cdump_main(int argc UNUSED_PARAM, char **argv)
if (mode == I2C_SMBUS_BYTE) {
res = i2c_smbus_write_byte(fd, first);
if (res < 0)
- bb_perror_msg_and_die("write start address");
+ bb_simple_perror_msg_and_die("write start address");
}
dump_data(fd, mode, first, last, block, blen);
@@ -1398,7 +1398,7 @@ static void check_i2c_func(int fd)
get_funcs_matrix(fd, &funcs);
if (!(funcs & I2C_FUNC_I2C))
- bb_error_msg_and_die("adapter does not support I2C transfers");
+ bb_simple_error_msg_and_die("adapter does not support I2C transfers");
}
//usage:#define i2ctransfer_trivial_usage
@@ -1451,7 +1451,7 @@ int i2ctransfer_main(int argc UNUSED_PARAM, char **argv)
char *end;
if (nmsgs >= I2C_RDWR_IOCTL_MAX_MSGS)
- bb_error_msg_and_die("too many messages, max: "I2C_RDWR_IOCTL_MAX_MSGS_STR);
+ bb_simple_error_msg_and_die("too many messages, max: "I2C_RDWR_IOCTL_MAX_MSGS_STR);
flags = 0;
arg_ptr = *argv;