i2c: Don't print uninitialized data when verbose

i2c -sv or i2c -rv prints an uninitialized field i2c_opt.addr.
Suppress the verbose message entirely for scan and reset,
where it provides no information, and zero initialize the field.

See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279261

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1345
This commit is contained in:
John F. Carr 2024-05-23 15:50:14 -04:00 committed by Warner Losh
parent 6e45b50342
commit 14980d69ff

View File

@ -751,6 +751,7 @@ main(int argc, char** argv)
/* Default values */
i2c_opt.off = 0;
i2c_opt.addr = 0;
i2c_opt.verbose = 0;
i2c_opt.dir = 'r'; /* direction = read */
i2c_opt.width = "8";
@ -875,12 +876,6 @@ main(int argc, char** argv)
return(EX_USAGE);
}
if (i2c_opt.verbose)
fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, "
"offset: 0x%02x, width: %s, count: %u\n", dev,
i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off,
i2c_opt.width, i2c_opt.count);
fd = open(dev, O_RDWR);
if (fd == -1) {
fprintf(stderr, "Error opening I2C controller (%s): %s\n",
@ -890,6 +885,11 @@ main(int argc, char** argv)
switch (do_what) {
case 'a':
if (i2c_opt.verbose)
fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, "
"offset: 0x%02x, width: %s, count: %u\n", dev,
i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off,
i2c_opt.width, i2c_opt.count);
error = access_bus(fd, i2c_opt);
break;
case 's':