Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 Avoid unportable signed integer left shift ...



details:   https://anonhg.NetBSD.org/src/rev/abedae059463
branches:  trunk
changeset: 324426:abedae059463
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Jul 03 11:45:54 2018 +0000

description:
Avoid unportable signed integer left shift in intr_calculatemasks()

Detected with Kernel Undefined Behavior Sanitizer.

There were at least two places reported, for consistency fix all the
left shift bit shift.

src/sys/arch/x86/x86/intr.c:339:22, left shift of 1 by 31 places cannot be represented in type 'int'
src/sys/arch/x86/x86/intr.c:347:15, left shift of 1 by 31 places cannot be represented in type 'int'

Reported by <Harry Pantazis>

diffstat:

 sys/arch/x86/x86/intr.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (41 lines):

diff -r b05c4dce4bc7 -r abedae059463 sys/arch/x86/x86/intr.c
--- a/sys/arch/x86/x86/intr.c   Tue Jul 03 09:39:32 2018 +0000
+++ b/sys/arch/x86/x86/intr.c   Tue Jul 03 11:45:54 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.126 2018/06/24 13:35:33 jdolecek Exp $      */
+/*     $NetBSD: intr.c,v 1.127 2018/07/03 11:45:54 kamil Exp $ */
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.126 2018/06/24 13:35:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.127 2018/07/03 11:45:54 kamil Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -334,18 +334,18 @@
                        continue;
                }
                for (q = ci->ci_isources[irq]->is_handlers; q; q = q->ih_next)
-                       levels |= 1 << q->ih_level;
+                       levels |= 1U << q->ih_level;
                intrlevel[irq] = levels;
                if (levels)
-                       unusedirqs &= ~(1 << irq);
+                       unusedirqs &= ~(1U << irq);
        }
 
        /* Then figure out which IRQs use each level. */
        for (level = 0; level < NIPL; level++) {
                int irqs = 0;
                for (irq = 0; irq < MAX_INTR_SOURCES; irq++)
-                       if (intrlevel[irq] & (1 << level))
-                               irqs |= 1 << irq;
+                       if (intrlevel[irq] & (1U << level))
+                               irqs |= 1U << irq;
                ci->ci_imask[level] = irqs | unusedirqs;
        }
 



Home | Main Index | Thread Index | Old Index