From patchwork Thu Oct 20 06:59:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 9386033 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 AF21860762 for ; Thu, 20 Oct 2016 06:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CC1B293AE for ; Thu, 20 Oct 2016 06:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9169F29869; Thu, 20 Oct 2016 06:59:36 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham 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 29E79293AE for ; Thu, 20 Oct 2016 06:59:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754433AbcJTG7e (ORCPT ); Thu, 20 Oct 2016 02:59:34 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36046 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752708AbcJTG7d (ORCPT ); Thu, 20 Oct 2016 02:59:33 -0400 Received: by mail-pf0-f193.google.com with SMTP id r16so4664659pfg.3 for ; Wed, 19 Oct 2016 23:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=UvHVbB2q33DSDXBeDbgkWk3gGbuVKDVHc7RZggxxMeo=; b=zSoE+dr5QNdlaGU24gSdrS1u2PvrkzRxJmzFuuX8ciK/Va9Q9p6ZpgNnOQ4QlH15Cd 9vE7VI/lHZG25rBVr+iQA7qyFhOLU8QL2q8Tui78cpmb5U1t9FzMQLQEEAphkSEUoSKy ZYpjILuWW9eumaXJZfk3RsxcUsFEV6G55PWe/ucEI2utbbm5lZe0QXNXByY/WPys+qq5 7SGci/aqp1xLoh1hHjKWqTU3zTIEeGvTgiSJN5xuvAR01Q/rhHZ2RWcf2mR7tF/S6JuH MzM5ulWXUu+ZXKuRKn4ILmyGkhdhLKfIITc8ZT7NL1GcKBE2CKhwByB7UsrGds46kWcm 7cKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=UvHVbB2q33DSDXBeDbgkWk3gGbuVKDVHc7RZggxxMeo=; b=fzB+cANP0eC3HsyX/smiGuSPZNNtgKQSmzdTF0420jNRbnVZnCyQJvvuvF7EuwvDAN S4uG6uBPHX0v1BRRRbamZFjBU4p7FqXH3er+WYU0dVlZUiF0ghl6mc0D+HJ1LIFxs4Lc edWLWQiheCHcn3TQXEVBzt55c5Lwi8nrxDtZqadIz5GVxws/XMzmYDqiUCs6sIKvZNia Q3X+1WV5lufXGHUv02zzYZaJSGOK553KnV2YO+cJ6HIpJWYubQCmqmdOQHaZUDByv0s+ XOzmTyYPBG0deVVGjgv6ujKj5NI7z/TH26X3rEhwK9JbQgaCNlWDJpwpfDwnPddEpVNi 1slw== X-Gm-Message-State: AA6/9Rmt23yQhegEcBHsOmG1msBoVdBOxSTgS6qxo0xGeeFOsr7owe8cY+Xx6+/UBUsm7w== X-Received: by 10.98.91.134 with SMTP id p128mr18826403pfb.22.1476946772361; Wed, 19 Oct 2016 23:59:32 -0700 (PDT) Received: from symbol-HP-ZBook-15 ([140.101.159.249]) by smtp.gmail.com with ESMTPSA id x1sm68760543pay.41.2016.10.19.23.59.31 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Oct 2016 23:59:31 -0700 (PDT) Date: Thu, 20 Oct 2016 12:29:33 +0530 From: Souptick Joarder To: linux-wireless@vger.kernel.org Cc: Larry.Finger@lwfinger.net, gregkh@linuxfoundation.org, florian.c.schilhabel@googlemail.com Subject: [PATCH] staging: rtl8712: Free memory and return failure when kmalloc fails Message-ID: <20161020065932.GA21705@symbol-HP-ZBook-15> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 This patch is added to free memory and return failure when kmalloc fails Signed-off-by: Souptick joarder --- drivers/staging/rtl8712/os_intfs.c | 3 ++- drivers/staging/rtl8712/rtl871x_cmd.c | 5 ++++- drivers/staging/rtl8712/rtl871x_xmit.c | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c index cbe4de0..aab3141 100644 --- a/drivers/staging/rtl8712/os_intfs.c +++ b/drivers/staging/rtl8712/os_intfs.c @@ -313,7 +313,8 @@ u8 r8712_init_drv_sw(struct _adapter *padapter) return _FAIL; if (r8712_init_mlme_priv(padapter) == _FAIL) return _FAIL; - _r8712_init_xmit_priv(&padapter->xmitpriv, padapter); + if ((_r8712_init_xmit_priv(&padapter->xmitpriv, padapter)) != _SUCCESS) + return _FAIL; _r8712_init_recv_priv(&padapter->recvpriv, padapter); memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv)); diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c index b7ee5e6..04638f1 100644 --- a/drivers/staging/rtl8712/rtl871x_cmd.c +++ b/drivers/staging/rtl8712/rtl871x_cmd.c @@ -72,8 +72,11 @@ static sint _init_cmd_priv(struct cmd_priv *pcmdpriv) ((addr_t)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ - 1)); pcmdpriv->rsp_allocated_buf = kmalloc(MAX_RSPSZ + 4, GFP_ATOMIC); - if (!pcmdpriv->rsp_allocated_buf) + if (!pcmdpriv->rsp_allocated_buf) { + kfree(pcmdpriv->cmd_allocated_buf); + pcmdpriv->cmd_allocated_buf = NULL; return _FAIL; + } pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((addr_t)(pcmdpriv->rsp_allocated_buf) & 3); pcmdpriv->cmd_issued_cnt = 0; diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c index be38364..484d2f2 100644 --- a/drivers/staging/rtl8712/rtl871x_xmit.c +++ b/drivers/staging/rtl8712/rtl871x_xmit.c @@ -128,8 +128,11 @@ sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv, _init_queue(&pxmitpriv->pending_xmitbuf_queue); pxmitpriv->pallocated_xmitbuf = kmalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4, GFP_ATOMIC); - if (!pxmitpriv->pallocated_xmitbuf) + if (!pxmitpriv->pallocated_xmitbuf) { + kfree(pxmitpriv->pallocated_frame_buf); + pxmitpriv->pallocated_frame_buf = NULL; return _FAIL; + } pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - ((addr_t)(pxmitpriv->pallocated_xmitbuf) & 3); pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;