From patchwork Fri May 27 13:07:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9138321 X-Patchwork-Delegate: luca@coelho.fi Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BCAF16075C for ; Fri, 27 May 2016 13:08:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC5D327BF4 for ; Fri, 27 May 2016 13:08:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A126028096; Fri, 27 May 2016 13:08:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1903527BF4 for ; Fri, 27 May 2016 13:08:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752302AbcE0NIQ (ORCPT ); Fri, 27 May 2016 09:08:16 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:53461 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750833AbcE0NIO (ORCPT ); Fri, 27 May 2016 09:08:14 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue004) with ESMTPA (Nemesis) id 0M940H-1bEIN21YmD-00CRQb; Fri, 27 May 2016 15:08:01 +0200 From: Arnd Bergmann To: Emmanuel Grumbach , Matti Gottlieb Cc: Linus Torvalds , Arnd Bergmann , Johannes Berg , Luca Coelho , Intel Linux Wireless , Kalle Valo , Moshe Harel , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iwlwifi: mvm: avoid harmless -Wmaybe-uninialized warning Date: Fri, 27 May 2016 15:07:03 +0200 Message-Id: <1464354462-1940949-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 MIME-Version: 1.0 X-Provags-ID: V03:K0:vJI8oCkA+lVMhyCIRrqh7Fj1IL9FyETCyAZbUWNFxVA1On7WQJe cNUbpJiGxODjnlopTUdgsPLdGEAYk+P5zH84wZIWBv7UkFvIxtE2qMtc+bBv9Fqr5VcVvWi NvYMczw9vVX/YZgWw/RP87E5PpNOS5qVIlpPfFBStbpaTKae2DQABl+R3i0Sm3+Um0bmpq/ 54CA+n32nb/KfdLAXaGfw== X-UI-Out-Filterresults: notjunk:1; V01:K0:qHnmPWUBmJg=:srtLbRRQPSqA0Qcw3PzV3M tHCEXwhOAAoScSE9SUXMPdVKhk7z8X2nRulwKxxw9eT/ugdc13CbnPV85ZBJcz8IBLMj+CYJU VshFVfQxiffHD0uKArGv29/dj0Cypscrr4abK/mbq+KkVL2izW68RKxKuLNp5zqwj/IZ0PlDv 4Xbg059rLZj9/ANElCTH09SKWpLonNLNCUlUz/5YV2KHNyayaXNVGKivJVJ5zTTaCNwxbbKDM eVfyTNQXKa3bgsB/gouklUmAgBex56b0b4CQ9Lo83/PFIolFLOLD50FI60w6nDGdTSBCGudH6 sU96vP0edNk+jysbXNcrNt6csrcbUk80d2mN72jMduJVa4IhmykoVTSUJeoLC9hGd1RrHzQb5 GrvGtt/J5IcIXtF0x4Cd3a+4FnM+BhgDm47hBS5MKh38MT1jjC9+ryBBngLxtSihbZ+V9X/68 v64IHYw47HtUhq/Q20bT9xv82Ru5o8/zTEgqLCzBzFACu5Jdx1P9Vwe9A6ngWYEV4HGl1yI0n cztSxuzYOutgZnPONmymfSeCEosj9Dnqygng+tj6vd4QRz5+TyvsSjhmt35Aw7WexTatYWCsc yOs3ihLPlIfhPnrujEJQRhugFa63hjq71f2OYOpyeiv4Src6IGqqAhasTX/QgUx496aExZg48 Tnz7CFnee9ZPyW8GVu6tDrk+LlyOLSwIyfFKaixErpCUKzWFlXFco7ES5NtBz5yb4LJDQGwM4 5hDpysH2IoIrCYPFAqepB82zKptxacJNJ6bLEQ== Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP gcc is apparently unablel to track the state of the local 'resp_v2' variable across the kzalloc() function, and warns about the response variable being used without an initialization: drivers/net/wireless/intel/iwlwifi/mvm/nvm.c: In function ‘iwl_mvm_update_mcc’: drivers/net/wireless/intel/iwlwifi/mvm/nvm.c:727:36: warning: ‘mcc_resp_v1’ may be used uninitialized in this function [-Wmaybe-uninitialized] resp_cp->n_channels = mcc_resp_v1->n_channels; drivers/net/wireless/intel/iwlwifi/mvm/nvm.c:721:3: warning: ‘mcc_resp’ may be used uninitialized in this function [-Wmaybe-uninitialized] memcpy(resp_cp, mcc_resp, resp_len); The warning showed up in x86 allmodconfig after my patch to unhide -Wmaybe-uninitialized warnings by default was merged, though it always existed in randconfig builds. I did not catch the warning earlier because I was testing on ARM, which never produced the warning. This rearranges the code in a way that improves readability for both humans and the compiler, and that avoids the warning. Signed-off-by: Arnd Bergmann Fixes: 6fa52430f0b3 ("iwlwifi: mvm: change mcc update API") --- drivers/net/wireless/intel/iwlwifi/mvm/nvm.c | 41 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c index 25a98401a64f..0551a4bb163c 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c @@ -667,8 +667,7 @@ iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2, .mcc = cpu_to_le16(alpha2[0] << 8 | alpha2[1]), .source_id = (u8)src_id, }; - struct iwl_mcc_update_resp *mcc_resp, *resp_cp = NULL; - struct iwl_mcc_update_resp_v1 *mcc_resp_v1 = NULL; + struct iwl_mcc_update_resp *resp_cp; struct iwl_rx_packet *pkt; struct iwl_host_cmd cmd = { .id = MCC_UPDATE_CMD, @@ -701,34 +700,36 @@ iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2, /* Extract MCC response */ if (resp_v2) { - mcc_resp = (void *)pkt->data; + struct iwl_mcc_update_resp *mcc_resp = (void *)pkt->data; + n_channels = __le32_to_cpu(mcc_resp->n_channels); + resp_len = sizeof(struct iwl_mcc_update_resp) + + n_channels * sizeof(__le32); + resp_cp = kmemdup(mcc_resp, resp_len, GFP_KERNEL); } else { - mcc_resp_v1 = (void *)pkt->data; + struct iwl_mcc_update_resp_v1 *mcc_resp_v1 = (void *)pkt->data; + n_channels = __le32_to_cpu(mcc_resp_v1->n_channels); + resp_len = sizeof(struct iwl_mcc_update_resp) + + n_channels * sizeof(__le32); + resp_cp = kzalloc(resp_len, GFP_KERNEL); + + if (resp_cp) { + resp_cp->status = mcc_resp_v1->status; + resp_cp->mcc = mcc_resp_v1->mcc; + resp_cp->cap = mcc_resp_v1->cap; + resp_cp->source_id = mcc_resp_v1->source_id; + resp_cp->n_channels = mcc_resp_v1->n_channels; + memcpy(resp_cp->channels, mcc_resp_v1->channels, + n_channels * sizeof(__le32)); + } } - resp_len = sizeof(struct iwl_mcc_update_resp) + n_channels * - sizeof(__le32); - - resp_cp = kzalloc(resp_len, GFP_KERNEL); if (!resp_cp) { ret = -ENOMEM; goto exit; } - if (resp_v2) { - memcpy(resp_cp, mcc_resp, resp_len); - } else { - resp_cp->status = mcc_resp_v1->status; - resp_cp->mcc = mcc_resp_v1->mcc; - resp_cp->cap = mcc_resp_v1->cap; - resp_cp->source_id = mcc_resp_v1->source_id; - resp_cp->n_channels = mcc_resp_v1->n_channels; - memcpy(resp_cp->channels, mcc_resp_v1->channels, - n_channels * sizeof(__le32)); - } - status = le32_to_cpu(resp_cp->status); mcc = le16_to_cpu(resp_cp->mcc);