Skip to contentSkip to conversation

staging: wilc1000: correct Smatch warnings & use flexible-array member

PATCH New [email protected] 1 participant 4 messages Mar 2, 2020 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: wilc1000: correct Smatch warnings & use flexible-array member

From: Ajay Singh <[email protected]>

This patch series contains changes to address few Smatch static checker reported warnings. Also added one patch to make use of flexible-array member instead of zero-length array for few cases which were missed earlier.

Ajay Singh (3):
staging: wilc1000: use correct data for memcpy in
wilc_hif_pack_sta_param()
staging: wilc1000: remove unnecessary always true 'if' conditions
staging: wilc1000: use flexible-array member instead of zero-length
array

 drivers/staging/wilc1000/cfg80211.c | 26 ++++++++++++--------------
 drivers/staging/wilc1000/hif.c      |  2 +-
 drivers/staging/wilc1000/spi.c      | 10 +++++-----
 drivers/staging/wilc1000/wlan.c     |  6 ++----
 4 files changed, 20 insertions(+), 24 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/3 staging: wilc1000: use correct data for memcpy in wilc_hif_pack_sta_param()

From: Ajay Singh <[email protected]>

Use correct data for memcpy in wilc_hif_pack_sta_param(). Its reported by Smatch static code analyser tool as discussed in [1].

[1]. https://lore.kernel.org/linux-wireless/20200302092346.GA24308@kadam/

---
 drivers/staging/wilc1000/hif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wilc1000/hif.c +1 -1
index c8c41c2df4ec..6c7de2f8d3f2 100644
@@ -801,7 +801,7 @@ static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
 
 	if (params->ht_capa) {
 		*cur_byte++ = true;
-		memcpy(cur_byte, &params->ht_capa,
+		memcpy(cur_byte, params->ht_capa,
 		       sizeof(struct ieee80211_ht_cap));
 	} else {
 		*cur_byte++ = false;
Signature · 1 line
2.24.0
#2 lore raw

PATCH 2/3 staging: wilc1000: remove unnecessary always true 'if' conditions

In reply to [email protected]

From: Ajay Singh <[email protected]>

Remove the unnecessary always true 'if' conditions and simiplifed the logic as suggested in [1].

[1]. https://lore.kernel.org/linux-wireless/20200302092346.GA24308@kadam/

---
 drivers/staging/wilc1000/cfg80211.c | 26 ++++++++++++--------------
 drivers/staging/wilc1000/wlan.c     |  6 ++----
 2 files changed, 14 insertions(+), 18 deletions(-)
drivers/staging/wilc1000/cfg80211.c +12 -14
index 5d8faa01337d..54e02807cebf 100644
@@ -888,7 +888,6 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 		     struct cfg80211_pmksa *pmksa)
 {
 	u32 i;
-	int ret = 0;
 	struct wilc_vif *vif = netdev_priv(netdev);
 	struct wilc_priv *priv = &vif->priv;
 
@@ -901,21 +900,20 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 		}
 	}
 
-	if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
-		for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
-			memcpy(priv->pmkid_list.pmkidlist[i].bssid,
-			       priv->pmkid_list.pmkidlist[i + 1].bssid,
-			       ETH_ALEN);
-			memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
-			       priv->pmkid_list.pmkidlist[i + 1].pmkid,
-			       WLAN_PMKID_LEN);
-		}
-		priv->pmkid_list.numpmkid--;
-	} else {
-		ret = -EINVAL;
+	if (i == priv->pmkid_list.numpmkid)
+		return -EINVAL;
+
+	for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
+		memcpy(priv->pmkid_list.pmkidlist[i].bssid,
+		       priv->pmkid_list.pmkidlist[i + 1].bssid,
+		       ETH_ALEN);
+		memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
+		       priv->pmkid_list.pmkidlist[i + 1].pmkid,
+		       WLAN_PMKID_LEN);
 	}
+	priv->pmkid_list.numpmkid--;
 
-	return ret;
+	return 0;
 }
 
 static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
drivers/staging/wilc1000/wlan.c +2 -4
index 3aeca882f431..6a82fb2f283e 100644
@@ -703,10 +703,8 @@ static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size)
 			wilc_wfi_mgmt_rx(wilc, buff_ptr, pkt_len);
 		} else {
 			if (!is_cfg_packet) {
-				if (pkt_len > 0) {
-					wilc_frmw_to_host(wilc, buff_ptr,
-							  pkt_len, pkt_offset);
-				}
+				wilc_frmw_to_host(wilc, buff_ptr, pkt_len,
+						  pkt_offset);
 			} else {
 				struct wilc_cfg_rsp rsp;
 
Signature · 1 line
2.24.0
#3 lore raw

PATCH 3/3 staging: wilc1000: use flexible-array member instead of zero-length array

In reply to [email protected]

From: Ajay Singh <[email protected]>

Use flexible-array member introduced in C99 instead of zero-length array. Most of zero-length array was already taken care in previous patch [1]. Now modified few more cases which were not handled earlier.

[1]. https://patchwork.kernel.org/patch/11394197/

---
 drivers/staging/wilc1000/spi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/wilc1000/spi.c +5 -5
index 11653ac118cd..dfd25df75780 100644
@@ -109,27 +109,27 @@ struct wilc_spi_cmd {
 	union {
 		struct {
 			u8 addr[3];
-			u8 crc[0];
+			u8 crc[];
 		} __packed simple_cmd;
 		struct {
 			u8 addr[3];
 			u8 size[2];
-			u8 crc[0];
+			u8 crc[];
 		} __packed dma_cmd;
 		struct {
 			u8 addr[3];
 			u8 size[3];
-			u8 crc[0];
+			u8 crc[];
 		} __packed dma_cmd_ext;
 		struct {
 			u8 addr[2];
 			__be32 data;
-			u8 crc[0];
+			u8 crc[];
 		} __packed internal_w_cmd;
 		struct {
 			u8 addr[3];
 			__be32 data;
-			u8 crc[0];
+			u8 crc[];
 		} __packed w_cmd;
 	} u;
 } __packed;
Signature · 1 line
2.24.0