struct wid describes a WID, the TLV this driver sends to the firmware: a 16-bit id, a length, and a payload. The length and the payload pointer are signed (s32 size, s8 *val). That is unusual for a TLV, and a negative length or a sign-extended value is easy to miss at the call sites. Make size a u32 and val a u8 *. Payloads are byte buffers everywhere in the driver. Of the 24 casts to s8 *, 17 become casts to u8 *, and 7 are dropped because the variable is already a u8. The (s32) cast on the SSID list length in wilc_scan() is dropped as well, since valuesize is already a u32. The channel in handle_remain_on_chan() is a u16 stored into one byte, so its (s8) cast becomes (u8) to keep the truncation visible. power_mode in wilc_set_power_mgmt() becomes a u8, so that &power_mode still matches val without a cast. It only holds WILC_FW_NO_POWERSAVE (0) or WILC_FW_MIN_FAST_PS (1). The RSSI stays s8 in struct rf_info and in the wilc_get_rssi() argument, since the sign is part of the value. The two places that point a WID at it, wilc_get_statistics() and wilc_get_rssi(), cast it to u8 *. The block that fills WID_SET_MFP is re-indented with tabs, since checkpatch flags its existing spaces once the line is touched. No functional change intended. The build uses -Wno-pointer-sign, so this does not fix a warning; it makes the field types match the buffers the callers pass. On x86_64 the generated code differs only in handle_set_mcast_filter() and wilc_add_beacon(), where wid.size is passed to kmalloc() and kzalloc() and is now zero-extended instead of sign-extended. The values there are far below 2^31. Suggested-by: Jeff Johnson Link: https://lore.kernel.org/all/accee45c-7cae-48fc-b868-b7404b8c061c@oss.qualcomm.com/ Signed-off-by: Yasuaki Torimaru --- Testing: built drivers/net/wireless/microchip/wilc1000/ with W=1 on top of wireless-next (18d0bedbb5f0), before and after this patch, with WILC1000_SDIO=m and WILC1000_SPI=m: x86_64, i386 and arm64 with GCC 15.3.0, and x86_64 with clang 21.1.8. No warnings in any of them. Comparing objdump -d per function, the only code changes are the two sign extensions mentioned above (x86_64 with GCC and clang, and arm64), plus, on arm64, the operands of two equality compares in wilc_send_config_pkt() swapped. i386 output is identical. The rest is addresses and alignment padding. Not tested on hardware. Tool use: Claude Code with claude-mythos-5-2 and claude-opus-5-5 wrote this change and the draft of this message, after Jeff Johnson's review comment, and ran the build and the object comparison above. I reviewed the change and the results. drivers/net/wireless/microchip/wilc1000/hif.c | 64 +++++++++---------- .../net/wireless/microchip/wilc1000/wlan_if.h | 4 +- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/drivers/net/wireless/microchip/wilc1000/hif.c b/drivers/net/wireless/microchip/wilc1000/hif.c index 60fe5f08964f3..62d5c24536bda 100644 --- a/drivers/net/wireless/microchip/wilc1000/hif.c +++ b/drivers/net/wireless/microchip/wilc1000/hif.c @@ -127,7 +127,7 @@ static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt) abort_running_scan = 1; wid.id = WID_ABORT_RUNNING_SCAN; wid.type = WID_CHAR; - wid.val = (s8 *)&abort_running_scan; + wid.val = &abort_running_scan; wid.size = sizeof(char); result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); @@ -201,28 +201,28 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, request->ssids[i].ssid_len); buffer += request->ssids[i].ssid_len; } - wid_list[index].size = (s32)(valuesize + 1); + wid_list[index].size = valuesize + 1; index++; } } wid_list[index].id = WID_INFO_ELEMENT_PROBE; wid_list[index].type = WID_BIN_DATA; - wid_list[index].val = (s8 *)request->ie; + wid_list[index].val = (u8 *)request->ie; wid_list[index].size = request->ie_len; index++; wid_list[index].id = WID_SCAN_TYPE; wid_list[index].type = WID_CHAR; wid_list[index].size = sizeof(char); - wid_list[index].val = (s8 *)&scan_type; + wid_list[index].val = &scan_type; index++; if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) { wid_list[index].id = WID_PASSIVE_SCAN_TIME; wid_list[index].type = WID_SHORT; wid_list[index].size = sizeof(u16); - wid_list[index].val = (s8 *)&request->duration; + wid_list[index].val = (u8 *)&request->duration; index++; scan_timeout = (request->duration * ch_list_len) + 500; @@ -247,7 +247,7 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, wid_list[index].id = WID_START_SCAN_REQ; wid_list[index].type = WID_CHAR; wid_list[index].size = sizeof(char); - wid_list[index].val = (s8 *)&scan_source; + wid_list[index].val = &scan_source; index++; hif_drv->usr_scan_req.scan_result = scan_result_fn; @@ -280,11 +280,11 @@ static int wilc_send_connect_wid(struct wilc_vif *vif) struct wilc_join_bss_param *bss_param = conn_attr->param; - wid_list[wid_cnt].id = WID_SET_MFP; - wid_list[wid_cnt].type = WID_CHAR; - wid_list[wid_cnt].size = sizeof(char); - wid_list[wid_cnt].val = (s8 *)&conn_attr->mfp_type; - wid_cnt++; + wid_list[wid_cnt].id = WID_SET_MFP; + wid_list[wid_cnt].type = WID_CHAR; + wid_list[wid_cnt].size = sizeof(char); + wid_list[wid_cnt].val = (u8 *)&conn_attr->mfp_type; + wid_cnt++; wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE; wid_list[wid_cnt].type = WID_BIN_DATA; @@ -295,13 +295,13 @@ static int wilc_send_connect_wid(struct wilc_vif *vif) wid_list[wid_cnt].id = WID_11I_MODE; wid_list[wid_cnt].type = WID_CHAR; wid_list[wid_cnt].size = sizeof(char); - wid_list[wid_cnt].val = (s8 *)&conn_attr->security; + wid_list[wid_cnt].val = &conn_attr->security; wid_cnt++; wid_list[wid_cnt].id = WID_AUTH_TYPE; wid_list[wid_cnt].type = WID_CHAR; wid_list[wid_cnt].size = sizeof(char); - wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type; + wid_list[wid_cnt].val = (u8 *)&conn_attr->auth_type; wid_cnt++; wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED; @@ -358,7 +358,7 @@ static void handle_connect_timeout(struct work_struct *work) wid.id = WID_DISCONNECT; wid.type = WID_CHAR; - wid.val = (s8 *)&dummy_reason_code; + wid.val = (u8 *)&dummy_reason_code; wid.size = sizeof(char); result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); @@ -738,7 +738,7 @@ int wilc_disconnect(struct wilc_vif *vif) wid.id = WID_DISCONNECT; wid.type = WID_CHAR; - wid.val = (s8 *)&dummy_reason_code; + wid.val = (u8 *)&dummy_reason_code; wid.size = sizeof(char); result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); @@ -786,31 +786,31 @@ int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats) wid_list[wid_cnt].id = WID_LINKSPEED; wid_list[wid_cnt].type = WID_CHAR; wid_list[wid_cnt].size = sizeof(char); - wid_list[wid_cnt].val = (s8 *)&stats->link_speed; + wid_list[wid_cnt].val = &stats->link_speed; wid_cnt++; wid_list[wid_cnt].id = WID_RSSI; wid_list[wid_cnt].type = WID_CHAR; wid_list[wid_cnt].size = sizeof(char); - wid_list[wid_cnt].val = (s8 *)&stats->rssi; + wid_list[wid_cnt].val = (u8 *)&stats->rssi; wid_cnt++; wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT; wid_list[wid_cnt].type = WID_INT; wid_list[wid_cnt].size = sizeof(u32); - wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt; + wid_list[wid_cnt].val = (u8 *)&stats->tx_cnt; wid_cnt++; wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT; wid_list[wid_cnt].type = WID_INT; wid_list[wid_cnt].size = sizeof(u32); - wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt; + wid_list[wid_cnt].val = (u8 *)&stats->rx_cnt; wid_cnt++; wid_list[wid_cnt].id = WID_FAILED_COUNT; wid_list[wid_cnt].type = WID_INT; wid_list[wid_cnt].size = sizeof(u32); - wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt; + wid_list[wid_cnt].val = (u8 *)&stats->tx_fail_cnt; wid_cnt++; result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt); @@ -894,7 +894,7 @@ static int handle_remain_on_chan(struct wilc_vif *vif, return -ENOMEM; wid.val[0] = remain_on_chan_flag; - wid.val[1] = (s8)hif_remain_ch->ch; + wid.val[1] = (u8)hif_remain_ch->ch; result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); kfree(wid.val); @@ -1126,7 +1126,7 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len, wid_list[0].id = WID_11I_MODE; wid_list[0].type = WID_CHAR; wid_list[0].size = sizeof(char); - wid_list[0].val = (s8 *)&cipher_mode; + wid_list[0].val = &cipher_mode; key_buf = kzalloc_flex(*key_buf, key, t_key_len); if (!key_buf) @@ -1175,7 +1175,7 @@ int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len, wid.id = WID_ADD_PTK; wid.type = WID_STR; wid.size = sizeof(*key_buf) + t_key_len; - wid.val = (s8 *)key_buf; + wid.val = (u8 *)key_buf; result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); kfree(key_buf); } @@ -1206,7 +1206,7 @@ int wilc_add_igtk(struct wilc_vif *vif, const u8 *igtk, u8 igtk_key_len, wid.id = WID_ADD_IGTK; wid.type = WID_STR; wid.size = sizeof(*key_buf) + t_key_len; - wid.val = (s8 *)key_buf; + wid.val = (u8 *)key_buf; result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); kfree(key_buf); @@ -1250,7 +1250,7 @@ int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len, wid_list[0].id = WID_11I_MODE; wid_list[0].type = WID_CHAR; wid_list[0].size = sizeof(char); - wid_list[0].val = (s8 *)&cipher_mode; + wid_list[0].val = &cipher_mode; wid_list[1].id = WID_ADD_RX_GTK; wid_list[1].type = WID_STR; @@ -1413,7 +1413,7 @@ s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val) wid.id = WID_GET_INACTIVE_TIME; wid.type = WID_INT; - wid.val = (s8 *)out_val; + wid.val = (u8 *)out_val; wid.size = sizeof(u32); result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1); if (result) @@ -1435,7 +1435,7 @@ int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level) wid.id = WID_RSSI; wid.type = WID_CHAR; wid.size = sizeof(char); - wid.val = rssi_level; + wid.val = (u8 *)rssi_level; result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1); if (result) netdev_err(vif->ndev, "Failed to get RSSI value\n"); @@ -1471,28 +1471,28 @@ int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param) if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) { wid_list[i].id = WID_SHORT_RETRY_LIMIT; - wid_list[i].val = (s8 *)¶m->short_retry_limit; + wid_list[i].val = (u8 *)¶m->short_retry_limit; wid_list[i].type = WID_SHORT; wid_list[i].size = sizeof(u16); i++; } if (param->flag & WILC_CFG_PARAM_RETRY_LONG) { wid_list[i].id = WID_LONG_RETRY_LIMIT; - wid_list[i].val = (s8 *)¶m->long_retry_limit; + wid_list[i].val = (u8 *)¶m->long_retry_limit; wid_list[i].type = WID_SHORT; wid_list[i].size = sizeof(u16); i++; } if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) { wid_list[i].id = WID_FRAG_THRESHOLD; - wid_list[i].val = (s8 *)¶m->frag_threshold; + wid_list[i].val = (u8 *)¶m->frag_threshold; wid_list[i].type = WID_SHORT; wid_list[i].size = sizeof(u16); i++; } if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) { wid_list[i].id = WID_RTS_THRESHOLD; - wid_list[i].val = (s8 *)¶m->rts_threshold; + wid_list[i].val = (u8 *)¶m->rts_threshold; wid_list[i].type = WID_SHORT; wid_list[i].size = sizeof(u16); i++; @@ -1943,7 +1943,7 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout) struct wilc *wilc = vif->wilc; struct wid wid; int result; - s8 power_mode; + u8 power_mode; if (enabled) power_mode = WILC_FW_MIN_FAST_PS; diff --git a/drivers/net/wireless/microchip/wilc1000/wlan_if.h b/drivers/net/wireless/microchip/wilc1000/wlan_if.h index 254a046e3b1bf..d7dbdfd243d58 100644 --- a/drivers/net/wireless/microchip/wilc1000/wlan_if.h +++ b/drivers/net/wireless/microchip/wilc1000/wlan_if.h @@ -203,8 +203,8 @@ enum wid_type { struct wid { u16 id; enum wid_type type; - s32 size; - s8 *val; + u32 size; + u8 *val; }; enum { base-commit: 18d0bedbb5f0538396cb7f763ed9cd1dd69c5b23 -- 2.54.0