From patchwork Mon Jul 25 02:42:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Reid X-Patchwork-Id: 9245137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6373A607FD for ; Mon, 25 Jul 2016 02:43:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 575002094D for ; Mon, 25 Jul 2016 02:43:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C2CB262FF; Mon, 25 Jul 2016 02:43:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCEB526785 for ; Mon, 25 Jul 2016 02:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752673AbcGYCnM (ORCPT ); Sun, 24 Jul 2016 22:43:12 -0400 Received: from 203-59-230-133.perm.iinet.net.au ([203.59.230.133]:48256 "EHLO preid-centos7.electromag.com.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752650AbcGYCnK (ORCPT ); Sun, 24 Jul 2016 22:43:10 -0400 Received: by preid-centos7.electromag.com.au (Postfix, from userid 1000) id 63D56300D961A; Mon, 25 Jul 2016 10:43:03 +0800 (AWST) From: Phil Reid To: sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, linux-pm@vger.kernel.org Cc: Phil Reid Subject: [PATCH v2 1/4] power: sbs-battery: Use devm_kzalloc to alloc data Date: Mon, 25 Jul 2016 10:42:57 +0800 Message-Id: <1469414580-14121-2-git-send-email-preid@electromag.com.au> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1469414580-14121-1-git-send-email-preid@electromag.com.au> References: <1469414580-14121-1-git-send-email-preid@electromag.com.au> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_kzalloc to allow memory to be freed automatically on driver probe failure or removal. Signed-off-by: Phil Reid --- drivers/power/sbs-battery.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c index 768b9fc..20f3be6 100644 --- a/drivers/power/sbs-battery.c +++ b/drivers/power/sbs-battery.c @@ -819,7 +819,7 @@ static int sbs_probe(struct i2c_client *client, if (!sbs_desc->name) return -ENOMEM; - chip = kzalloc(sizeof(struct sbs_info), GFP_KERNEL); + chip = devm_kzalloc(&client->dev, sizeof(struct sbs_info), GFP_KERNEL); if (!chip) return -ENOMEM; @@ -920,8 +920,6 @@ exit_psupply: if (chip->gpio_detect) gpio_free(pdata->battery_detect); - kfree(chip); - return rc; } @@ -938,9 +936,6 @@ static int sbs_remove(struct i2c_client *client) cancel_delayed_work_sync(&chip->work); - kfree(chip); - chip = NULL; - return 0; }