Skip to contentSkip to conversation

wifi: iwlegacy: replace BUG_ON() with WARN_ON() on num_stations check

PATCH New [email protected] 1 participant 1 message Jul 24 Intel wireless 3945ABG/bg, 4965AGN (iwlegacy)

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 wifi: iwlegacy: replace BUG_ON() with WARN_ON() on num_stations check

From: Stanislaw Gruszka <[email protected]>

BUG_ON() for il->num_stations < 0 can happen in real word, see
https://bugzilla.kernel.org/show_bug.cgi?id=221733

Replace BUG_ON() with WARN_ON() (and reset the counter to 0) to do not put whole system to inconsistent state on the condition.

Also allocate debugfs buffer for all stations (32 or 25) to do not use num_stations since it can not be valid number.

---
 drivers/net/wireless/intel/iwlegacy/common.c | 7 ++++---
 drivers/net/wireless/intel/iwlegacy/debug.c  | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/net/wireless/intel/iwlegacy/common.c +4 -3
index 8d0ff339ad08..0bb807ff8edf 100644
@@ -2179,8 +2179,8 @@ il_remove_station(struct il_priv *il, const u8 sta_id, const u8 * addr)
 	il->stations[sta_id].used &= ~IL_STA_DRIVER_ACTIVE;
 
 	il->num_stations--;
-
-	BUG_ON(il->num_stations < 0);
+	if (WARN_ON(il->num_stations < 0))
+		il->num_stations = 0;
 
 	spin_unlock_irqrestore(&il->sta_lock, flags);
 
@@ -2328,7 +2328,8 @@ il_dealloc_bcast_stations(struct il_priv *il)
 
 		il->stations[i].used &= ~IL_STA_UCODE_ACTIVE;
 		il->num_stations--;
-		BUG_ON(il->num_stations < 0);
+		if (WARN_ON(il->num_stations < 0))
+			il->num_stations = 0;
 		kfree(il->stations[i].lq);
 		il->stations[i].lq = NULL;
 	}
drivers/net/wireless/intel/iwlegacy/debug.c +1 -1
index d998a3f1b056..8a9f79ff1c6e 100644
@@ -396,7 +396,7 @@ il_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
 	int i, j, pos = 0;
 	ssize_t ret;
 	/* Add 30 for initial string */
-	const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
+	const size_t bufsz = 30 + sizeof(char) * 500 * max_sta;
 
 	buf = kmalloc(bufsz, GFP_KERNEL);
 	if (!buf)
Signature · 1 line
2.50.1