From patchwork Mon Oct 8 00:47:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 1563361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 216B9DFF71 for ; Mon, 8 Oct 2012 00:51:00 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TL1Vj-0008Kx-Sd; Mon, 08 Oct 2012 00:47:55 +0000 Received: from mail-qa0-f49.google.com ([209.85.216.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TL1Vd-0008Kj-H9 for linux-arm-kernel@lists.infradead.org; Mon, 08 Oct 2012 00:47:52 +0000 Received: by mail-qa0-f49.google.com with SMTP id a17so1554074qae.15 for ; Sun, 07 Oct 2012 17:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=/Ozf5/2dFTx8MUFG9XeapjCq1burCOA7SVvONTh0IYw=; b=e9PspE400n4TGr6ULSo7fLk3e+o8Dpl+Z6zgT7eULdgJCyJFBri8MhjRNYReDlcj8s TPzMkN/EdEpidrTuw4L1WGFTkPSA7Mwa0G8D9+M9kRcH4Qb9eEVbzWjV3iwnNCtfSqZd XbN2T4JkhM7pJmhtJxgLzKaQuw/lZeRSfmIfN6R12kUVVoqKYsFjeWtdwTQYWlEXpJ5J fgSZ+bJSUcsQsiqp8J5mWOKdhU7VTQSPGr5JDADsycH7OFbMlvZRez/1bmy3slk1chy1 RHpRckoobNK24ifmZFyY7sUS5ULO3pSW+BlzDJieol7OSTNbHUqs5ZWEYeG643s1xr0d +xNA== MIME-Version: 1.0 Received: by 10.224.178.4 with SMTP id bk4mr9723228qab.38.1349657267480; Sun, 07 Oct 2012 17:47:47 -0700 (PDT) Received: by 10.229.146.194 with HTTP; Sun, 7 Oct 2012 17:47:47 -0700 (PDT) Date: Mon, 8 Oct 2012 08:47:47 +0800 Message-ID: Subject: [PATCH] serial: vt8500: fix possible memory leak in vt8500_serial_probe() From: Wei Yongjun To: linux@prisktech.co.nz, alan@linux.intel.com, gregkh@linuxfoundation.org, grant.likely@secretlab.ca, rob.herring@calxeda.com X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (weiyj.lk[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: devicetree-discuss@lists.ozlabs.org, yongjun_wei@trendmicro.com.cn, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Wei Yongjun vt8500_port is malloced in vt8500_serial_probe() and should be freed before leaving from the error handling cases, otherwise it will cause memory leak. dpatch engine is used to auto generate this patch. (https://github.com/weiyj/dpatch) Signed-off-by: Wei Yongjun Acked-by: Tony Prisk --- drivers/tty/serial/vt8500_serial.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c index 205d4cf..43fc369 100644 --- a/drivers/tty/serial/vt8500_serial.c +++ b/drivers/tty/serial/vt8500_serial.c @@ -584,13 +584,16 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev) sizeof(vt8500_ports_in_use)); } - if (port > VT8500_MAX_PORTS) - return -ENODEV; + if (port > VT8500_MAX_PORTS) { + ret = -ENODEV; + goto err; + } /* reserve the port id */ if (test_and_set_bit(port, &vt8500_ports_in_use)) { /* port already in use - shouldn't really happen */ - return -EBUSY; + ret = -EBUSY; + goto err; } vt8500_port->uart.type = PORT_VT8500;