Module Name: src
Committed By: skrll
Date: Sun Jul 12 13:33:44 UTC 2020
Modified Files:
src/sys/arch/arm/cortex: gic.c
Log Message:
Avoid undefined behaviour. Detected by KUBSAN.
To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/arm/cortex/gic.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/arm/cortex/gic.c
diff -u src/sys/arch/arm/cortex/gic.c:1.39 src/sys/arch/arm/cortex/gic.c:1.40
--- src/sys/arch/arm/cortex/gic.c:1.39 Mon Apr 13 12:14:04 2020
+++ src/sys/arch/arm/cortex/gic.c Sun Jul 12 13:33:44 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: gic.c,v 1.39 2020/04/13 12:14:04 jmcneill Exp $ */
+/* $NetBSD: gic.c,v 1.40 2020/07/12 13:33:44 skrll Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -34,7 +34,7 @@
#define _INTR_PRIVATE
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.39 2020/04/13 12:14:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.40 2020/07/12 13:33:44 skrll Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -430,11 +430,11 @@ armgic_establish_irq(struct pic_softc *p
* There are 16 irqs per CFG register. 10=EDGE 00=LEVEL
*/
uint32_t new_cfg = cfg;
- uint32_t old_cfg = (cfg >> twopair_shift) & 3;
- if (is->is_type == IST_LEVEL && (old_cfg & 2) != 0) {
- new_cfg &= ~(3 << twopair_shift);
+ uint32_t old_cfg = (cfg >> twopair_shift) & __BITS(1, 0);
+ if (is->is_type == IST_LEVEL && (old_cfg & __BIT(1)) != 0) {
+ new_cfg &= ~(__BITS(1, 0) << twopair_shift);
} else if (is->is_type == IST_EDGE && (old_cfg & 2) == 0) {
- new_cfg |= 2 << twopair_shift;
+ new_cfg |= __BIT(1) << twopair_shift;
}
if (new_cfg != cfg) {
gicd_write(sc, cfg_reg, new_cfg);