diff --git a/core/hdd/src/wlan_hdd_ext_scan.c b/core/hdd/src/wlan_hdd_ext_scan.c index e5cf724e4560..e692ab71f666 100644 --- a/core/hdd/src/wlan_hdd_ext_scan.c +++ b/core/hdd/src/wlan_hdd_ext_scan.c @@ -2905,6 +2905,11 @@ static int hdd_extscan_start_fill_bucket_channel_spec( j = 0; nla_for_each_nested(channels, bucket[QCA_WLAN_VENDOR_ATTR_EXTSCAN_CHANNEL_SPEC], rem2) { + if ((j >= req_msg->buckets[bkt_index].numChannels) || + hdd_extscan_channel_max_reached(req_msg, + total_channels)) + break; + if (nla_parse(channel, QCA_WLAN_VENDOR_ATTR_EXTSCAN_SUBCMD_CONFIG_PARAM_MAX, nla_data(channels), nla_len(channels), @@ -2913,10 +2918,6 @@ static int hdd_extscan_start_fill_bucket_channel_spec( return -EINVAL; } - if (hdd_extscan_channel_max_reached(req_msg, - total_channels)) - break; - /* Parse and fetch channel */ if (!channel[ QCA_WLAN_VENDOR_ATTR_EXTSCAN_CHANNEL_SPEC_CHANNEL]) {