From patchwork Tue Nov 20 05:22:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 12965 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9373723FC2 for ; Tue, 20 Nov 2012 05:29:14 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 48E8AA18088 for ; Tue, 20 Nov 2012 05:29:14 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so7671712iej.11 for ; Mon, 19 Nov 2012 21:29:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=vohjU49P2IpC9MvO+u3qXRiX9T1E3zCKceZGwr3LZNA=; b=lhQqvxI1FBOoY7nJ83AoFsrn6srAJzC5CetUUxcAwiY8VWm+IU9mAXlTvnxG14wWDX 8mBscUQf1q2HKqmG0dXl77D0UFeaYgyj0OuW2zQMARWaQdIeVNZqVOVqDIf8JUfsmeX5 r/8rDXDFkXYrmQWF8b+xMto6xJ8yvtqVGH7eb+EVTfXyz1Eg5sdT8zy6dg+utcBhlZSC wS+Ve9csB8k5hnjV9+6aq7Fe/3ipIkmcIZ/qgDlpSjwrs5tB1I+V1zurBGc8BuCz7Dv3 XZuwLYPwBwEVSaflfh+NsBOc/x8+PomkKcpa3N3kl6w6sJGB9Z5qHrhfOLHIulClCont euIg== Received: by 10.50.161.169 with SMTP id xt9mr8716024igb.62.1353389354056; Mon, 19 Nov 2012 21:29:14 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp271292igt; Mon, 19 Nov 2012 21:29:13 -0800 (PST) Received: by 10.69.0.8 with SMTP id au8mr46072964pbd.58.1353389353556; Mon, 19 Nov 2012 21:29:13 -0800 (PST) Received: from mail-da0-f49.google.com (mail-da0-f49.google.com [209.85.210.49]) by mx.google.com with ESMTPS id zw5si16742468pbc.187.2012.11.19.21.29.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Nov 2012 21:29:13 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.49 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.210.49; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.49 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) smtp.mail=sachin.kamat@linaro.org Received: by mail-da0-f49.google.com with SMTP id v40so1409461dad.36 for ; Mon, 19 Nov 2012 21:29:13 -0800 (PST) Received: by 10.68.237.167 with SMTP id vd7mr40040981pbc.161.1353389353286; Mon, 19 Nov 2012 21:29:13 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id d2sm7429712paw.19.2012.11.19.21.29.10 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Nov 2012 21:29:12 -0800 (PST) From: Sachin Kamat To: linux-kernel@vger.kernel.org Cc: myungjoo.ham@samsung.com, cw00.choi@samsung.com, sachin.kamat@linaro.org, patches@linaro.org Subject: [PATCH 6/7] extcon: max8997: Use devm_kzalloc Date: Tue, 20 Nov 2012 10:52:42 +0530 Message-Id: <1353388963-23761-7-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1353388963-23761-1-git-send-email-sachin.kamat@linaro.org> References: <1353388963-23761-1-git-send-email-sachin.kamat@linaro.org> X-Gm-Message-State: ALoCoQl0O+0t/XhUwABXZQoeMV3+874IX7U0wcT/jd+comj4gaonpFobVqTkMSUKFqJXMiJS5gOW devm_kzalloc() is a device managed function. It makes error handling and cleanup code a bit simpler. Signed-off-by: Sachin Kamat --- drivers/extcon/extcon-max8997.c | 18 ++++++------------ 1 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index ffdbe8c..8059325 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -433,11 +433,11 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev) struct max8997_muic_info *info; int ret, i; - info = kzalloc(sizeof(struct max8997_muic_info), GFP_KERNEL); + info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_muic_info), + GFP_KERNEL); if (!info) { dev_err(&pdev->dev, "failed to allocate memory\n"); - ret = -ENOMEM; - goto err_kfree; + return -ENOMEM; } info->dev = &pdev->dev; @@ -471,7 +471,8 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev) } /* External connector */ - info->edev = kzalloc(sizeof(struct extcon_dev), GFP_KERNEL); + info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev), + GFP_KERNEL); if (!info->edev) { dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); ret = -ENOMEM; @@ -482,7 +483,7 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev) ret = extcon_dev_register(info->edev, NULL); if (ret) { dev_err(&pdev->dev, "failed to register extcon device\n"); - goto err_extcon; + goto err_irq; } /* Initialize registers according to platform data */ @@ -500,13 +501,9 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev) return ret; -err_extcon: - kfree(info->edev); err_irq: while (--i >= 0) free_irq(muic_irqs[i].virq, info); - kfree(info); -err_kfree: return ret; } @@ -521,9 +518,6 @@ static int __devexit max8997_muic_remove(struct platform_device *pdev) extcon_dev_unregister(info->edev); - kfree(info->edev); - kfree(info); - return 0; }