From patchwork Sun Sep 3 08:56:43 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: 111516 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp175490qge; Sun, 3 Sep 2017 01:58:58 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5ZzztBO/8OC6e5OJD6n0PH17PgrCgsFBB31gNLGMjtn2BlXr9rI8Hp/co7cspA67/fCf1J X-Received: by 10.99.99.6 with SMTP id x6mr8334908pgb.224.1504429138642; Sun, 03 Sep 2017 01:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504429138; cv=none; d=google.com; s=arc-20160816; b=OACCZO3QDZ330BaWY0d81pBkGKIyzi6PQCjXI7JEM+bVH38cimQ9CdP/nMS/6ucbg7 pvZgKNXZ87XRLIRchE+hGrE8dox32fkXfV+lPwYztESKHjchp6ASMZDpZk3yE0kJURIO YGCsgiBmm+YNyNU/3ww8yrgZx7hJNswGMghYHwVFFbH/b8hvdjZJ61dTyUlTxPiTDsmr 5ruIoMFAK0aoTYOvt9ZcJijFHpe9QloE/O50t5+S4lpZ12ZzQFx/E0Z4crB4LMNd3Skz Yk6mSbYJri0jCflEGA8WrYtN4Aqtey+U4eKJaFaZigOIPeyUaEvARqddajjkx3E5JxDP qrIg== 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=ETFMuQ7i+ASEbt6lCVoZwHPLf35dYVR9eD0WNlwxE3BStweryQku4iU6maNWG9CaAP d7H5aJVp4rdZyoSWiVn44B6Tei9JZcgD0pabBxPMgw9Z51syN29OVoqyVyNZ/mDTDzGA 5nYlUFl+1K2RCBWJR27NxvaZQxIUlrPUM4eNoU9vSKwi23kbQwvfDCalnaCJZd8J6NoM UfRRKfM+o6gAyJ5XMcrvdYAuOEshAKVqA308ca9ZtbhuMwjdULriWNKD1eRwbBGxdCRk cpLTh/4lAgYn5eTDDr+num2TYFNp2yymbunP3QXL/wdP+kkjZK/0o/y9bO0tGmWQBEYH ld+A== 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 m87si3085859pfi.469.2017.09.03.01.58.58; Sun, 03 Sep 2017 01:58:58 -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 S1752130AbdICI5G (ORCPT + 26 others); Sun, 3 Sep 2017 04:57:06 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:49098 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751119AbdICI5B (ORCPT ); Sun, 3 Sep 2017 04:57:01 -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 20B1B2B; Sun, 3 Sep 2017 01:57:01 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D30303F483; Sun, 3 Sep 2017 01:56:58 -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 1/8] staging: ccree: Replace kzalloc with devm_kzalloc Date: Sun, 3 Sep 2017 11:56:43 +0300 Message-Id: <1504429011-25514-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504429011-25514-1-git-send-email-gilad@benyossef.com> References: <1504429011-25514-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); }