[PATCH 1/2] staging: brcm80211: replaced static ASSERTs with BUILD_BUG_ON

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

 



Code cleanup. ASSERTs that check static (compile time) conditions
have been replaced by the Linux macro BUILD_BUG_ON, so violations
are detected compile time rather than run time.

Signed-off-by: Roland Vossen <rvossen@xxxxxxxxxxxx>
Reviewed-by: Arend van Spriel <arend@xxxxxxxxxxxx>
---
 drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c |    6 ++--
 drivers/staging/brcm80211/brcmsmac/wlc_bmac.c  |   20 ++++++------
 drivers/staging/brcm80211/brcmsmac/wlc_main.c  |   40 +++++++++++-------------
 3 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c b/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c
index c6cdcd9..7939868 100644
--- a/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c
+++ b/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c
@@ -165,9 +165,9 @@ struct ampdu_info *wlc_ampdu_attach(struct wlc_info *wlc)
 	int i;
 
 	/* some code depends on packed structures */
-	ASSERT(DOT11_MAXNUMFRAGS == NBITS(u16));
-	ASSERT(ISPOWEROF2(AMPDU_TX_BA_MAX_WSIZE));
-	ASSERT(ISPOWEROF2(AMPDU_RX_BA_MAX_WSIZE));
+	BUILD_BUG_ON(DOT11_MAXNUMFRAGS != NBITS(u16));
+	BUILD_BUG_ON(!ISPOWEROF2(AMPDU_TX_BA_MAX_WSIZE));
+	BUILD_BUG_ON(!ISPOWEROF2(AMPDU_RX_BA_MAX_WSIZE));
 	ASSERT(wlc->pub->tunables->ampdunummpdu <= AMPDU_MAX_MPDU);
 	ASSERT(wlc->pub->tunables->ampdunummpdu > 0);
 
diff --git a/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c b/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c
index 5a96dc3..fc162dc 100644
--- a/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c
+++ b/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c
@@ -547,8 +547,8 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
 		 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
 		 * RX: RX_FIFO (RX data packets)
 		 */
-		ASSERT(TX_AC_BK_FIFO == 0);
-		ASSERT(RX_FIFO == 0);
+		BUILD_BUG_ON(TX_AC_BK_FIFO != 0);
+		BUILD_BUG_ON(RX_FIFO != 0);
 		wlc_hw->di[0] = dma_attach(name, wlc_hw->sih,
 					   (wme ? DMAREG(wlc_hw, DMA_TX, 0) :
 					    NULL), DMAREG(wlc_hw, DMA_RX, 0),
@@ -563,8 +563,8 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
 		 *   (legacy) TX_DATA_FIFO (TX data packets)
 		 * RX: UNUSED
 		 */
-		ASSERT(TX_AC_BE_FIFO == 1);
-		ASSERT(TX_DATA_FIFO == 1);
+		BUILD_BUG_ON(TX_AC_BE_FIFO != 1);
+		BUILD_BUG_ON(TX_DATA_FIFO != 1);
 		wlc_hw->di[1] = dma_attach(name, wlc_hw->sih,
 					   DMAREG(wlc_hw, DMA_TX, 1), NULL,
 					   tune->ntxd, 0, 0, -1, 0, 0,
@@ -576,7 +576,7 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
 		 * TX: TX_AC_VI_FIFO (TX AC Video data packets)
 		 * RX: UNUSED
 		 */
-		ASSERT(TX_AC_VI_FIFO == 2);
+		BUILD_BUG_ON(TX_AC_VI_FIFO != 2);
 		wlc_hw->di[2] = dma_attach(name, wlc_hw->sih,
 					   DMAREG(wlc_hw, DMA_TX, 2), NULL,
 					   tune->ntxd, 0, 0, -1, 0, 0,
@@ -587,8 +587,8 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
 		 * TX: TX_AC_VO_FIFO (TX AC Voice data packets)
 		 *   (legacy) TX_CTL_FIFO (TX control & mgmt packets)
 		 */
-		ASSERT(TX_AC_VO_FIFO == 3);
-		ASSERT(TX_CTL_FIFO == 3);
+		BUILD_BUG_ON(TX_AC_VO_FIFO != 3);
+		BUILD_BUG_ON(TX_CTL_FIFO != 3);
 		wlc_hw->di[3] = dma_attach(name, wlc_hw->sih,
 					   DMAREG(wlc_hw, DMA_TX, 3),
 					   NULL, tune->ntxd, 0, 0, -1,
@@ -648,7 +648,7 @@ int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device, uint unit,
 	WL_TRACE("wl%d: wlc_bmac_attach: vendor 0x%x device 0x%x\n",
 		 unit, vendor, device);
 
-	ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
+	BUILD_BUG_ON(sizeof(wlc_d11rxhdr_t) > WL_HWRXOFF);
 
 	wme = true;
 
@@ -1384,7 +1384,7 @@ wlc_bmac_mhf(struct wlc_hw_info *wlc_hw, u8 idx, u16 mask, u16 val,
 
 	ASSERT((val & ~mask) == 0);
 	ASSERT(idx < MHFMAX);
-	ASSERT(ARRAY_SIZE(addr) == MHFMAX);
+	BUILD_BUG_ON(ARRAY_SIZE(addr) != MHFMAX);
 
 	switch (bands) {
 		/* Current band only or all bands,
@@ -1460,7 +1460,7 @@ static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs)
 		M_HOST_FLAGS5
 	};
 
-	ASSERT(ARRAY_SIZE(addr) == MHFMAX);
+	BUILD_BUG_ON(ARRAY_SIZE(addr) != MHFMAX);
 
 	for (idx = 0; idx < MHFMAX; idx++) {
 		wlc_bmac_write_shm(wlc_hw, addr[idx], mhfs[idx]);
diff --git a/drivers/staging/brcm80211/brcmsmac/wlc_main.c b/drivers/staging/brcm80211/brcmsmac/wlc_main.c
index 639b5d7..98a5466 100644
--- a/drivers/staging/brcm80211/brcmsmac/wlc_main.c
+++ b/drivers/staging/brcm80211/brcmsmac/wlc_main.c
@@ -1356,7 +1356,7 @@ void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe)
 		 }
 	};
 
-	ASSERT(sizeof(*pe) == WME_PARAM_IE_LEN);
+	BUILD_BUG_ON(sizeof(*pe) != WME_PARAM_IE_LEN);
 	memcpy(pe, &stadef, sizeof(*pe));
 }
 
@@ -1733,35 +1733,31 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
 	WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
 		unit, __func__, vendor, device);
 
-	ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS);
-	ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS);
+	BUILD_BUG_ON(WSEC_MAX_RCMTA_KEYS > WSEC_MAX_KEYS);
+	BUILD_BUG_ON(WSEC_MAX_DEFAULT_KEYS != WLC_DEFAULT_KEYS);
 
 	/* some code depends on packed structures */
-	ASSERT(sizeof(struct ethhdr) == ETH_HLEN);
-	ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE);
-	ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN);
-	ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN);
-	ASSERT(sizeof(d11txh_t) == D11_TXH_LEN);
-	ASSERT(sizeof(d11rxhdr_t) == RXHDR_LEN);
-	ASSERT(sizeof(struct ieee80211_hdr) == DOT11_A4_HDR_LEN);
-	ASSERT(sizeof(struct ieee80211_rts) == DOT11_RTS_LEN);
-	ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN);
-	ASSERT(sizeof(struct ieee80211_ht_cap) == HT_CAP_IE_LEN);
-#ifdef BRCM_FULLMAC
-	ASSERT(offsetof(wl_scan_params_t, channel_list) ==
-	       WL_SCAN_PARAMS_FIXED_SIZE);
-#endif
-	ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32)));
-	ASSERT(ISPOWEROF2(MA_WINDOW_SZ));
-
-	ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
+	BUILD_BUG_ON(sizeof(struct ethhdr) != ETH_HLEN);
+	BUILD_BUG_ON(sizeof(d11regs_t) != SI_CORE_SIZE);
+	BUILD_BUG_ON(sizeof(ofdm_phy_hdr_t) != D11_PHY_HDR_LEN);
+	BUILD_BUG_ON(sizeof(cck_phy_hdr_t) != D11_PHY_HDR_LEN);
+	BUILD_BUG_ON(sizeof(d11txh_t) != D11_TXH_LEN);
+	BUILD_BUG_ON(sizeof(d11rxhdr_t) != RXHDR_LEN);
+	BUILD_BUG_ON(sizeof(struct ieee80211_hdr) != DOT11_A4_HDR_LEN);
+	BUILD_BUG_ON(sizeof(struct ieee80211_rts) != DOT11_RTS_LEN);
+	BUILD_BUG_ON(sizeof(tx_status_t) != TXSTATUS_LEN);
+	BUILD_BUG_ON(sizeof(struct ieee80211_ht_cap) != HT_CAP_IE_LEN);
+	BUILD_BUG_ON(!IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32)));
+	BUILD_BUG_ON(!ISPOWEROF2(MA_WINDOW_SZ));
+
+	BUILD_BUG_ON(sizeof(wlc_d11rxhdr_t) > WL_HWRXOFF);
 
 	/*
 	 * Number of replay counters value used in WPA IE must match # rxivs
 	 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
 	 * 'RSN Information Element' figure 8 for this mapping.
 	 */
-	ASSERT((WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
+	BUILD_BUG_ON(!(WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
 		&& 16 == WLC_NUMRXIVS)
 	       || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
 		   && 4 == WLC_NUMRXIVS));
-- 
1.7.1


_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux