From patchwork Fri Nov 15 12:13:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hante Meuleman X-Patchwork-Id: 3188011 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ED456C045B for ; Fri, 15 Nov 2013 12:13:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01AF2208A1 for ; Fri, 15 Nov 2013 12:13:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26DBA20820 for ; Fri, 15 Nov 2013 12:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752145Ab3KOMNt (ORCPT ); Fri, 15 Nov 2013 07:13:49 -0500 Received: from mms1.broadcom.com ([216.31.210.17]:4156 "EHLO mms1.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750861Ab3KOMNr convert rfc822-to-8bit (ORCPT ); Fri, 15 Nov 2013 07:13:47 -0500 Received: from [10.9.208.53] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.5)); Fri, 15 Nov 2013 04:13:23 -0800 X-Server-Uuid: 06151B78-6688-425E-9DE2-57CB27892261 Received: from SJEXCHCAS05.corp.ad.broadcom.com (10.16.203.12) by IRVEXCHCAS06.corp.ad.broadcom.com (10.9.208.53) with Microsoft SMTP Server (TLS) id 14.1.438.0; Fri, 15 Nov 2013 04:13:37 -0800 Received: from SJEXCHMB15.corp.ad.broadcom.com ( [fe80::ade7:c955:4805:f845]) by SJEXCHCAS05.corp.ad.broadcom.com ( [::1]) with mapi id 14.01.0438.000; Fri, 15 Nov 2013 04:13:37 -0800 From: "Hante Meuleman" To: "Geyslan G. Bem" cc: "Brett Rudley" , "Arend Van Spriel" , "Franky Lin" , "John W. Linville" , "Pieter-Paul Giesberts" , "Piotr Haber" , "linux-wireless@vger.kernel.org" , brcm80211-dev-list , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] brcmfmac: fix possible memory leak Thread-Topic: [PATCH] brcmfmac: fix possible memory leak Thread-Index: AQHO4fpMK2ChQlgc2UWX5OSdFp3HBpomMogA Date: Fri, 15 Nov 2013 12:13:37 +0000 Message-ID: References: <1384516475-26589-1-git-send-email-geyslan@gmail.com> In-Reply-To: <1384516475-26589-1-git-send-email-geyslan@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.16.203.100] MIME-Version: 1.0 X-WSS-ID: 7E98D0691508419282-01-01 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Good find, wrong solution. The chanspecs is a temporarily variable which should be freed when exiting the function. Not only when there is an error. I personally would have preferred just a free at the end of the " if (request->n_channels) {". So something like this: } err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state, action, P2PAPI_BSSCFG_DEVICE); + kfree(chanspecs); } In this case the pointer doesn't have to be initialized to NULL. Regards, Hante -----Original Message----- From: Geyslan G. Bem [mailto:geyslan@gmail.com] Sent: vrijdag 15 november 2013 12:54 To: geyslan@gmail.com Cc: Brett Rudley; Arend Van Spriel; Franky Lin; Hante Meuleman; John W. Linville; Pieter-Paul Giesberts; Piotr Haber; linux-wireless@vger.kernel.org; brcm80211-dev-list; netdev@vger.kernel.org; linux-kernel@vger.kernel.org Subject: [PATCH] brcmfmac: fix possible memory leak In case of error free 'chanspecs'. Signed-off-by: Geyslan G. Bem --- drivers/net/wireless/brcm80211/brcmfmac/p2p.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c index d7a9745..aea2c2e 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c @@ -771,7 +771,7 @@ static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_cfg80211_vif *vif; struct net_device *dev = NULL; int i, num_nodfs = 0; - u16 *chanspecs; + u16 *chanspecs = NULL; brcmf_dbg(TRACE, "enter\n"); @@ -825,8 +825,10 @@ static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg, action, P2PAPI_BSSCFG_DEVICE); } exit: - if (err) + if (err) { brcmf_err("error (%d)\n", err); + kfree(chanspecs); + } return err; }