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
This commit is contained in:
Mark Johnston committed 2026-11-04 23:14:13 +00:00
1 parent 9ca2cfeb4e
commit 12b3c29a98
7 files changed
+13 -11

No files matched your search

@@ -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_ */
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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,
+6 -5
View File
@@ -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) &&
+2 -2
View File
@@ -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) || \
+1 -1
View File
@@ -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 */
+1
View File
@@ -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 */