Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cfg80211: initialize reg_rule in __freq_reg_info()

Sparse started warning on this function because we can potentially
return an uninitialized value. The reason is that if the caller
passes a min_bw value that is higher then the last value in bws[], we
will not go into the loop and reg_rule will remain initialized. This
cannot happen because the only caller of this function uses either 1
or 20 in min_bw, but the function will be more robust if we
pre-initialize the value.

Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20210204154439.6c884ea7281c.I257278d03b0c1ae0aa6631672cfa48f1a95d5996@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Luca Coelho and committed by
Johannes Berg
9e6d5126 6194f7e6

+1 -1
+1 -1
net/wireless/reg.c
··· 1629 1629 { 1630 1630 const struct ieee80211_regdomain *regd = reg_get_regdomain(wiphy); 1631 1631 static const u32 bws[] = {0, 1, 2, 4, 5, 8, 10, 16, 20}; 1632 - const struct ieee80211_reg_rule *reg_rule; 1632 + const struct ieee80211_reg_rule *reg_rule = ERR_PTR(-ERANGE); 1633 1633 int i = ARRAY_SIZE(bws) - 1; 1634 1634 u32 bw; 1635 1635