From nobody Tue Jun 23 15:51:51 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gl8h748RYz6hdW2 for ; Tue, 23 Jun 2026 15:51:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gl8h733ldz3DnD for ; Tue, 23 Jun 2026 15:51:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782229911; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0JZHVBNoBslnPKAysrAdyktTtu4LszLFNOHuLMPkKVs=; b=OiOnwMstfin4w1Le30UgSaFQRsrWS9z9QERJl/h4VFj0/5Goo1IwUX1yjJ6/wP2mZGgXVE wezpNCC05guDMdjbLhVrtefSOxVp+e9fTVis2+AJ9cBR/qu0vyUhWMHccEtArmv1vgwCeV 1ZHEBSaACG8mD1bS8bl2ZQjxBqwLYbRtQGleS/2hGfPp/gdfIopfHeZ6aIjfqvo6j3jEFM 9dqHtAR7Wx6NJ8NXAzhbNrMrti8n/AQF8/k6H9GlaB0PqYXdSk2uVOiNkzQa0jpk4uxXtz zs0lTlH/Q6qtc0F9XnN4nRL/1SLuAIIG6v3U9Eo4nB0i31C3hs7iVKGpko6IOw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782229911; a=rsa-sha256; cv=none; b=Q4A8jmErFAxUuyRpwS6a1UADBdXhapZm9AwDxY4sUpgIwcbHJW96diCA5vEr49zG0ej/Sj mUiHU94P3/+pCukNhLcdlwNEnOT1rpR5PLFFIFvWbSXMPCdjV+lJMIOB+Xui8BOw1bajBd u+e7/XHynE/f311mCYLHNrN0JnGgQLX2RnPUb2FU0YmSMZYr2u7CFyJ1ZpgKue8H++hLiM 6qfXSm3D1gSjykmI3Q0m0PKeTBLr7mcEufICMROngeG/a4TxIPMi+2qY4nC6WWg0CfbAvA eQcLiiOypqYF8XHN20/cp7EODMUgrESz+XGzhO+j395/koDuzF8S+rC6+ydCTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782229911; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0JZHVBNoBslnPKAysrAdyktTtu4LszLFNOHuLMPkKVs=; b=hlpN8ofGhMv6Hcp1VC4xylju1ly3x/XkMSlm51VU2pQ2Ai91IINBV4LhsZgMfCl8O9guOM T2jJ0WRGJzweEdDKw60DEkS/nyCBdBreJBctpK+xDH2ysD0Inb76sN39fgqeOezi28Vjqr sE1/VRAThF7R/ozSZy1ZM6lN+Ii/LacCpMDOZfv0tmFSsWuPBLp1nUqa8ottOqOGsiYumg JQ8E2xFlyVs976Div/dBU4jiAE5H3y9ReqtkXufN82RC1EUDJLq9Qcwnzndg78dykU+cVM plZuEEgzZt0PWPHjlsN2vuhdAisW1t/Z4Wa40ojQtwIhjOfscLHlzcx96+UZUQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gl8h71zp5zglM for ; Tue, 23 Jun 2026 15:51:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 239a4 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 23 Jun 2026 15:51:51 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: c6eb9f16cf0e - main - pciconf: Minor cleanups in the config register methods List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c6eb9f16cf0e19b54b382aa44f0c9a7bcec5fc40 Auto-Submitted: auto-generated Date: Tue, 23 Jun 2026 15:51:51 +0000 Message-Id: <6a3aab97.239a4.320d5ec4@gitrepo.freebsd.org> The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=c6eb9f16cf0e19b54b382aa44f0c9a7bcec5fc40 commit c6eb9f16cf0e19b54b382aa44f0c9a7bcec5fc40 Author: John Baldwin AuthorDate: 2026-06-23 15:51:43 +0000 Commit: John Baldwin 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)