diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 24c498b6ac6188cff25d7c9cc01d8226a8537c82..1bc4677ff94056c814f49a8b4eba1c068cd00dd9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,3 +8,5 @@ stages:
 variables:
   DEBUG: 'TRUE'
   SOURCE_FOLDER: "libdsl libethernet libwifi"
+  RUN_CPPCHECK: "cppcheck --enable=all --error-exitcode=1 --suppress=unusedFunction --suppress=unusedStructMember --suppress=unusedLabel --suppress=variableScope --suppress=unreadVariable --suppress=knownConditionTrueFalse --suppress=constParameter --suppress=objectIndex ."
+  COMMON_IMAGE: iopsys/code-analysis:0.27
diff --git a/libeasy/event.c b/libeasy/event.c
index b8967ac029662b47b7482c63663a27f1ed631eeb..45a020aeaeaeeee02b4502d56db53bc18608467f 100644
--- a/libeasy/event.c
+++ b/libeasy/event.c
@@ -143,8 +143,8 @@ int LIBEASY_API easy_register_event(struct event_struct *req, void **handle)
 	ev->sock = sock;
 	ev->filter_event = req->filter_event;
 	nl_socket_disable_seq_check(sock);
-	err = nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM,
-				easy_default_event_handler, ev);
+	nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM,
+			    easy_default_event_handler, ev);
 
 	if ((err = genl_connect(sock)) < 0) {
 		libeasy_err("Error: %s\n", nl_geterror(err));
diff --git a/libeasy/tests/test_event.c b/libeasy/tests/test_event.c
index 139c121bb060295e855b6f1d74f0428d874c3cac..d13601cd96cecfd9ef00a149f88a181c0952040d 100644
--- a/libeasy/tests/test_event.c
+++ b/libeasy/tests/test_event.c
@@ -244,9 +244,6 @@ int main(int argc, char **argv)
 		}
 	}
 
-	argc -= optind;
-	argv += optind;
-
 	if (!jsonfile) {
 		libeasy_err("A valid events definition file needed!\n");
 		return -1;
diff --git a/libeasy/utils.c b/libeasy/utils.c
index 163d35481723f4684f0ec70cdc55f28b06a311b9..71135d78b24a6f2a4a6e78583a3a25f17229f3ec 100644
--- a/libeasy/utils.c
+++ b/libeasy/utils.c
@@ -299,7 +299,7 @@ int vsnsystemf(char *output, size_t output_size, const char *format, va_list ap)
 	size_t cmdline_size = 256;
 	char *cmdline = NULL, *new_cmdline;
 
-	cmdline = (char *)malloc(cmdline_size * sizeof(char));
+	cmdline = (char *)malloc(cmdline_size);
 	if (!cmdline)
 		goto out;
 
diff --git a/libethernet/bcm/bcm.c b/libethernet/bcm/bcm.c
index b507e250c06410f93c00cdbbe39d0b88c36f3481..e475dd053150d61b847ded16d2f6253da281c23d 100644
--- a/libethernet/bcm/bcm.c
+++ b/libethernet/bcm/bcm.c
@@ -76,7 +76,7 @@ static int bcm_eth_get_unit_port(const char *ifname, int *unit, int *port)
 		unsigned int portmap = data.port_map;
 
 		for (i = 0; i < 8 * sizeof(portmap); i++) {
-			if (!!(portmap & (1 << i))) {
+			if (!!(portmap & (1UL << i))) {
 				*port = i;
 				break;
 			}
@@ -293,7 +293,7 @@ static int read_eth_stats(const char *ifname, struct eth_stats *s)
 	memset(&data, 0, sizeof(struct ethswctl_data));
 	ret = bcm_eth_get_unit_port(ifname, &unit, &port);
 	if (ret)
-		return ret_proc == 0 ? 0 : -1;
+		return -1;
 
 	data.op = ETHSWEMACGET;
 	data.port = port;
@@ -304,7 +304,7 @@ static int read_eth_stats(const char *ifname, struct eth_stats *s)
 						sizeof(struct ethswctl_data));
 	if (ret != 0) {
 		libethernet_err("ioctl failed! ret = %d\n", ret);
-		return ret_proc == 0 ? 0 : -1;
+		return -1;
 	}
 
 	s->tx_bytes = data.emac_stats_s.tx_byte;
diff --git a/libwifi/chlist.c b/libwifi/chlist.c
index d5ba745c7e10a33f28a4e9a3147218f5808273c4..1dc8c9469ade65c6ebc44db12e854596e2a2c675 100644
--- a/libwifi/chlist.c
+++ b/libwifi/chlist.c
@@ -375,7 +375,7 @@ int get_valid_channels(const char *ifname, int band, int bw, const char *cc,
 		return -1;
 
 	if (band == 2) {
-		if (region > g_region_chlist_num)
+		if (region >= g_region_chlist_num)
 			return -1;
 
 		while (g_region_chlist[region].list[idx].start) {
@@ -391,7 +391,7 @@ int get_valid_channels(const char *ifname, int band, int bw, const char *cc,
 		return 0;
 	}
 
-	if (region > a_region_chlist_num)
+	if (region >= a_region_chlist_num)
 		return -1;
 
 	while (a_region_chlist[region].list[idx].start) {
@@ -644,6 +644,9 @@ int wifi_get_opclass_internal(enum wifi_regdomain reg, enum wifi_band b,
 		break;
 	}
 
+	if (!tab)
+		return -1;
+
 	for (i = 0; i < tabsize; i++) {
 		struct wifi_opclass *ptr = tab + i;
 
@@ -1588,7 +1591,7 @@ static int radio_get_supported_opclass(const char *name, int *num_opclass,
 
 	rd_opclass = calloc(max, sizeof(struct wifi_opclass));
 	if (WARN_ON(!rd_opclass))
-		return -1;
+		return -1;	//cppcheck-suppress memleak
 
 	rd_num_opclass = max;
 	ret  = _radio_get_supported_opclass(name, &rd_num_opclass, rd_opclass);
diff --git a/libwifi/modules/broadcom/bcm.c b/libwifi/modules/broadcom/bcm.c
index 7baa17bc2ee47d6128c836b305a015b4cbd443f5..df75925f1da87b131ab7aca1aa611e226229ad34 100644
--- a/libwifi/modules/broadcom/bcm.c
+++ b/libwifi/modules/broadcom/bcm.c
@@ -917,15 +917,16 @@ static int bcm_wifi_bss_info(const char *ifname, struct wifi_bss *bss)
 	if (res->chanspec == 0 || res->num_secs == 0)
 		return -1;
 
+	c = &res->secs[0];
 	if (swap) {
 		res->num_secs = BCMSWAP16(res->num_secs);
-		c = &res->secs[0];
 		c->duration = BCMSWAP32(c->duration);
 		c->congest_ibss = BCMSWAP32(c->congest_ibss);
 		c->congest_obss = BCMSWAP32(c->congest_obss);
 		c->interference = BCMSWAP32(c->interference);
 		c->timestamp = BCMSWAP32(c->timestamp);
 	}
+
 	if (c->duration) {
 		int ibss_pcnt, obss_pcnt, inter_pcnt;
 
@@ -2904,9 +2905,7 @@ const struct wifi_driver bcm_driver = {
 	.get_assoclist = bcm_get_assoclist,
 	.get_sta_info = bcm_get_sta_info,
 	.iface.probe_sta = bcm_probe_sta,
-#if 0
-	.get_sta_stats = bcm_get_sta_stats,
-#endif
+	/* .get_sta_stats = bcm_get_sta_stats, */
 	.iface.start_wps = bcm_start_wps,
 	.iface.stop_wps = bcm_stop_wps,
 	.iface.get_wps_status = bcm_get_wps_status,
diff --git a/libwifi/modules/broadcom/brcm.c b/libwifi/modules/broadcom/brcm.c
index 49ce2320359d52891c59c5d050d1813412a754b3..b2c2367902f7a939a19c38ae1b824c20ec70d4fd 100644
--- a/libwifi/modules/broadcom/brcm.c
+++ b/libwifi/modules/broadcom/brcm.c
@@ -955,14 +955,14 @@ static int register_event(const char *ifname, struct event_struct *ev,
 			  void **evhandle)
 {
 	struct event_ctx *ctx;
-	void *handle;
+	void *handle = NULL;
 	int ret;
 
 	libwifi_dbg("%s %s called family %s group %s\n", ifname, __func__, ev->family, ev->group);
 
 	ctx = calloc(1, sizeof(struct event_ctx));
 	if (WARN_ON(!ctx))
-		return -1;
+		return -1;	//cppcheck-suppress memleak
 
 	if (!strcmp(ev->family, "bcmwl"))
 		ret = bcmwl_register_event(ifname, ev, &handle);
diff --git a/libwifi/modules/broadcom/wlctrl.c b/libwifi/modules/broadcom/wlctrl.c
index 3f95d1f9d1e026f87837fabbcd1eb2db9cdff614..51f4422de38ce193a0650407d7777370832c6bee 100644
--- a/libwifi/modules/broadcom/wlctrl.c
+++ b/libwifi/modules/broadcom/wlctrl.c
@@ -364,7 +364,7 @@ static chanspec_t ctrlchannel_to_chanspec(const char *ifname, uint32_t ch,
 	enum wifi_band band;
 	char bwstr[16] = {0};
 	bool bw_sep = true;
-	int cs = 0;
+	unsigned int cs = 0;
 
 
 	if (bcmwl_get_oper_band(ifname, &band))
@@ -408,7 +408,7 @@ static int wl_ioctl_iface_get_beacon(const char *name, uint8_t *bcn, size_t *len
 {
 	char buf[WLC_IOCTL_MAXLEN] = { 0 };
 	int ret;
-	size_t bcn_len;
+	uint32_t bcn_len;
 
 	if (WARN_ON(!bcn) || WARN_ON(!len) || WARN_ON(*len == 0))
 		return -EINVAL;
@@ -420,9 +420,9 @@ static int wl_ioctl_iface_get_beacon(const char *name, uint8_t *bcn, size_t *len
 	if (WARN_ON(ret))
 		return ret;
 
-	bcn_len = (size_t)wl_swap_32(name, *(uint32_t*)buf);
+	bcn_len = wl_swap_32(name, *(uint32_t*)buf);
 
-	if (WARN_ON(bcn_len <= 0 || *len < bcn_len )) {
+	if (WARN_ON(bcn_len == 0 || *len < bcn_len )) {
 		*len = 0;
 		return -1;
 	}
@@ -610,7 +610,7 @@ static int wl_cli_get_noise(const char *name, int *noise)
 
 int bcmwl_radio_get_noise(const char *name, int *noise)
 {
-	uint32_t val;
+	uint32_t val = 0;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
@@ -1101,7 +1101,7 @@ static int bcmwl_radio_channels_update_survey(const char *name, struct chan_entr
 #else
 int bcmwl_radio_get_noise(const char *name, int *noise)
 {
-	uint32_t val;
+	uint32_t val = 0;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
@@ -1140,7 +1140,7 @@ int bcmwl_radio_get_country(const char *name, char *alpha2)
 static int bcmwl_get_rssi(const char *name, int8_t *rssi)
 {
 	int ret;
-	uint32_t val;
+	uint32_t val = 0;
 	struct wl_arg arg = {
 		.ifname = name,
 		.cmd = WLC_GET_RSSI,
@@ -1431,7 +1431,7 @@ int bcmwl_iface_chan_switch(const char *ifname, struct chan_switch_param *param)
 static int bcmwl_get_macmode(const char *name, int *macmode)
 {
 	int ret;
-	uint32_t val;
+	uint32_t val = 0;
 	struct wl_arg arg = {
 		.ifname = name,
 		.cmd = WLC_GET_MACMODE,
@@ -1584,7 +1584,7 @@ static int bcmwl_iface_update_maclist(const char *name, uint8_t *sta, bool remov
 	if (changed) {
 		dst_maclist->count = swap ? BCMSWAP32(count) : count;
 
-		struct wl_arg arg = {
+		struct wl_arg arg2 = {
 			.ifname = name,
 			.cmd = WLC_SET_MACLIST,
 			.param = &dbuf,
@@ -1595,7 +1595,7 @@ static int bcmwl_iface_update_maclist(const char *name, uint8_t *sta, bool remov
 		};
 
 		/* Set MAC list */
-		ret = wl_ioctl(&arg);
+		ret = wl_ioctl(&arg2);
 	} else {
 		libwifi_dbg("[%s] %s : no change on MAC deny list\n", name, __func__);
 	}
@@ -1991,7 +1991,7 @@ int bcmwl_iface_get_beacon_ies(const char *name, uint8_t *ies, int *len)
 	ies_len = bcn_len - ((uint8_t *)&bf->cap_info - bcn + 2);
 	bcn_ies = bf->var;
 
-	if (WARN_ON(ies_len <= 0 || *len < ies_len)) {
+	if (WARN_ON(ies_len == 0 || *len < ies_len)) {
 		*len = 0;
 		return -1;
 	}
@@ -2168,7 +2168,7 @@ int bcmwl_ap_get_oper_stds(const char *name, uint8_t *std)
 
 int bcmwl_get_oper_band(const char *name, enum wifi_band *band)
 {
-	uint32_t val, b;
+	uint32_t val = 0, b;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
@@ -2427,13 +2427,14 @@ int bcmwl_iface_get_exp_tp(const char *ifname, uint8_t *macaddr, struct wifi_sta
 	 *  - we can fill maximum 85% of airtime - best case
 	 *  - Reserve 20% for TCP ACK.
 	 */
-	sta->est_rx_thput = (recent_rx_rate.rate * 85) / 100;
-	sta->est_tx_thput = (recent_tx_rate.rate * 85) / 100;
+	//sta->est_rx_thput = (recent_rx_rate.rate * 85) / 100;
+	//sta->est_tx_thput = (recent_tx_rate.rate * 85) / 100;
 
 	sta->est_rx_thput = (recent_rx_rate.rate * 8) / 10;
 	sta->est_tx_thput = (recent_tx_rate.rate * 8) / 10;
 
-	libwifi_dbg("[%s] " MACSTR " exp_max_tx %d Mbps exp_max_rx %d Mbps\n", ifname, MAC2STR(macaddr), sta->est_tx_thput, sta->est_rx_thput);
+	libwifi_dbg("[%s] " MACSTR " exp_max_tx %d Mbps exp_max_rx %d Mbps\n",
+		    ifname, MAC2STR(macaddr), sta->est_tx_thput, sta->est_rx_thput);
 
 	return 0;
 }
@@ -2616,7 +2617,7 @@ int bcmwl_radio_channels_info(const char *ifname, struct chan_entry *channel, in
 
 int bcmwl_radio_get_beacon_int(const char *name, uint32_t *beacon_int)
 {
-	int bint;
+	int bint = 0;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
@@ -2638,7 +2639,7 @@ int bcmwl_radio_get_beacon_int(const char *name, uint32_t *beacon_int)
 
 int bcmwl_radio_get_dtim(const char *name, uint32_t *dtim_period)
 {
-	int dtim;
+	int dtim = 0;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
@@ -2840,6 +2841,7 @@ int bcmwl_radio_get_gi(const char *name, int he, enum wifi_guard *gi)
 			break;
 		case 5:
 			*gi = (he == 1) ? WIFI_4xLTF_GI3200 : WIFI_SGI;
+			break;
 		default:
 			*gi = WIFI_GI_UNKNOWN;
 			break;
@@ -3233,7 +3235,7 @@ int bcmwl_register_event(const char *ifname, struct event_struct *ev,
 
 	ctx = calloc(1, sizeof(*ctx));
 	if (WARN_ON(!ctx))
-		return ret;
+		return ret;	//cppcheck-suppress memleak
 
 	ev->fd_monitor = bcmwl_event_socket_open(ifname);
 	if (ev->fd_monitor == -1) {
@@ -3358,7 +3360,7 @@ static int bcmwl_event_handle(const char *ifname, bcm_event_t *event, int size,
 		 event->event.ifname, event_name, macaddr);
 
 	if (reason != -1)
-		snprintf(buf + strlen(buf), buf_size, ", \"reason\":%d", reason);
+		snprintf(buf + strlen(buf), buf_size, ", \"reason\":%u", reason);
 
 
 	if (datalen > 0)
@@ -3823,10 +3825,12 @@ static int bcmwl_event_bit(const char *ifname, unsigned int bit, int set)
 
 	ext = calloc(1, sizeof(*ext) + mask_len);
 	if (WARN_ON(!ext))
-		return -1;
+		return -1;	//cppcheck-suppress memleak
 
-	if (WARN_ON((bit / 8) >= mask_len))
+	if (WARN_ON((bit / 8) >= mask_len)) {
+		free(ext);
 		return -1;
+	}
 
 	ext->ver = EVENTMSGS_VER;
 	ext->len = mask_len;
@@ -3870,7 +3874,7 @@ int bcmwl_driver_info(const char *name, struct wifi_metainfo *info)
 
 int bcmwl_iface_get_wpa_auth(const char *name, uint32_t *wpa_auth)
 {
-	uint32_t val;
+	uint32_t val = 0;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
@@ -3892,7 +3896,7 @@ int bcmwl_iface_get_wpa_auth(const char *name, uint32_t *wpa_auth)
 
 int bcmwl_iface_get_auth(const char *name, uint32_t *auth)
 {
-	uint32_t val;
+	uint32_t val = 0;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
@@ -3914,7 +3918,7 @@ int bcmwl_iface_get_auth(const char *name, uint32_t *auth)
 
 int bcmwl_iface_get_wsec(const char *name, uint32_t *enc)
 {
-	uint32_t val;
+	uint32_t val = 0;
 	int ret;
 	struct wl_arg arg = {
 		.ifname = name,
diff --git a/libwifi/modules/intel/intel.c b/libwifi/modules/intel/intel.c
index 3315f4629dc97d1a7f8e342aa153b177445a68aa..76d011db70370e1dd61d4df6f19cfd6937c80d87 100644
--- a/libwifi/modules/intel/intel.c
+++ b/libwifi/modules/intel/intel.c
@@ -1126,7 +1126,7 @@ int intel_req_bss_transition(const char *ifname, unsigned char *sta,
 	snprintf(buf + strlen(buf), sizeof(buf), "%s", "pref=1 ");
 	snprintf(buf + strlen(buf), sizeof(buf), "%s", "disassoc_imminent=1 ");
 	if (tmo)
-		snprintf(buf + strlen(buf), sizeof(buf), "valid_int=%d ", tmo);
+		snprintf(buf + strlen(buf), sizeof(buf), "valid_int=%u ", tmo);
 
 	if (bsss_nr > 5)
 		bsss_nr = 5;
diff --git a/libwifi/modules/mac80211/mac80211.c b/libwifi/modules/mac80211/mac80211.c
index adfbf362b8f4323edbbd9052c38a363333c17adb..c2570fb424c14cf8346b5656f9a71875257d5f96 100644
--- a/libwifi/modules/mac80211/mac80211.c
+++ b/libwifi/modules/mac80211/mac80211.c
@@ -450,8 +450,8 @@ static int radio_channels_info(const char *name, struct chan_entry *channel, int
 		return ret;
 
 	WARN_ON(nlwifi_get_country(name, cc));
-	if (!strcmp(cc, "US") || !strcmp(cc, "JP"))
-		return ret;
+	if (!strcmp(cc, "US") || !strcmp(cc, "JP"))	/* FIXME-CR: other non-ETSI countries */
+		return 0;
 
 	/* Check weather channels - just in case of regulatory issue */
 	for (i = 0; i < *num; i++) {
diff --git a/libwifi/modules/nlwifi/nlwifi.c b/libwifi/modules/nlwifi/nlwifi.c
index 551c042cf4d65ec62df23ac8368e09dcfa1265c9..bf6939a2adfafa5fedb824eb7c3224b8392e10a5 100644
--- a/libwifi/modules/nlwifi/nlwifi.c
+++ b/libwifi/modules/nlwifi/nlwifi.c
@@ -421,7 +421,7 @@ static int nlwifi_cmd(const char *name, struct nlwifi_ctx *ctx)
 	}
 
 	nl = nlwifi_socket();
-	if (nl <= 0)
+	if (!nl)
 		goto out;
 
 	msg = nlwifi_alloc_msg(nl, ctx->cmd, ctx->flags, 0);
@@ -491,7 +491,7 @@ int nlwifi_scan(const char *ifname, struct scan_param *p)
 	}
 
 	nl = nlwifi_socket();
-	if (nl <= 0)
+	if (!nl)
 		goto out;
 
 	msg = nlwifi_alloc_msg(nl, NL80211_CMD_TRIGGER_SCAN, 0, 0);
@@ -799,7 +799,7 @@ static int nlwifi_get_bandwidth_from_ie(uint8_t *ies, size_t len,
 
 				if (cfs1 == 0) {
 					*bw = BW80;
-				} else if (cfs1 > 0){
+				} else {
 					if (cfs1 - cfs0 == 8)
 						*bw = BW160;
 					else if (cfs1 - cfs0 == 16)
@@ -928,7 +928,7 @@ int nlwifi_get_chan(const char *ifname, uint32_t *channel)
 	*channel = ieee80211_frequency_to_channel(freq);
 	libwifi_dbg("freq = %u chan %u\n", freq, *channel);
 
-	return ret;
+	return 0;
 }
 
 static int nlwifi_get_supp_channels_cb(struct nl_msg *msg, void *data)
@@ -1072,7 +1072,7 @@ int nlwifi_get_supp_channels(const char *name, uint32_t *chlist, int *num,
 
 	*num = data.num;
 
-	return ret;
+	return 0;
 }
 
 int nlwifi_get_bandwidth(const char *ifname, enum wifi_bw *bandwidth)
@@ -1111,7 +1111,7 @@ int nlwifi_get_bandwidth(const char *ifname, enum wifi_bw *bandwidth)
 
 	libwifi_dbg("nlwifi bandwidth = %d\n", *bandwidth);
 
-	return ret;
+	return 0;
 }
 
 int nlwifi_get_channel(const char *name, uint32_t *channel,
@@ -1165,7 +1165,7 @@ int nlwifi_get_mode(const char *ifname, enum wifi_mode *mode)
 	*mode = ieee80211_type_to_wifi_mode((enum nl80211_iftype) nl_iftype);
 	libwifi_dbg("nl_type=%d wifi_mode=%d\n", nl_iftype, *mode);
 
-	return ret;
+	return 0;
 }
 
 static int _nlwifi_vendor_cmdresp(struct nl_msg *msg, void *resp)
@@ -1189,7 +1189,7 @@ static int _nlwifi_vendor_cmdresp(struct nl_msg *msg, void *resp)
 	}
 
 	nla_for_each_nested(nl_iter, nl_resp, iter) {
-		memcpy(res->data + *res->len, nla_data(nl_iter),
+		memcpy((uint8_t *)res->data + *res->len, nla_data(nl_iter),
 						nla_len(nl_iter));
 		*res->len += nla_len(nl_iter);
 	}
@@ -1222,7 +1222,7 @@ int nlwifi_vendor_cmd(const char *ifname, uint32_t vid, uint32_t subcmd,
 	}
 
 	nl = nlwifi_socket();
-	if (nl <= 0)
+	if (!nl)
 		goto out;
 
 	msg = nlwifi_alloc_msg(nl, NL80211_CMD_VENDOR, 0, 0);
@@ -1546,7 +1546,7 @@ int nlwifi_radio_info(const char *name, struct wifi_radio *radio)
 
 	nlwifi_phy_to_netdev(name, netdev, sizeof(netdev));
 	if (WARN_ON(nlwifi_get_survey(netdev, &survey_data)))
-		return ret;
+		return 0;
 
 	radio->channel = ieee80211_frequency_to_channel(survey.freq);
 	radio->diag.cca_time = survey.active_time * 1000;
@@ -1556,7 +1556,7 @@ int nlwifi_radio_info(const char *name, struct wifi_radio *radio)
 	radio->num_iface = WIFI_IFACE_MAX_NUM;
 	nlwifi_get_phy_wifi_ifaces( name, radio->iface, &radio->num_iface);
 
-	return ret;
+	return 0;
 }
 
 static int nlwifi_get_assoclist_cb(struct nl_msg *msg, void *assoclist)
@@ -1626,7 +1626,7 @@ int nlwifi_get_assoclist(const char *ifname, uint8_t *stas, int *num_stas)
 
 	*num_stas = stalist.i;
 
-	return ret;
+	return 0;
 }
 
 static int nlwifi_bitrate_attrs(struct nlattr *attr, struct wifi_rate *rate)
@@ -1928,7 +1928,7 @@ int nlwifi_get_sta_info(const char *ifname, uint8_t *addr, struct wifi_sta *info
 	return nlwifi_cmd(ifname, &ctx);
 }
 
-int nlwifi_sta_get_stats(const char *ifname, struct wifi_sta_stats *s)
+int nlwifi_sta_get_stats(const char *ifname, struct wifi_sta_stats *stats)
 {
 	struct wifi_sta station = {};
 	struct stainfo {
@@ -1954,9 +1954,9 @@ int nlwifi_sta_get_stats(const char *ifname, struct wifi_sta_stats *s)
 	if (ret)
 		return ret;
 
-	memcpy(s, &(sta.s->stats), sizeof(struct wifi_sta_stats));
+	memcpy(stats, &(sta.s->stats), sizeof(struct wifi_sta_stats));
 
-	return ret;
+	return 0;
 }
 
 static int nlwifi_get_scan_results_cb(struct nl_msg *msg, void *sres)
@@ -2070,7 +2070,7 @@ static int nlwifi_get_scan_results_cb(struct nl_msg *msg, void *sres)
 		    e->rsn.wpa_versions, e->rsn.pair_ciphers, e->rsn.group_cipher,
 		    e->rsn.akms, e->rsn.rsn_caps);
 
-	ret = nlwifi_get_ie(ie, ie_len, IE_BSS_LOAD, &e->load);
+	nlwifi_get_ie(ie, ie_len, IE_BSS_LOAD, &e->load);
 
 	ret = nlwifi_get_ie(ie, ie_len, IE_EXT_CAP, &e->caps.ext);
 	if (!ret)
@@ -2134,7 +2134,7 @@ int nlwifi_get_scan_results(const char *ifname, struct wifi_bss *bsss,
 	*num = scanres.i;
 	libwifi_dbg("Num scanned bsss = %d   bsss = %p\n", *num, bsss);
 
-	return ret;
+	return 0;
 }
 
 
@@ -2160,7 +2160,7 @@ int nlwifi_get_country(const char *name, char *alpha2)
 	int ret = -1;
 
 	nl = nlwifi_socket();
-	if (nl <= 0)
+	if (!nl)
 		goto out;
 
 	msg = nlwifi_alloc_msg(nl, NL80211_CMD_GET_REG, 0, 0);
@@ -2286,7 +2286,7 @@ int nlwifi_get_noise(const char *name, int *noise)
 		return -1;
 
 	*noise = survey.noise;
-	return ret;
+	return 0;
 }
 
 int nlwifi_get_supp_stds(const char *name, uint8_t *std)
@@ -2434,11 +2434,11 @@ int nlwifi_channels_info(const char *name, struct chan_entry *channel, int *num)
 	entry_num = *num;
 	entry = calloc(entry_num, sizeof(*entry));
 	if (WARN_ON(!entry))
-		return ret;
+		return -1;	//cppcheck-suppress memleak
 
 	if (WARN_ON(nlwifi_surveys_get(name, entry, &entry_num))) {
 		free(entry);
-		return ret;
+		return -1;
 	}
 
 	for (i = 0; i < *num; i++) {
@@ -2506,7 +2506,7 @@ int nlwifi_get_oper_band(const char *name, enum wifi_band *band)
 
 int nlwifi_get_4addr(const char *ifname, bool *enabled)
 {
-	uint8_t en;
+	uint8_t en = 0;
 	int ret;
 	struct cmd_respdata res = {
 		.attr = NL80211_ATTR_4ADDR,
@@ -2689,8 +2689,8 @@ int nlwifi_register_event(const char *ifname, struct event_struct *req, void **h
 	wev->sock = sock;
 
 	nl_socket_disable_seq_check(sock);
-	err = nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM,
-				ev->handler, wev);
+	nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM,
+			    ev->handler, wev);
 
 	if ((err = genl_connect(sock)) < 0) {
 		libwifi_err("%s: %s\n", __func__, nl_geterror(err));
diff --git a/libwifi/modules/test/test.c b/libwifi/modules/test/test.c
index 8c967d41b3b9d0e4357faf0b4b58354f2c8a7a8e..fb286ff1208f21794c83ed50feb30376479dc8eb 100644
--- a/libwifi/modules/test/test.c
+++ b/libwifi/modules/test/test.c
@@ -470,8 +470,7 @@ int test_req_bss_transition(const char *ifname, unsigned char *sta,
 				bsss[offset + 0], bsss[offset + 1], bsss[offset + 2],
 				bsss[offset + 3], bsss[offset + 4], bsss[offset + 5]);
 		strncat(bsss_str, macstr, sizeof(macstr));
-		if (i < bsss_nr)
-			strncat(bsss_str, ",", 1);
+		strncat(bsss_str, ",", 1);
 	}
 
 	strncat(bsss_str, "]", 1);
@@ -928,9 +927,7 @@ const struct wifi_driver test_driver = {
 	.register_event = test_register_event,
 	.iface.get_caps = test_ap_get_caps,
 	.radio.get_caps = test_radio_get_caps,
-#if 0
-	.vendor_cmd = test_vendor_cmd, // leave out
-#endif
+	/* .vendor_cmd = test_vendor_cmd, */
 	.iface.get_neighbor_list = test_get_neighbor_list,
 	.iface.add_neighbor = test_add_neighbor,
 	.iface.del_neighbor = test_del_neighbor,
diff --git a/libwifi/modules/wpactrl/wpactrl_util.c b/libwifi/modules/wpactrl/wpactrl_util.c
index 09d30ccc6df586a1f3988d602fb0656719330e9e..fe7e8ad4ed8d68c99755e517f534198e63b3fa60 100644
--- a/libwifi/modules/wpactrl/wpactrl_util.c
+++ b/libwifi/modules/wpactrl/wpactrl_util.c
@@ -87,7 +87,7 @@ static int get_param(const char *buf, const char *param, char *value, size_t val
 		loc = strstr(line, param);
 		if (!loc || loc != line)
 			continue;
-		snprintf(search_str, sizeof(search_str), "%s=%%%d[^\n]s", param, value_max);
+		snprintf(search_str, sizeof(search_str), "%s=%%%zu[^\n]s", param, value_max);
 
 		if (WARN_ON(sscanf(line, search_str, value) != 1)) {
 			free(origin_p);
@@ -1094,7 +1094,7 @@ int hostapd_cli_iface_get_neighbor_list(const char *ifname, struct nbr *nbrs, in
 	/* make sure we have place for show_neighbor output */
 	buf = calloc(*nr, 256);
 	if (WARN_ON(!buf))
-		return -1;
+		return -1;	//cppcheck-suppress memleak
 
 	ret = hostapd_cli_get(ifname, "show_neighbor", buf, *nr * 256);
 	if (WARN_ON(ret)) {
@@ -1278,22 +1278,24 @@ int hostapd_cli_iface_req_bss_transition(const char *ifname, unsigned char *sta,
 
 	nbrs = calloc(nr, sizeof(*nbr));
 	if (WARN_ON(!nbrs))
-		return -1;
+		return -1;	//cppcheck-suppress memleak
 
 	if (wifi_get_neighbor_list(ifname, nbrs, &nr)) {
 		free(nbrs);
 		return -1;
 	}
 
-	if (WARN_ON(bsss_nr && !nr))
+	if (WARN_ON(bsss_nr && !nr)) {
+		free(nbrs);
 		return -1;
+	}
 
 	buflen = 256 + bsss_nr * 256;
 
 	buf = malloc(buflen);
 	if (WARN_ON(!buf)) {
 		free(nbrs);
-		return -1;
+		return -1;	//cppcheck-suppress memleak
 	}
 
 	len = 0;
@@ -1326,7 +1328,7 @@ int hostapd_cli_iface_req_bss_transition(const char *ifname, unsigned char *sta,
 
 	if (params->valid_int)
 		len += snprintf(buf + len, buflen - len,
-				"valid_int=%hu", params->valid_int);
+				"valid_int=%hhu", params->valid_int);
 
 	if (params->bss_term)
 		len += snprintf(buf + len, buflen - len,
@@ -1672,7 +1674,7 @@ int supplicant_cli_get_oper_std(const char *ifname, uint8_t *std)
 		libwifi_warn("%s ieee80211n parameter not found in buffer [%s]!\n",
 		__func__, buf);
 	}
-	if (WARN_ON(sscanf(val, "%1hhd", &n_state) != 1)) {
+	if (WARN_ON(sscanf(val, "%1hhu", &n_state) != 1)) {
 		libwifi_warn("Failed to parse ieee80211n parameter\n");
 	}
 
@@ -1680,7 +1682,7 @@ int supplicant_cli_get_oper_std(const char *ifname, uint8_t *std)
 		libwifi_warn("%s ieee80211ac parameter not found in buffer [%s]!\n",
 		__func__, buf);
 	}
-	if (WARN_ON(sscanf(val, "%1hhd", &ac_state) != 1)) {
+	if (WARN_ON(sscanf(val, "%1hhu", &ac_state) != 1)) {
 		libwifi_warn("Failed to parse ieee80211ac parameter\n");
 	}
 
diff --git a/libwifi/util.c b/libwifi/util.c
index 04def986605466e9a4cffeb627e1cbf83a51e03d..52700705f2845589a0c92c41cfddc174399981f0 100644
--- a/libwifi/util.c
+++ b/libwifi/util.c
@@ -45,7 +45,7 @@ bool __is_any_bit_set(unsigned int v, int sizeof_v, ...)
 
 	while (i++ < sizeof_v) {
 		b = va_arg(args, int);
-		if (b < 0 || b > sizeof_v - 1)
+		if (b > sizeof_v - 1)
 			goto out;
 
 		if (!!(v & BIT(b))) {
@@ -70,7 +70,7 @@ bool __is_all_bits_set(unsigned int v, int sizeof_v, ...)
 
 	while (i++ < sizeof_v) {
 		b = va_arg(args, int);
-		if (b < 0 || b > sizeof_v - 1)
+		if (b > sizeof_v - 1)
 			goto out;
 
 		if (!(v & BIT(b))) {
@@ -97,9 +97,7 @@ int wifi_channel_to_freq(int chan)
 			2484;
 
 	if (chan > 32 && chan <= 196)
-		return (chan >= 182 && chan <= 196) ?
-				4000 + chan * 5 :
-				5000 + chan * 5;
+		return (chan >= 182) ? 4000 + chan * 5 : 5000 + chan * 5;
 
 	return -EINVAL;
 }
@@ -185,7 +183,7 @@ uint8_t *wifi_find_vsie(uint8_t *ies, size_t len, uint8_t *oui,
 			if (type != 0xff && vsie[5] != type)
 				continue;
 
-			if (stype == 0xff || (stype != 0xff && vsie[6] == stype))
+			if (stype == 0xff || vsie[6] == stype)
 				return vsie;
 		}
 	}
@@ -773,9 +771,7 @@ int wifi_parse_wpa_ie(uint8_t *iebuf, size_t len, struct wifi_rsne *r)
 			return -1;
 		}
 		offset += 4;
-	}
 
-	if (wpa_version == 1) {
 		r->wpa_versions |= WPA_VERSION1;
 	} else {
 		r->wpa_versions |= WPA_VERSION2;
diff --git a/libwifi/wifi.h b/libwifi/wifi.h
index 14e980c04cc6acb8fe0ace5ffdc5ec9f4f814576..8255bc7e7c95346488f99c5123d11a0a1da84b96 100644
--- a/libwifi/wifi.h
+++ b/libwifi/wifi.h
@@ -2217,7 +2217,7 @@ const int *chan2list(int chan, int bw);
 /** Iterator for information elements */
 #define wifi_foreach_ie(e, _iebuf, _len)				\
 	for ((e) = (_iebuf);						\
-		(e)[1] >= 0 && (_iebuf) + (_len) - (e) - 2 - (e)[1] >= 0;	\
+		(_iebuf) + (_len) - (e) - 2 - (e)[1] >= 0;		\
 		(e) += 2 + (e)[1])
 
 /* Get list of APIs that this library supports */