The branch main has been updated by jhb:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=c6eb9f16cf0e19b54b382aa44f0c9a7bcec5fc40

commit c6eb9f16cf0e19b54b382aa44f0c9a7bcec5fc40
Author:     John Baldwin <[email protected]>
AuthorDate: 2026-06-23 15:51:43 +0000
Commit:     John Baldwin <[email protected]>
CommitDate: 2026-06-23 15:51:43 +0000

    pciconf: Minor cleanups in the config register methods
    
    This is mostly to provide cleaner code for future changes to copy
    from.
    
    - Use NULL instead of casting 0 to pointer types.
    
    - Inline readone() in the sole caller now that it is just a single line.
    
    - Use a helper variable for the count of items on each line of output
      in readit().
    
    - Fix the double space in the middle of byte output to only trigger
      for width 1.  For other widths it would output spurious spaces at
      the end of the line which doesn't really hurt, but is buggy
      nonetheless.
    
    - Avoid using implicit booleans by explicitly comparing integer
      expressions against zero.
    
    - Don't compare the endptr returned from strtol() against NULL.
    
    Differential Revision:  https://reviews.freebsd.org/D57535
---
 usr.sbin/pciconf/pciconf.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/usr.sbin/pciconf/pciconf.c b/usr.sbin/pciconf/pciconf.c
index 7da8aeadae93..e2a3beeba6f7 100644
--- a/usr.sbin/pciconf/pciconf.c
+++ b/usr.sbin/pciconf/pciconf.c
@@ -1289,13 +1289,6 @@ getsel(const char *str)
                return (parsesel(str));
 }
 
-static void
-readone(int fd, struct pcisel *sel, long reg, int width)
-{
-
-       printf("%0*x", width*2, read_config(fd, sel, reg, width));
-}
-
 static void
 readit(const char *name, const char *reg, int width)
 {
@@ -1303,7 +1296,7 @@ readit(const char *name, const char *reg, int width)
        long rend;
        long r;
        char *end;
-       int i;
+       int i, items_per_line;
        int fd;
        struct pcisel sel;
 
@@ -1312,18 +1305,22 @@ readit(const char *name, const char *reg, int width)
                err(1, "%s", _PATH_DEVPCI);
 
        rend = rstart = strtol(reg, &end, 0);
-       if (end && *end == ':') {
+       if (*end == ':') {
                end++;
-               rend = strtol(end, (char **) 0, 0);
+               rend = strtol(end, NULL, 0);
        }
        sel = getsel(name);
+       items_per_line = 16 / width;
        for (i = 1, r = rstart; r <= rend; i++, r += width) {
-               readone(fd, &sel, r, width);
-               if (i && !(i % 8))
+               printf("%0*x", width * 2, read_config(fd, &sel, r, width));
+
+               /* Use a double space in the middle when outputting bytes. */
+               if (width == 1 && i % 16 == 8)
                        putchar(' ');
-               putchar(i % (16/width) ? ' ' : '\n');
+
+               putchar(i % items_per_line == 0 ? '\n' : ' ');
        }
-       if (i % (16/width) != 1)
+       if (i % items_per_line != 1)
                putchar('\n');
        close(fd);
 }
@@ -1335,9 +1332,9 @@ writeit(const char *name, const char *reg, const char 
*data, int width)
        struct pci_io pi;
 
        pi.pi_sel = getsel(name);
-       pi.pi_reg = strtoul(reg, (char **)0, 0); /* XXX error check */
+       pi.pi_reg = strtoul(reg, NULL, 0); /* XXX error check */
        pi.pi_width = width;
-       pi.pi_data = strtoul(data, (char **)0, 0); /* XXX error check */
+       pi.pi_data = strtoul(data, NULL, 0); /* XXX error check */
 
        fd = open(_PATH_DEVPCI, O_RDWR, 0);
        if (fd < 0)

Reply via email to