From patchwork Thu Sep 7 09:00:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 111868 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp516592qge; Thu, 7 Sep 2017 02:01:29 -0700 (PDT) X-Google-Smtp-Source: ADKCNb4D6GSqJG0eZnwiaNm4mWhc2oBcxMCrPrYAzuOonecAZt0X51T8yua198xsM2/y4o04EK20 X-Received: by 10.84.210.67 with SMTP id z61mr2170983plh.125.1504774889884; Thu, 07 Sep 2017 02:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504774889; cv=none; d=google.com; s=arc-20160816; b=VdvqWyoIZFcc4dbWudoN3tOzh2DavBCWFAKA9S63QI6NJkWCfuMox3v75q+E3ElZt1 GB86Os6ohLuEa13hlMHyn2JKYCDrgWQhLtwnGU8Zq7semw2MMZOCzFJlTsn8vInfozI4 8uPDmcEVWr/Z8uwv3jjq76/scFCK3+sUbTFza8EvS/mq8J2yzLEz4RHgT2o4789atNPF /m+6z6mVVqUA91hLUWpSHl+FMQrUpSx2N8Ca0ioma5JWQ6K5Hno6WdWyPVdm975zHKrQ 5Jl/9TfqmbehGt8vBwro+DFEi/85QIhvtjLnznZj4A3Jvfpb5frzIREJJxhbz2kiidl3 aI/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=vr0O0X1ppuf7Ox72JxDd97Kmq4myzJbIb1/QbStSqYg=; b=LMuZCPDQoi0CiZz9vBrEEQrczoRikSm8upZ8QAkJsxzY8iL10Dy3IEXZsm6870ya10 UhLadJnDYct3DyFyJXIQ5RNKJRj569POkAeUYKgVbcJL2inFUQJcKq8zYuk9auFrj4tg z6KITXW4l+R6jpCfuGJPAkFXTGs4dabGV71609qtFImWmfmISYN0SZVHojP6PLu8YYtH Gyc1J60Z2DYV9v+iBoajrdvCAbdSBeQqcUpqixJBmt7FbxpAX9IMnX5phuVw/wtcjEGl BoGP1XSq2mO7nmURlpAEln7IW1dTdURK2wdM5HQA0/Ap0NG1aBGBAtvAtNVXxwlHZgX4 nWJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e28si1529620pgn.756.2017.09.07.02.01.29; Thu, 07 Sep 2017 02:01:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754924AbdIGJB1 (ORCPT + 26 others); Thu, 7 Sep 2017 05:01:27 -0400 Received: from foss.arm.com ([217.140.101.70]:57226 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754905AbdIGJBZ (ORCPT ); Thu, 7 Sep 2017 05:01:25 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 681A680D; Thu, 7 Sep 2017 02:01:25 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.140]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D1BF63F540; Thu, 7 Sep 2017 02:01:22 -0700 (PDT) From: Gilad Ben-Yossef To: Greg Kroah-Hartman , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: Ofir Drang , Suniel Mahesh Subject: [PATCH v3 1/8] staging: ccree: Replace kzalloc with devm_kzalloc Date: Thu, 7 Sep 2017 12:00:09 +0300 Message-Id: <1504774817-11984-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504774817-11984-1-git-send-email-gilad@benyossef.com> References: <1504774817-11984-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suniel Mahesh It is recommended to use managed function devm_kzalloc, which simplifies driver cleanup paths and driver code. This patch does the following: (a) replace kzalloc with devm_kzalloc. (b) drop kfree(), because memory allocated with devm_kzalloc() is automatically freed on driver detach, otherwise it leads to a double free. (c) remove unnecessary blank lines. Signed-off-by: Suniel Mahesh [gby: rebase on top of latest coding style fixes changes] Acked-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_driver.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) -- 2.1.4 diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index 9c6f120..47e0880 100644 --- a/drivers/staging/ccree/ssi_driver.c +++ b/drivers/staging/ccree/ssi_driver.c @@ -223,14 +223,15 @@ static int init_cc_resources(struct platform_device *plat_dev) struct resource *req_mem_cc_regs = NULL; void __iomem *cc_base = NULL; bool irq_registered = false; - struct ssi_drvdata *new_drvdata = kzalloc(sizeof(*new_drvdata), - GFP_KERNEL); + struct ssi_drvdata *new_drvdata; struct device *dev = &plat_dev->dev; struct device_node *np = dev->of_node; u32 signature_val; int rc = 0; - if (unlikely(!new_drvdata)) { + new_drvdata = devm_kzalloc(&plat_dev->dev, sizeof(*new_drvdata), + GFP_KERNEL); + if (!new_drvdata) { SSI_LOG_ERR("Failed to allocate drvdata"); rc = -ENOMEM; goto init_cc_res_err; @@ -435,10 +436,8 @@ static int init_cc_resources(struct platform_device *plat_dev) resource_size(new_drvdata->res_mem)); new_drvdata->res_mem = NULL; } - kfree(new_drvdata); dev_set_drvdata(&plat_dev->dev, NULL); } - return rc; } @@ -479,8 +478,6 @@ static void cleanup_cc_resources(struct platform_device *plat_dev) drvdata->cc_base = NULL; drvdata->res_mem = NULL; } - - kfree(drvdata); dev_set_drvdata(&plat_dev->dev, NULL); }