From 5cd0e228ac4113a539424084598868f0eca5ea7a Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 16 May 2014 16:49:17 +0300 Subject: [PATCH] P2P: Iterate through full pref_chan list in search of a valid channel p2p_get_pref_freq() went through the full list only if the channels arguments was provided. If no channel list contraint was in place, the first pref_chan item was picked regardless of whether it is valid channel and as such, a later valid entry could have been ignored. Allow this to loop through all the entries until a valid channel is found or the end of the pref_chan list is reached. As an extra bonus, this simplifies the p2p_get_pref_freq() implementation quite a bit. Signed-off-by: Jouni Malinen --- src/p2p/p2p_utils.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/p2p/p2p_utils.c b/src/p2p/p2p_utils.c index de47c1223..06cb646d9 100644 --- a/src/p2p/p2p_utils.c +++ b/src/p2p/p2p_utils.c @@ -384,23 +384,14 @@ unsigned int p2p_get_pref_freq(struct p2p_data *p2p, const struct p2p_channels *channels) { unsigned int i; - int freq = 0; - - if (channels == NULL) { - if (p2p->cfg->num_pref_chan) { - freq = p2p_channel_to_freq( - p2p->cfg->pref_chan[0].op_class, - p2p->cfg->pref_chan[0].chan); - if (freq < 0) - freq = 0; - } - return freq; - } + int freq; for (i = 0; p2p->cfg->pref_chan && i < p2p->cfg->num_pref_chan; i++) { freq = p2p_channel_to_freq(p2p->cfg->pref_chan[i].op_class, p2p->cfg->pref_chan[i].chan); - if (p2p_channels_includes_freq(channels, freq)) + if (freq <= 0) + continue; + if (!channels || p2p_channels_includes_freq(channels, freq)) return freq; }