summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorandvar <andvar@NetBSD.org>2021-11-05 23:39:47 +0000
committerandvar <andvar@NetBSD.org>2021-11-05 23:39:47 +0000
commit29d081106d135880cc0bf64557bc5d13ffbcb907 (patch)
treed4c9843e3204e56c98f97599617ae6b4ae79555f /sys/dev
parenta61f8685a6653f344cd1b5c80694d03d0a385efb (diff)
mcx(4): ensure that RQT size is always a power of two.
Fixes PR kern/56484. Thanks riastradh for the power of two patch :). OK: mrg, jmcneill, riastradh.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/if_mcx.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/sys/dev/pci/if_mcx.c b/sys/dev/pci/if_mcx.c
index 45250f57975..3b33f5d8671 100644
--- a/sys/dev/pci/if_mcx.c
+++ b/sys/dev/pci/if_mcx.c
@@ -1,4 +1,4 @@
-/* $NetBSD: if_mcx.c,v 1.22 2021/09/26 20:14:07 jmcneill Exp $ */
+/* $NetBSD: if_mcx.c,v 1.23 2021/11/05 23:39:47 andvar Exp $ */
/* $OpenBSD: if_mcx.c,v 1.101 2021/06/02 19:16:11 patrick Exp $ */
/*
@@ -23,7 +23,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mcx.c,v 1.22 2021/09/26 20:14:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mcx.c,v 1.23 2021/11/05 23:39:47 andvar Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_mcx.c,v 1.22 2021/09/26 20:14:07 jmcneill Exp $")
#include <sys/interrupt.h>
#include <sys/pcq.h>
#include <sys/cpu.h>
+#include <sys/bitops.h>
#include <machine/intr.h>
@@ -2956,6 +2957,8 @@ mcx_attach(device_t parent, device_t self, void *aux)
sc->sc_nqueues = uimin(MCX_MAX_QUEUES, msix);
sc->sc_nqueues = uimin(sc->sc_nqueues, ncpu);
+ /* Round down to a power of two. */
+ sc->sc_nqueues = 1U << ilog2(sc->sc_nqueues);
sc->sc_queues = kmem_zalloc(sc->sc_nqueues * sizeof(*sc->sc_queues),
KM_SLEEP);