From patchwork Thu May 2 16:03:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 2512691 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 260CBDF215 for ; Thu, 2 May 2013 16:10:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760115Ab3EBQKu (ORCPT ); Thu, 2 May 2013 12:10:50 -0400 Received: from fallback7.mail.ru ([94.100.176.135]:41327 "EHLO fallback7.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758614Ab3EBQKt (ORCPT ); Thu, 2 May 2013 12:10:49 -0400 X-Greylist: delayed 448 seconds by postgrey-1.27 at vger.kernel.org; Thu, 02 May 2013 12:10:49 EDT Received: from smtp27.mail.ru (smtp27.mail.ru [94.100.176.180]) by fallback7.mail.ru (mPOP.Fallback_MX) with ESMTP id 37229CCA6A12; Thu, 2 May 2013 20:03:46 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Message-Id:Date:Subject:Cc:To:From; bh=g4qzTf8cEluBM1qM0jnuVOdI6cGF3BZSXwEgmK4hZTM=; b=iBCtTT12WSjFEoaqmTycTkrhZbQiswgyivvUjrle0TUzvCZ/EiZ7axHRcjxKuWEf78OO9m99jq48N62QAZtZwzfl0tEPOOdyNG1NTn+YCd+iOyqF9pgM5SNIID/Teq3qSdJHTtUYzhtDVs2nnkKsGFvwZNMDhRY+7h15+EuO1lQ=; Received: from [188.134.40.128] (port=62181 helo=shc.zet) by smtp27.mail.ru with esmtpa (envelope-from ) id 1UXvyZ-0006e5-Hz; Thu, 02 May 2013 20:03:19 +0400 From: Alexander Shiyan To: linux-arm-kernel@lists.infradead.org Cc: linux-omap@vger.kernel.org, linux-usb@vger.kernel.org, Felipe Balbi , Tony Lindgren , Arnd Bergmann , Alexander Shiyan Subject: [PATCH] ARM: OMAP-USB: Fix possible memory leak Date: Thu, 2 May 2013 20:03:16 +0400 Message-Id: <1367510596-27780-1-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.1.5 X-Spam: Not detected X-Mras: Ok Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Signed-off-by: Alexander Shiyan --- arch/arm/mach-omap2/usb-host.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-omap2/usb-host.c b/arch/arm/mach-omap2/usb-host.c index aa27d7f..8d17a0d 100644 --- a/arch/arm/mach-omap2/usb-host.c +++ b/arch/arm/mach-omap2/usb-host.c @@ -570,8 +570,10 @@ static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply, supplies->dev_name = dev_id; reg_data = kzalloc(sizeof(*reg_data), GFP_KERNEL); - if (!reg_data) + if (!reg_data) { + kfree(supplies); return -ENOMEM; + } reg_data->constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS; reg_data->consumer_supplies = supplies; @@ -579,8 +581,11 @@ static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply, config = kmemdup(&hsusb_reg_config, sizeof(hsusb_reg_config), GFP_KERNEL); - if (!config) + if (!config) { + kfree(supplies); + kfree(reg_data); return -ENOMEM; + } config->supply_name = name; config->gpio = gpio; @@ -589,17 +594,25 @@ static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply, /* create a regulator device */ pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); - if (!pdev) + if (!pdev) { + kfree(supplies); + kfree(reg_data); + kfree(config); return -ENOMEM; + } pdev->id = PLATFORM_DEVID_AUTO; pdev->name = reg_name; pdev->dev.platform_data = config; ret = platform_device_register(pdev); - if (ret) + if (ret) { pr_err("%s: Failed registering regulator %s for %s\n", __func__, name, dev_id); + kfree(supplies); + kfree(reg_data); + kfree(config); + } return ret; }