svn commit: r322256 - head/sys/dev/hwpmc

Konstantin Belousov kib at FreeBSD.org
Tue Aug 8 15:46:31 UTC 2017


Author: kib
Date: Tue Aug  8 15:46:29 2017
New Revision: 322256
URL: https://svnweb.freebsd.org/changeset/base/322256

Log:
  Fix logic error in the the assert, causing the condition to be always true.
  
  Also improve the formatting of the corresponding KASSERT message.
  
  Based on the submission by:	Svyatoslav <razmyslov at viva64.com>
  Found by:	PVS-Studio
  PR:	217741
  Reviewed by:	emaste
  Sponsored by:	The FreeBSD Foundation (kib)
  MFC after:	1 week

Modified:
  head/sys/dev/hwpmc/hwpmc_piv.c

Modified: head/sys/dev/hwpmc/hwpmc_piv.c
==============================================================================
--- head/sys/dev/hwpmc/hwpmc_piv.c	Tue Aug  8 15:37:21 2017	(r322255)
+++ head/sys/dev/hwpmc/hwpmc_piv.c	Tue Aug  8 15:46:29 2017	(r322256)
@@ -809,8 +809,8 @@ p4_config_pmc(int cpu, int ri, struct pmc *pm)
 	mtx_lock_spin(&pc->pc_mtx);
 	cfgflags = P4_PCPU_GET_CFGFLAGS(pc,ri);
 
-	KASSERT(cfgflags >= 0 || cfgflags <= 3,
-	    ("[p4,%d] illegal cfgflags cfg=%d on cpu=%d ri=%d", __LINE__,
+	KASSERT((cfgflags & ~0x3) == 0,
+	    ("[p4,%d] illegal cfgflags cfg=%#x on cpu=%d ri=%d", __LINE__,
 		cfgflags, cpu, ri));
 
 	KASSERT(cfgflags == 0 || phw->phw_pmc,
@@ -835,8 +835,8 @@ p4_config_pmc(int cpu, int ri, struct pmc *pm)
 			phw->phw_pmc = NULL;
 	}
 
-	KASSERT(cfgflags >= 0 || cfgflags <= 3,
-	    ("[p4,%d] illegal runcount cfg=%d on cpu=%d ri=%d", __LINE__,
+	KASSERT((cfgflags & ~0x3) == 0,
+	    ("[p4,%d] illegal runcount cfg=%#x on cpu=%d ri=%d", __LINE__,
 		cfgflags, cpu, ri));
 
 	P4_PCPU_SET_CFGFLAGS(pc,ri,cfgflags);


More information about the svn-src-all mailing list