From patchwork Mon Oct 8 02:35:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 1563491 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 39FFD3FD9C for ; Mon, 8 Oct 2012 02:37:54 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TL3CA-0005Qw-JP; Mon, 08 Oct 2012 02:35:50 +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 1TL3C7-0005Qi-I7 for linux-arm-kernel@lists.infradead.org; Mon, 08 Oct 2012 02:35:48 +0000 Received: by mail-qa0-f49.google.com with SMTP id a17so1592303qae.15 for ; Sun, 07 Oct 2012 19:35:46 -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=qCtWq1t3X7xtQFSCjLezJwkUTbUctZkmzZp286s2LMg=; b=ApqH0ImjHg57zrKsXCUYmazKF1b5XcYfeInLxdH0AYVhNgvs5yc3NzMB0wKTxTSg+8 ACOsNOCMAwSfr+wBW8rFdQnyaQMXI3UQxyV1NbizbhP6wi82tXgRgBzNoLsU21ow60LH W67H/cswk0lUqsnWMUp4pwnX5k1Uv16oVFdsM5q02gmExkV3l0en8b4ntx8aQyQSwGVv /WYkRGXhjFjvViRDFC+76kxCG7X0AfoFW58h71112naow6rZhANzOhDWEyG3Q20mOdBj pGPlggmW+ln7oYv+2AFuI4urNDz4BsfR8/wD5HEalypVBNGeit5S9metiTdKGmDj0WES BvWw== MIME-Version: 1.0 Received: by 10.49.4.65 with SMTP id i1mr39755982qei.51.1349663746059; Sun, 07 Oct 2012 19:35:46 -0700 (PDT) Received: by 10.229.146.194 with HTTP; Sun, 7 Oct 2012 19:35:46 -0700 (PDT) Date: Mon, 8 Oct 2012 10:35:46 +0800 Message-ID: Subject: [PATCH v2] 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.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (weiyj.lk[at]gmail.com) -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 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. Fix it by move the allocation of vt8500_port after those test. dpatch engine is used to auto generate this patch. (https://github.com/weiyj/dpatch) Signed-off-by: Wei Yongjun Acked-by: Tony Prisk --- v1 -> v2: move the allocation of vt8500_port after those test --- drivers/tty/serial/vt8500_serial.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c index 205d4cf..4354fe5 100644 --- a/drivers/tty/serial/vt8500_serial.c +++ b/drivers/tty/serial/vt8500_serial.c @@ -567,10 +567,6 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev) if (!mmres || !irqres) return -ENODEV; - vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL); - if (!vt8500_port) - return -ENOMEM; - if (np) port = of_alias_get_id(np, "serial"); if (port > VT8500_MAX_PORTS) @@ -593,6 +589,10 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev) return -EBUSY; } + vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL); + if (!vt8500_port) + return -ENOMEM; + vt8500_port->uart.type = PORT_VT8500; vt8500_port->uart.iotype = UPIO_MEM; vt8500_port->uart.mapbase = mmres->start;