git: 8e97f5c28119 - stable/15 - ioctl: Add a macro for extracting the ioctl number from a command
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Nov 2026 22:22:27 UTC
The branch stable/15 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=8e97f5c2811974587569ba5a8653454fe273ef2e
commit 8e97f5c2811974587569ba5a8653454fe273ef2e
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-11-04 22:38:17 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-13 22:21:37 +0000
ioctl: Add a macro for extracting the ioctl number from a command
Sprinkle it in various drivers which hard-coded the command layout.
No functional change intended.
Reviewed by: dumbbell, emaste
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61045
(cherry picked from commit 12b3c29a985d1753693d732372dafe915a890259)
---
sys/compat/linuxkpi/common/include/linux/ioctl.h | 2 +-
sys/dev/sound/pcm/dsp.c | 2 +-
sys/dev/sound/pcm/mixer.c | 2 +-
sys/dev/syscons/scvesactl.c | 11 ++++++-----
sys/dev/syscons/scvidctl.c | 4 ++--
sys/netgraph/ng_eiface.c | 2 +-
sys/sys/ioccom.h | 1 +
7 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/ioctl.h b/sys/compat/linuxkpi/common/include/linux/ioctl.h
index 77c01224e6a5..34a4138417ea 100644
--- a/sys/compat/linuxkpi/common/include/linux/ioctl.h
+++ b/sys/compat/linuxkpi/common/include/linux/ioctl.h
@@ -33,6 +33,6 @@
#define _IOC_SIZE(cmd) IOCPARM_LEN(cmd)
#define _IOC_TYPE(cmd) IOCGROUP(cmd)
-#define _IOC_NR(cmd) ((cmd) & 0xff)
+#define _IOC_NR(cmd) IOCNUM(cmd)
#endif /* _LINUXKPI_LINUX_IOCTL_H_ */
diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c
index 520d742765ce..7bbbef259a8c 100644
--- a/sys/dev/sound/pcm/dsp.c
+++ b/sys/dev/sound/pcm/dsp.c
@@ -565,7 +565,7 @@ dsp_ioctl_channel(struct dsp_cdevpriv *priv, struct pcm_channel *ch,
PCM_UNLOCKASSERT(d);
- j = cmd & 0xff;
+ j = IOCNUM(cmd);
rdch = priv->rdch;
wrch = priv->wrch;
diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c
index d8db02ab5950..08e9bb579ada 100644
--- a/sys/dev/sound/pcm/mixer.c
+++ b/sys/dev/sound/pcm/mixer.c
@@ -912,7 +912,7 @@ mixer_ioctl_cmd(struct cdev *i_dev, unsigned long cmd, caddr_t arg, int mode,
{
struct snd_mixer *m;
int ret = EINVAL, *arg_i = (int *)arg;
- int v = -1, j = cmd & 0xff;
+ int v = -1, j = IOCNUM(cmd);
/*
* Certain ioctls may be made on any type of device (audio, mixer,
diff --git a/sys/dev/syscons/scvesactl.c b/sys/dev/syscons/scvesactl.c
index 38e5b36f192f..789a9dcab9ae 100644
--- a/sys/dev/syscons/scvesactl.c
+++ b/sys/dev/syscons/scvesactl.c
@@ -54,9 +54,10 @@ static int
vesa_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
{
scr_stat *scp;
- int mode;
+ int mode, num;
scp = SC_STAT(tp);
+ num = IOCNUM(cmd);
switch (cmd) {
/* generic text modes */
@@ -65,7 +66,7 @@ vesa_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
case SW_TEXT_132x60:
if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
- return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);
+ return sc_set_text_mode(scp, tp, num, 0, 0, 0, 0);
/* text modes */
case SW_VESA_C80x60:
@@ -75,7 +76,7 @@ vesa_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
case SW_VESA_C132x60:
if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
- mode = (cmd & 0xff) + M_VESA_BASE;
+ mode = num + M_VESA_BASE;
return sc_set_text_mode(scp, tp, mode, 0, 0, 0, 0);
/* graphics modes */
@@ -101,14 +102,14 @@ vesa_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
case SW_VESA_FULL_1280:
if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
- mode = (cmd & 0xff) + M_VESA_BASE;
+ mode = num + M_VESA_BASE;
return sc_set_graphics_mode(scp, tp, mode);
default:
if (IOCGROUP(cmd) == 'V') {
if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
- mode = (cmd & 0xff) + M_VESA_BASE;
+ mode = num + M_VESA_BASE;
if (((cmd & IOC_DIRMASK) == IOC_VOID) &&
(mode > M_VESA_FULL_1280) &&
diff --git a/sys/dev/syscons/scvidctl.c b/sys/dev/syscons/scvidctl.c
index dc2951bfb11d..6bed47215ad6 100644
--- a/sys/dev/syscons/scvidctl.c
+++ b/sys/dev/syscons/scvidctl.c
@@ -651,7 +651,7 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
case SW_EGAMONO80x25:
if (!(adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
- return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);
+ return sc_set_text_mode(scp, tp, IOCNUM(cmd), 0, 0, 0, 0);
/* GRAPHICS MODES */
case SW_BG320: case SW_BG640:
@@ -661,7 +661,7 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
case SW_VGA_MODEX:
if (!(adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
- return sc_set_graphics_mode(scp, tp, cmd & 0xff);
+ return sc_set_graphics_mode(scp, tp, IOCNUM(cmd));
#endif /* SC_NO_MODE_CHANGE */
#if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
diff --git a/sys/netgraph/ng_eiface.c b/sys/netgraph/ng_eiface.c
index 4598291f3d60..541e2685a362 100644
--- a/sys/netgraph/ng_eiface.c
+++ b/sys/netgraph/ng_eiface.c
@@ -332,7 +332,7 @@ ng_eiface_print_ioctl(struct ifnet *ifp, int command, caddr_t data)
ifp->if_xname,
str,
IOCGROUP(command),
- command & 0xff,
+ IOCNUM(command),
IOCPARM_LEN(command));
}
#endif /* DEBUG */
diff --git a/sys/sys/ioccom.h b/sys/sys/ioccom.h
index d8c2ca2ac6cc..3960983fbb90 100644
--- a/sys/sys/ioccom.h
+++ b/sys/sys/ioccom.h
@@ -47,6 +47,7 @@
#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
#define IOCGROUP(x) (((x) >> 8) & 0xff)
+#define IOCNUM(x) ((x) & 0xff)
#define IOCPARM_MAX (1 << IOCPARM_SHIFT) /* max size of ioctl */