Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Avoid undefined behavior. Found by KUBSan. Some o...



details:   https://anonhg.NetBSD.org/src/rev/12e91cfec33b
branches:  trunk
changeset: 1000461:12e91cfec33b
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu Jul 25 11:56:09 2019 +0000

description:
Avoid undefined behavior. Found by KUBSan. Some of errors are still remaining.

diffstat:

 sys/dev/ic/arn9285.c |  8 ++++----
 sys/dev/ic/athn.c    |  6 +++---
 sys/dev/ic/athnreg.h |  6 +++---
 3 files changed, 10 insertions(+), 10 deletions(-)

diffs (87 lines):

diff -r 5200173b1dc1 -r 12e91cfec33b sys/dev/ic/arn9285.c
--- a/sys/dev/ic/arn9285.c      Thu Jul 25 11:44:14 2019 +0000
+++ b/sys/dev/ic/arn9285.c      Thu Jul 25 11:56:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arn9285.c,v 1.3 2013/10/17 21:24:24 christos Exp $     */
+/*     $NetBSD: arn9285.c,v 1.4 2019/07/25 11:56:09 msaitoh Exp $      */
 /*     $OpenBSD: ar9285.c,v 1.19 2012/06/10 21:23:36 kettenis Exp $    */
 
 /*-
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arn9285.c,v 1.3 2013/10/17 21:24:24 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arn9285.c,v 1.4 2019/07/25 11:56:09 msaitoh Exp $");
 
 #ifndef _MODULE
 #include "athn_usb.h"
@@ -320,7 +320,7 @@
                AR_WRITE_BARRIER(sc);
                DELAY(100);
                reg = AR_READ(sc, AR9285_AN_RF2G4);
-               reg = RW(reg, AR9271_AN_RF2G4_DB2,    db2[0]);
+               reg = RW(reg, AR9271_AN_RF2G4_DB2, (uint32_t)db2[0]);
                AR_WRITE(sc, AR9285_AN_RF2G4, reg);
                AR_WRITE_BARRIER(sc);
                DELAY(100);
@@ -784,7 +784,7 @@
                    pdadcs[i + 0] <<  0 |
                    pdadcs[i + 1] <<  8 |
                    pdadcs[i + 2] << 16 |
-                   pdadcs[i + 3] << 24);
+                   (uint32_t)pdadcs[i + 3] << 24);
        }
        AR_WRITE_BARRIER(sc);
 }
diff -r 5200173b1dc1 -r 12e91cfec33b sys/dev/ic/athn.c
--- a/sys/dev/ic/athn.c Thu Jul 25 11:44:14 2019 +0000
+++ b/sys/dev/ic/athn.c Thu Jul 25 11:56:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: athn.c,v 1.21 2019/05/28 07:41:48 msaitoh Exp $        */
+/*     $NetBSD: athn.c,v 1.22 2019/07/25 11:56:09 msaitoh Exp $        */
 /*     $OpenBSD: athn.c,v 1.83 2014/07/22 13:12:11 mpi Exp $   */
 
 /*-
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: athn.c,v 1.21 2019/05/28 07:41:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: athn.c,v 1.22 2019/07/25 11:56:09 msaitoh Exp $");
 
 #ifndef _MODULE
 #include "athn_usb.h"          /* for NATHN_USB */
@@ -1021,7 +1021,7 @@
 
        /* exponent = 14 - floor(log2(coeff)) */
        for (exp = 31; exp > 0; exp--)
-               if (coeff & (1 << exp))
+               if (coeff & (1U << exp))
                        break;
        exp = 14 - (exp - COEFF_SCALE_SHIFT);
 
diff -r 5200173b1dc1 -r 12e91cfec33b sys/dev/ic/athnreg.h
--- a/sys/dev/ic/athnreg.h      Thu Jul 25 11:44:14 2019 +0000
+++ b/sys/dev/ic/athnreg.h      Thu Jul 25 11:56:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: athnreg.h,v 1.1 2013/03/30 02:53:02 christos Exp $     */
+/*     $NetBSD: athnreg.h,v 1.2 2019/07/25 11:56:09 msaitoh Exp $      */
 /*     $OpenBSD: athnreg.h,v 1.18 2012/06/10 21:23:36 kettenis Exp $   */
 
 /*-
@@ -851,12 +851,12 @@
 #define AR_INTR_SPURIOUS       0xffffffff
 
 /* Bits for AR_GPIO_OE_OUT. */
-#define AR_GPIO_OE_OUT_DRV_M   0x00000003
+#define AR_GPIO_OE_OUT_DRV_M   0x00000003UL
 #define AR_GPIO_OE_OUT_DRV_S   0
 #define AR_GPIO_OE_OUT_DRV_NO  0
 #define AR_GPIO_OE_OUT_DRV_LOW 1
 #define AR_GPIO_OE_OUT_DRV_HI  2
-#define AR_GPIO_OE_OUT_DRV_ALL 3
+#define AR_GPIO_OE_OUT_DRV_ALL 3UL
 
 /* Bits for AR_GPIO_INTR_POL. */
 #define AR_GPIO_INTR_POL_PIN(i)                (1 << (i))



Home | Main Index | Thread Index | Old Index