Module Name: src Committed By: msaitoh Date: Thu Jul 25 11:56:09 UTC 2019
Modified Files: src/sys/dev/ic: arn9285.c athn.c athnreg.h Log Message: Avoid undefined behavior. Found by KUBSan. Some of errors are still remaining. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/ic/arn9285.c cvs rdiff -u -r1.21 -r1.22 src/sys/dev/ic/athn.c cvs rdiff -u -r1.1 -r1.2 src/sys/dev/ic/athnreg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/arn9285.c diff -u src/sys/dev/ic/arn9285.c:1.3 src/sys/dev/ic/arn9285.c:1.4 --- src/sys/dev/ic/arn9285.c:1.3 Thu Oct 17 21:24:24 2013 +++ src/sys/dev/ic/arn9285.c Thu Jul 25 11:56:09 2019 @@ -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 @@ ar9285_init_from_rom(struct athn_softc * 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 @@ ar9285_set_power_calib(struct athn_softc 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); } Index: src/sys/dev/ic/athn.c diff -u src/sys/dev/ic/athn.c:1.21 src/sys/dev/ic/athn.c:1.22 --- src/sys/dev/ic/athn.c:1.21 Tue May 28 07:41:48 2019 +++ src/sys/dev/ic/athn.c Thu Jul 25 11:56:09 2019 @@ -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 @@ athn_get_delta_slope(uint32_t coeff, uin /* 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); Index: src/sys/dev/ic/athnreg.h diff -u src/sys/dev/ic/athnreg.h:1.1 src/sys/dev/ic/athnreg.h:1.2 --- src/sys/dev/ic/athnreg.h:1.1 Sat Mar 30 02:53:02 2013 +++ src/sys/dev/ic/athnreg.h Thu Jul 25 11:56:09 2019 @@ -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))