提交 5d4f929e 编写于 作者: J Johannes Berg 提交者: Emmanuel Grumbach

iwlwifi: mvm: do string formatting in debug triggers

The current code has a lot of duplicates of printing into a buffer
(while having to make sure it's NUL-filled and -terminated) and
then passing that to the debug trigger collection.

Since that's error-prone, instead make the debug trigger collection
function take a format string and format arguments (with compiler
validity checking) and handle the buffer internally.

This makes one behavioural change -- instead of sending the whole
buffer to userspace (clearing is needed to not leak stack data) it
just passes the actual string (including NUL-terminator.)
Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
Signed-off-by: NEmmanuel Grumbach <emmanuel.grumbach@intel.com>
上级 0d365ae5
...@@ -526,16 +526,33 @@ int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig, ...@@ -526,16 +526,33 @@ int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm, int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
struct iwl_fw_dbg_trigger_tlv *trigger, struct iwl_fw_dbg_trigger_tlv *trigger,
const char *str, size_t len) const char *fmt, ...)
{ {
unsigned int delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay)); unsigned int delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
u16 occurrences = le16_to_cpu(trigger->occurrences); u16 occurrences = le16_to_cpu(trigger->occurrences);
int ret; int ret, len = 0;
char buf[64];
if (!occurrences) if (!occurrences)
return 0; return 0;
ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), str, if (fmt) {
va_list ap;
buf[sizeof(buf) - 1] = '\0';
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
/* check for truncation */
if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
buf[sizeof(buf) - 1] = '\0';
len = strlen(buf) + 1;
}
ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf,
len, delay); len, delay);
if (ret) if (ret)
return ret; return ret;
......
...@@ -1412,7 +1412,7 @@ static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac, ...@@ -1412,7 +1412,7 @@ static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac,
if (rx_missed_bcon_since_rx >= stop_trig_missed_bcon_since_rx || if (rx_missed_bcon_since_rx >= stop_trig_missed_bcon_since_rx ||
rx_missed_bcon >= stop_trig_missed_bcon) rx_missed_bcon >= stop_trig_missed_bcon)
iwl_mvm_fw_dbg_collect_trig(mvm, trigger, NULL, 0); iwl_mvm_fw_dbg_collect_trig(mvm, trigger, NULL);
} }
int iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm, int iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
......
...@@ -3961,19 +3961,16 @@ static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, ...@@ -3961,19 +3961,16 @@ static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
struct ieee80211_vif *vif, struct ieee80211_vif *vif,
const struct ieee80211_event *event) const struct ieee80211_event *event)
{ {
#define CHECK_MLME_TRIGGER(_mvm, _trig, _buf, _cnt, _str...) \ #define CHECK_MLME_TRIGGER(_mvm, _trig, _buf, _cnt, _fmt...) \
do { \ do { \
if ((_cnt) && --(_cnt)) \ if ((_cnt) && --(_cnt)) \
break; \ break; \
snprintf(_buf, sizeof(_buf), ##_str); \ iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _fmt);\
iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _buf, \
sizeof(_buf)); \
} while (0) } while (0)
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
struct iwl_fw_dbg_trigger_tlv *trig; struct iwl_fw_dbg_trigger_tlv *trig;
struct iwl_fw_dbg_trigger_mlme *trig_mlme; struct iwl_fw_dbg_trigger_mlme *trig_mlme;
char buf[32];
if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME)) if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
return; return;
...@@ -3986,8 +3983,6 @@ static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, ...@@ -3986,8 +3983,6 @@ static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig)) if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
return; return;
memset(buf, 0, sizeof(buf));
if (event->u.mlme.data == ASSOC_EVENT) { if (event->u.mlme.data == ASSOC_EVENT) {
if (event->u.mlme.status == MLME_DENIED) if (event->u.mlme.status == MLME_DENIED)
CHECK_MLME_TRIGGER(mvm, trig, buf, CHECK_MLME_TRIGGER(mvm, trig, buf,
......
...@@ -1480,7 +1480,7 @@ int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm, ...@@ -1480,7 +1480,7 @@ int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm); void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm);
int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm, int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
struct iwl_fw_dbg_trigger_tlv *trigger, struct iwl_fw_dbg_trigger_tlv *trigger,
const char *str, size_t len); const char *fmt, ...) __printf(3, 4);
unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm, unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
struct ieee80211_vif *vif, struct ieee80211_vif *vif,
bool tdls, bool cmd_q); bool tdls, bool cmd_q);
...@@ -1527,7 +1527,7 @@ iwl_fw_dbg_trigger_simple_stop(struct iwl_mvm *mvm, ...@@ -1527,7 +1527,7 @@ iwl_fw_dbg_trigger_simple_stop(struct iwl_mvm *mvm,
if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trigger)) if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trigger))
return; return;
iwl_mvm_fw_dbg_collect_trig(mvm, trigger, NULL, 0); iwl_mvm_fw_dbg_collect_trig(mvm, trigger, NULL);
} }
#endif /* __IWL_MVM_H__ */ #endif /* __IWL_MVM_H__ */
...@@ -689,7 +689,6 @@ static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm, ...@@ -689,7 +689,6 @@ static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
{ {
struct iwl_fw_dbg_trigger_tlv *trig; struct iwl_fw_dbg_trigger_tlv *trig;
struct iwl_fw_dbg_trigger_cmd *cmds_trig; struct iwl_fw_dbg_trigger_cmd *cmds_trig;
char buf[32];
int i; int i;
if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF)) if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_FW_NOTIF))
...@@ -709,9 +708,9 @@ static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm, ...@@ -709,9 +708,9 @@ static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd) if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd)
continue; continue;
memset(buf, 0, sizeof(buf)); iwl_mvm_fw_dbg_collect_trig(mvm, trig,
snprintf(buf, sizeof(buf), "CMD 0x%02x received", pkt->hdr.cmd); "CMD 0x%02x received",
iwl_mvm_fw_dbg_collect_trig(mvm, trig, buf, sizeof(buf)); pkt->hdr.cmd);
break; break;
} }
} }
......
...@@ -362,7 +362,7 @@ int iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, ...@@ -362,7 +362,7 @@ int iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
iwl_fw_dbg_trigger_check_stop(mvm, mvmsta->vif, iwl_fw_dbg_trigger_check_stop(mvm, mvmsta->vif,
trig); trig);
if (trig_check && rx_status->signal < rssi) if (trig_check && rx_status->signal < rssi)
iwl_mvm_fw_dbg_collect_trig(mvm, trig, NULL, 0); iwl_mvm_fw_dbg_collect_trig(mvm, trig, NULL);
} }
} }
...@@ -552,7 +552,7 @@ iwl_mvm_rx_stats_check_trigger(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt) ...@@ -552,7 +552,7 @@ iwl_mvm_rx_stats_check_trigger(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt)
if (le32_to_cpup((__le32 *) (pkt->data + trig_offset)) < trig_thold) if (le32_to_cpup((__le32 *) (pkt->data + trig_offset)) < trig_thold)
return; return;
iwl_mvm_fw_dbg_collect_trig(mvm, trig, NULL, 0); iwl_mvm_fw_dbg_collect_trig(mvm, trig, NULL);
} }
void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm, void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册