From patchwork Tue Nov 27 05:58:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 13232 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 97E4723E08 for ; Tue, 27 Nov 2012 06:05:28 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 3756DA1930D for ; Tue, 27 Nov 2012 06:05:28 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id t4so5882481iag.11 for ; Mon, 26 Nov 2012 22:05:27 -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=WOo85RbzP/yT5ULhHptJmm6Ec/ZIW7DsZC0WnaKJU9w=; b=Uz1q5q3nC8FxzaqmMFSVeZShA194HKuU4Y9kp/tup5xCYYJ/+m6qGh1nK5pB/J5tK9 sz5LYcidyIaqCe/YDxmxTc5aw1f8m4QHpCNzmAYQwaNOG1L+mEo+JTkm3TL+uZgznMuN OF3H18vlE/z08PwmyLlZlGqSMmsHh4KcSZTHlMGmrOHAsdNNHVLza4P7HTLaYARczBbE ok0nXVzgHtwpAnEHZY0/e9fzX+nsdoVDqCjMZwxiivgaRXMG/vWMtgG9NtkM5qsQaVoz yJdQOpKIn0ZrCF06XSg2RRnmu7TKmhG4tsYcve7lJ8OGMKyZzRwtc2gkBv2DJJMD5CUL gaDg== Received: by 10.43.46.2 with SMTP id um2mr12697385icb.18.1353996327598; Mon, 26 Nov 2012 22:05:27 -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 n20csp405079igt; Mon, 26 Nov 2012 22:05:27 -0800 (PST) Received: by 10.66.73.135 with SMTP id l7mr40135124pav.55.1353996327058; Mon, 26 Nov 2012 22:05:27 -0800 (PST) Received: from mail-pb0-f42.google.com (mail-pb0-f42.google.com [209.85.160.42]) by mx.google.com with ESMTPS id sh10si22942299pbb.23.2012.11.26.22.05.26 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 26 Nov 2012 22:05:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.42 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.160.42; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.42 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-f42.google.com with SMTP id rp2so8263467pbb.29 for ; Mon, 26 Nov 2012 22:05:26 -0800 (PST) Received: by 10.68.253.230 with SMTP id ad6mr45610143pbd.84.1353996326838; Mon, 26 Nov 2012 22:05:26 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id nf9sm10064758pbc.17.2012.11.26.22.05.23 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 26 Nov 2012 22:05:26 -0800 (PST) From: Sachin Kamat To: linux-kernel@vger.kernel.org Cc: cbou@mail.ru, cbouatmailru@gmail.com, dwmw2@infradead.org, sachin.kamat@linaro.org, patches@linaro.org Subject: [PATCH 3/3] power: bq2415x_charger: Use devm_kzalloc() Date: Tue, 27 Nov 2012 11:28:46 +0530 Message-Id: <1353995926-4621-4-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1353995926-4621-1-git-send-email-sachin.kamat@linaro.org> References: <1353995926-4621-1-git-send-email-sachin.kamat@linaro.org> X-Gm-Message-State: ALoCoQnZ0cPZTuynTyCzm8H7S2mSV8/FQTc7RJn5UKIUvvUuxWzge2Vbk5j5uE0ranq5lwQpW9DK devm_kzalloc is device managed and makes error handling and code cleanup a bit simpler. Signed-off-by: Sachin Kamat --- drivers/power/bq2415x_charger.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c index 54c4ebf..f93359b 100644 --- a/drivers/power/bq2415x_charger.c +++ b/drivers/power/bq2415x_charger.c @@ -1522,7 +1522,7 @@ static int bq2415x_probe(struct i2c_client *client, goto error_1; } - bq = kzalloc(sizeof(*bq), GFP_KERNEL); + bq = devm_kzalloc(&client->dev, sizeof(*bq), GFP_KERNEL); if (!bq) { dev_err(&client->dev, "failed to allocate device data\n"); ret = -ENOMEM; @@ -1548,19 +1548,19 @@ static int bq2415x_probe(struct i2c_client *client, ret = bq2415x_power_supply_init(bq); if (ret) { dev_err(bq->dev, "failed to register power supply: %d\n", ret); - goto error_3; + goto error_2; } ret = bq2415x_sysfs_init(bq); if (ret) { dev_err(bq->dev, "failed to create sysfs entries: %d\n", ret); - goto error_4; + goto error_3; } ret = bq2415x_set_defaults(bq); if (ret) { dev_err(bq->dev, "failed to set default values: %d\n", ret); - goto error_5; + goto error_4; } if (bq->init_data.set_mode_hook) { @@ -1584,12 +1584,10 @@ static int bq2415x_probe(struct i2c_client *client, dev_info(bq->dev, "driver registered\n"); return 0; -error_5: - bq2415x_sysfs_exit(bq); error_4: - bq2415x_power_supply_exit(bq); + bq2415x_sysfs_exit(bq); error_3: - kfree(bq); + bq2415x_power_supply_exit(bq); error_2: kfree(name); error_1: @@ -1621,7 +1619,6 @@ static int bq2415x_remove(struct i2c_client *client) dev_info(bq->dev, "driver unregistered\n"); kfree(bq->name); - kfree(bq); return 0; }