From patchwork Tue Nov 20 05:22:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 12966 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 D346023FC2 for ; Tue, 20 Nov 2012 05:29:17 +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 89D2CA18088 for ; Tue, 20 Nov 2012 05:29:17 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so7671712iej.11 for ; Mon, 19 Nov 2012 21:29:17 -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=q0bs33XTD6gj7YaqcbINtOF1s8gBkmXYW6JmCaCdQR8=; b=IpsAFKTTNRge0cNXpQIm3Fj+7sq8C7pQK0f2Q1vU7BH0tA1CKEOcgBZY3k7r4Di3+L DQAOmPZh4dOBrOGJzhylG+YiNWE0ldyH/L81C4bL9x9lAD4Vh9pzRXo5VlRlVqvyg0hQ F9VWoNH73GVI593QojdCcLr8RySip5rM5//WfMdl7lD54HuwtHqKRcnFpTzYx69R4s5x ACTJRQpHGUAvkObOQJWCXApJo6NrdD4SH6CNdlc4E1yOIe8naI3ARMWN/EQnXxvc6cEv s2GN0L33BCqyDMQF171jFCRtuHDLCqGuFr3n33aRqEcteelCPT34SPh7ACZhEfZvMo2k HyyQ== Received: by 10.43.46.2 with SMTP id um2mr12877578icb.18.1353389357298; Mon, 19 Nov 2012 21:29:17 -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 n20csp271298igt; Mon, 19 Nov 2012 21:29:16 -0800 (PST) Received: by 10.68.83.68 with SMTP id o4mr46369303pby.25.1353389356460; Mon, 19 Nov 2012 21:29:16 -0800 (PST) Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com [209.85.160.48]) by mx.google.com with ESMTPS id gk10si16730553pbc.236.2012.11.19.21.29.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Nov 2012 21:29:16 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.48 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.160.48; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.48 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-pb0-f48.google.com with SMTP id rq13so3488912pbb.7 for ; Mon, 19 Nov 2012 21:29:16 -0800 (PST) Received: by 10.66.73.135 with SMTP id l7mr4963802pav.55.1353389356230; Mon, 19 Nov 2012 21:29:16 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id d2sm7429712paw.19.2012.11.19.21.29.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Nov 2012 21:29:15 -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 7/7] extcon: max77693: Use devm_kzalloc Date: Tue, 20 Nov 2012 10:52:43 +0530 Message-Id: <1353388963-23761-8-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: ALoCoQlGvf6VScFEIdN3SGJGerjo4trQeydV+9am9+q0dNGOSy98wKnW05a34nYMg3JlfoMnShK5 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-max77693.c | 23 ++++++++--------------- 1 files changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 2a0f397..3c29bb7 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -657,11 +657,11 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev) int ret, i; u8 id; - info = kzalloc(sizeof(struct max77693_muic_info), GFP_KERNEL); + info = devm_kzalloc(&pdev->dev, sizeof(struct max77693_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; info->max77693 = max77693; @@ -672,10 +672,9 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev) info->max77693->muic, &max77693_muic_regmap_config); if (IS_ERR(info->max77693->regmap_muic)) { - ret = PTR_ERR(info->max77693->regmap_muic); dev_err(max77693->dev, "failed to allocate register map: %d\n", ret); - goto err_regmap; + return PTR_ERR(info->max77693->regmap_muic); } } platform_set_drvdata(pdev, info); @@ -709,7 +708,8 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev) } /* Initialize extcon device */ - 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; @@ -720,7 +720,7 @@ static int __devinit max77693_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 MUIC register by using platform data */ @@ -753,7 +753,7 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev) MAX77693_MUIC_REG_ID, &id); if (ret < 0) { dev_err(&pdev->dev, "failed to read revision number\n"); - goto err_extcon; + goto err_irq; } dev_info(info->dev, "device ID : 0x%x\n", id); @@ -765,14 +765,9 @@ static int __devinit max77693_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); -err_regmap: - kfree(info); -err_kfree: return ret; } @@ -785,8 +780,6 @@ static int __devexit max77693_muic_remove(struct platform_device *pdev) free_irq(muic_irqs[i].virq, info); cancel_work_sync(&info->irq_work); extcon_dev_unregister(info->edev); - kfree(info->edev); - kfree(info); return 0; }