From patchwork Mon Sep 7 10:09:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Cho X-Patchwork-Id: 7133441 X-Patchwork-Delegate: kvalo@adurom.com 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 821C9BEEC1 for ; Mon, 7 Sep 2015 10:09:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A963D20662 for ; Mon, 7 Sep 2015 10:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B693C20678 for ; Mon, 7 Sep 2015 10:09:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751673AbbIGKJZ (ORCPT ); Mon, 7 Sep 2015 06:09:25 -0400 Received: from eusmtp01.atmel.com ([212.144.249.242]:45732 "EHLO eusmtp01.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbbIGKJY (ORCPT ); Mon, 7 Sep 2015 06:09:24 -0400 Received: from tony-itx.corp.atmel.com (10.161.101.13) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server id 14.3.235.1; Mon, 7 Sep 2015 12:09:22 +0200 From: Tony Cho To: CC: , , , , , , , , , , , Subject: [PATCH 3/3] staging: wilc1000: fix potential memory leak Date: Mon, 7 Sep 2015 19:09:31 +0900 Message-ID: <1441620571-23033-3-git-send-email-tony.cho@atmel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441620571-23033-1-git-send-email-tony.cho@atmel.com> References: <1441620571-23033-1-git-send-email-tony.cho@atmel.com> MIME-Version: 1.0 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, T_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 This patch adds kfree(mgmt_tx) when memory allocation of mgmt_tx->buff fails in the second calls of kmalloc() to avoid the memory leak from mgmt_tx first allocated before the second calls of kmalloc(). Signed-off-by: Tony Cho Signed-off-by: Chris Park --- drivers/staging/wilc1000/linux_mon.c | 1 + drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/staging/wilc1000/linux_mon.c b/drivers/staging/wilc1000/linux_mon.c index b5db23f..dd80071 100644 --- a/drivers/staging/wilc1000/linux_mon.c +++ b/drivers/staging/wilc1000/linux_mon.c @@ -242,6 +242,7 @@ static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len) mgmt_tx->buff = kmalloc(len, GFP_ATOMIC); if (mgmt_tx->buff == NULL) { PRINT_ER("Failed to allocate memory for mgmt_tx buff\n"); + kfree(mgmt_tx); return WILC_FAIL; } diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c index 663d0f8..cf76a33 100644 --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c @@ -2533,6 +2533,7 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy, mgmt_tx->buff = WILC_MALLOC(buf_len); if (mgmt_tx->buff == NULL) { PRINT_ER("Failed to allocate memory for mgmt_tx buff\n"); + kfree(mgmt_tx); return WILC_FAIL; } memcpy(mgmt_tx->buff, buf, len);