git: 14980d69ff0f - main - i2c: Don't print uninitialized data when verbose
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 20 Sep 2024 15:58:13 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=14980d69ff0fce53cad8188b4d14fd30ad6b93c0
commit 14980d69ff0fce53cad8188b4d14fd30ad6b93c0
Author: John F. Carr <jfc@mit.edu>
AuthorDate: 2024-05-23 19:50:14 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-09-20 15:37:58 +0000
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
---
usr.sbin/i2c/i2c.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/usr.sbin/i2c/i2c.c b/usr.sbin/i2c/i2c.c
index 12155f1a0663..e4a780ba828f 100644
--- a/usr.sbin/i2c/i2c.c
+++ b/usr.sbin/i2c/i2c.c
@@ -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':