From patchwork Thu Jul 27 14:27:32 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: 108836 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2130884qge; Thu, 27 Jul 2017 07:27:45 -0700 (PDT) X-Received: by 10.98.159.12 with SMTP id g12mr4304723pfe.279.1501165665676; Thu, 27 Jul 2017 07:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501165665; cv=none; d=google.com; s=arc-20160816; b=oky47/hX6PnYeToZVbL4oxJOV8iM5/phYu6YWNjUKdyk0w0TlAzX1ezpqzVHF4WDTV kwiWvFBOiCINe0WwCKKINo0FtERzZN7jnQkq08NK/RoaDzE/3INKxYrfscOVoYM/Sfly Noek0s2o+RXHUGlfFuOkk+br49nLGbHCE5Z40Xm/11BCJ1RyjJ1/Tgrk5uf4AQrDAoyR PhefqvKEX0CfeyqkMR3V0HVHobugi+NNudhlYJpAWbjLbxKySY3GRsvTEJdqj8jhWvEO Ltj5j11V4f1eWp1eLEd1RbVe+ZM4UG+HlDvFy4QdVtnpWCl4l17aLmalsxAuqTLnxcDl NSig== 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=M2qe8fGIxBNn/s3iNB6AP154lF75SILfnxymUYwiPDU=; b=sFiH89fNLScNHC7e8f4e0oFj3gu0Ck8BwAeK7S0Igl4zsngIQiPo8ZtH55aI2LksbQ y4aqyJo55CPElYoRt4bLUDIJjfsMXNWaIG9oObYNh6gW9Kogy4daBto4zKr9LQaHWjri ASUqA4O+FEoeGtIZXoFscAIH9kAjU6MdRQ4KcIMrD22jtPq8Ffuqcc2N2OdaYikmvlxx Cz5RcckZMEHLZMvrfYITFYJmMIY5sIwNgSlbmNL2Tt7b/XuE46lTxe4aWngR6ijlKFQ5 JK5f9wkfRgV1T4NYf33Wt1uB3fIFIWgclh9w2v8RLAyNMLh+u2AHcHTp7v4vvXF8iiXW ODPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 1si11685334plx.462.2017.07.27.07.27.45; Thu, 27 Jul 2017 07:27:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751569AbdG0O1o (ORCPT + 1 other); Thu, 27 Jul 2017 10:27:44 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47390 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751539AbdG0O1n (ORCPT ); Thu, 27 Jul 2017 10:27:43 -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 44C7A13D5; Thu, 27 Jul 2017 07:27:43 -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 764C93F540; Thu, 27 Jul 2017 07:27:41 -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/3] staging: ccree: Replace kzalloc with devm_kzalloc Date: Thu, 27 Jul 2017 17:27:32 +0300 Message-Id: <1501165654-30601-1-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@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 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) -- 2.1.4 diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index 1cae2b7..97dfc2c 100644 --- a/drivers/staging/ccree/ssi_driver.c +++ b/drivers/staging/ccree/ssi_driver.c @@ -223,13 +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; @@ -434,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; } @@ -478,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); }