Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4612986ooa; Tue, 14 Aug 2018 08:13:33 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyoDJEmfOVEhTEEi6JvH+2JtGA4AVUNNTWv5uzLk/iBaRT6O+Gd5KGJNBdx2ORlrovgTsdy X-Received: by 2002:a17:902:7b83:: with SMTP id w3-v6mr20631041pll.192.1534259613580; Tue, 14 Aug 2018 08:13:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534259613; cv=none; d=google.com; s=arc-20160816; b=tszCSm8vRU2lxxtVD08UFgKFcCKCuHUWGo3uSD5CsR6/VbIhiZKnAtX95FSJht3bPb uOqQhKarddBPM8Sks4aU0as+GP17Kgm8pTmAjKPMQTbtpooNSxWBJ8yePCai1zrCi3Ft YGIdUmxQXhaFJpJICg/FnnXI4WJGh1GxCF/JQcnTUPlw19RPAW91huZttNFScytI/nWQ So2la8kASiqlFURfqrBXxRIVfIJFHsAprABzQWqo30weLTCju6Y07gTwVX8alXSHfMmk nMHfzXhfEGTje0Lfd95pRSap7P75CFCQNkhlq2X4T3GkA8EAZ2Nfuf2aBM2vki/R17E8 zrFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=MBYdNAkG48yKSDBeSbkP2SJXPEH2uzHaOgkRrZW8rq4=; b=Nr0TlE6YnmTDJTJfdLHtBxRUQjhpAHqHAyvbRjOF4Mhzn/dooWsMgkqVOaAiV+Pg5q D1Y+kxHGU6Hthze7eq6EjqqqGidKSR7vJ6vVgcNbWdiQSnkZjgrVOPm/zFlXEOwNkUNo NFWRuKiqULs4BSDQrA0LRRnjzJK3lVMIHkw732R3O8AHPYQlfn40rMVNe+KZ5TMO9rNf Z0hPYJQsNTj/Yyv8hSDhe+uehzlFshljfiHEmPPmulA7iTpTkKbCXG99TkN5beX5Wis7 97YFvH0iRsJdgXs5lKGAiAtwNesLUUOeXIOjPUcef1iLpNdlSt/bNfLqOOG7J+SN0qxJ iNNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y13-v6si17771045pgp.560.2018.08.14.08.13.17; Tue, 14 Aug 2018 08:13:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732069AbeHNR61 (ORCPT + 99 others); Tue, 14 Aug 2018 13:58:27 -0400 Received: from gateway34.websitewelcome.com ([192.185.149.105]:45313 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728880AbeHNR61 (ORCPT ); Tue, 14 Aug 2018 13:58:27 -0400 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 4BF5A70AF for ; Tue, 14 Aug 2018 10:10:53 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id paxufy3TpBcCXpay4fWIpk; Tue, 14 Aug 2018 10:10:52 -0500 X-Authority-Reason: nr=8 Received: from [189.250.37.72] (port=45736 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1fpaxs-000JSd-VW; Tue, 14 Aug 2018 10:10:33 -0500 Date: Tue, 14 Aug 2018 10:10:31 -0500 From: "Gustavo A. R. Silva" To: Sean Wang , Marcel Holtmann , Johan Hedberg , Matthias Brugger Cc: linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] Bluetooth: mediatek: Fix memory leak Message-ID: <20180814151031.GA25096@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.37.72 X-Source-L: No X-Exim-ID: 1fpaxs-000JSd-VW X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.37.72]:45736 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 8 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case memory resources for *fw* were allocated, release them before return. Addresses-Coverity-ID: 1472611 ("Resource leak") Fixes: 7237c4c9ec92 ("Bluetooth: mediatek: Add protocol support for MediaTek serial devices") Signed-off-by: Gustavo A. R. Silva --- drivers/bluetooth/btmtkuart.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c index ed2a5c7..4593baf 100644 --- a/drivers/bluetooth/btmtkuart.c +++ b/drivers/bluetooth/btmtkuart.c @@ -144,8 +144,10 @@ static int mtk_setup_fw(struct hci_dev *hdev) fw_size = fw->size; /* The size of patch header is 30 bytes, should be skip */ - if (fw_size < 30) - return -EINVAL; + if (fw_size < 30) { + err = -EINVAL; + goto free_fw; + } fw_size -= 30; fw_ptr += 30; @@ -172,8 +174,8 @@ static int mtk_setup_fw(struct hci_dev *hdev) fw_ptr += dlen; } +free_fw: release_firmware(fw); - return err; } -- 2.7.4