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); } From patchwork Thu Jul 27 14:27:33 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: 108837 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2131036qge; Thu, 27 Jul 2017 07:27:51 -0700 (PDT) X-Received: by 10.99.102.68 with SMTP id a65mr4271225pgc.252.1501165671082; Thu, 27 Jul 2017 07:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501165671; cv=none; d=google.com; s=arc-20160816; b=cSWoBzMZksRmv5+VSqc6p/vqnsMu/JBVq1ghvvowuMR1P2wpLGh0s+4QmKiZA5Cgpi dyye0Bwi1TE2O/y16DszWnZ4Es6yaDFiJ18Eg///JmnrSHftB8nbks5tnk4HSH09ZTQu ZDFub3Wmbkq3WceURsN3xD3U6na9t/JPFmT8KiJpUNLBHPSxuAoZseOUx/KsCnmC4rhc SQeau08GGL9ND8Y3lc8Xm+YUYVwXJBNPyaxvXxzLia8SrxTomTy8kA2+503JtID1z9P4 ecyo58FRJGeohC/eVsiqo/PKL1CXD84tWwLeJILek+XKu3XQrSiLkE3Q/3LQMDsHgWlb R/2g== 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=775itMP3phtK2DrvnSjo6uYHFay+Ho2CKzL4I67ISBU=; b=yFFvtgIQ7os5QCHbqEz7IEJrK+n1i6hgIovaaGgIWG29hgoqakl/8hJh0g/6JTn006 IvS64OvBrqmRg4wumrKFjZcI8s3ntHsRHNcLPXn3H3UPrDKLjRbApeunnXnBoNIIo8Po CmR17D0TAqSyaT//0pCZn8oX5fIf1wHZMadQxTtdp6IHAlrjta3qpI0orexsQUTe2LSZ bPPgpTqnJfyhcbYTceRGHqbiwKlIfdLJFIcWoeY1i670M63JdolXckgqbnwwEgRnicH6 cMG9GyIvYOhkokPv//L0VllrapIpzUddPAPkYLnFzAvZM55BVcEImh39djSCO9C8tctl tunQ== 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 f3si11183492pgn.157.2017.07.27.07.27.50; Thu, 27 Jul 2017 07:27:51 -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 S1751800AbdG0O1s (ORCPT + 1 other); Thu, 27 Jul 2017 10:27:48 -0400 Received: from foss.arm.com ([217.140.101.70]:47406 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751797AbdG0O1q (ORCPT ); Thu, 27 Jul 2017 10:27:46 -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 DB01C13D5; Thu, 27 Jul 2017 07:27:45 -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 171A73F540; Thu, 27 Jul 2017 07:27:43 -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 2/3] staging: ccree: Convert to devm_ioremap_resource for map, unmap Date: Thu, 27 Jul 2017 17:27:33 +0300 Message-Id: <1501165654-30601-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1501165654-30601-1-git-send-email-gilad@benyossef.com> References: <1501165654-30601-1-git-send-email-gilad@benyossef.com> 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_ioremap_resource(), which simplifies driver cleanup paths and driver code. This patch does the following: (a) replace request_mem_region(), ioremap() and corresponding error handling with devm_ioremap_resource(). (b) remove struct resource pointer(res_mem) in struct ssi_drvdata as it seems redundant, use struct resource pointer which is defined locally and adjust return value of platform_get_resource() accordingly. (c) release_mem_region() and iounmap() are dropped, since devm_ioremap_ resource() releases and unmaps mem region on driver detach. (d) adjust log messages accordingly and remove any 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 | 60 ++++++++++---------------------------- drivers/staging/ccree/ssi_driver.h | 1 - 2 files changed, 15 insertions(+), 46 deletions(-) -- 2.1.4 diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index 97dfc2c..603eb03 100644 --- a/drivers/staging/ccree/ssi_driver.c +++ b/drivers/staging/ccree/ssi_driver.c @@ -246,35 +246,21 @@ static int init_cc_resources(struct platform_device *plat_dev) dev_set_drvdata(&plat_dev->dev, new_drvdata); /* Get device resources */ /* First CC registers space */ - new_drvdata->res_mem = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); - if (unlikely(!new_drvdata->res_mem)) { - SSI_LOG_ERR("Failed getting IO memory resource\n"); - rc = -ENODEV; - goto init_cc_res_err; - } - SSI_LOG_DEBUG("Got MEM resource (%s): start=%pad end=%pad\n", - new_drvdata->res_mem->name, - new_drvdata->res_mem->start, - new_drvdata->res_mem->end); + req_mem_cc_regs = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); /* Map registers space */ - req_mem_cc_regs = request_mem_region(new_drvdata->res_mem->start, resource_size(new_drvdata->res_mem), "arm_cc7x_regs"); - if (unlikely(!req_mem_cc_regs)) { - SSI_LOG_ERR("Couldn't allocate registers memory region at 0x%08X\n", - (unsigned int)new_drvdata->res_mem->start); - rc = -EBUSY; - goto init_cc_res_err; - } - cc_base = ioremap(new_drvdata->res_mem->start, resource_size(new_drvdata->res_mem)); - if (unlikely(!cc_base)) { - SSI_LOG_ERR("ioremap[CC](0x%08X,0x%08X) failed\n", - (unsigned int)new_drvdata->res_mem->start, - (unsigned int)resource_size(new_drvdata->res_mem)); - rc = -ENOMEM; + new_drvdata->cc_base = devm_ioremap_resource(&plat_dev->dev, + req_mem_cc_regs); + if (IS_ERR(new_drvdata->cc_base)) { + rc = PTR_ERR(new_drvdata->cc_base); goto init_cc_res_err; } - SSI_LOG_DEBUG("CC registers mapped from %pa to 0x%p\n", &new_drvdata->res_mem->start, cc_base); - new_drvdata->cc_base = cc_base; - + SSI_LOG_DEBUG("Got MEM resource (%s): start=%pad end=%pad\n", + req_mem_cc_regs->name, + req_mem_cc_regs->start, + req_mem_cc_regs->end); + SSI_LOG_DEBUG("CC registers mapped from %pa to 0x%p\n", + &req_mem_cc_regs->start, new_drvdata->cc_base); + cc_base = new_drvdata->cc_base; /* Then IRQ */ new_drvdata->res_irq = platform_get_resource(plat_dev, IORESOURCE_IRQ, 0); if (unlikely(!new_drvdata->res_irq)) { @@ -424,17 +410,9 @@ static int init_cc_resources(struct platform_device *plat_dev) #ifdef ENABLE_CC_SYSFS ssi_sysfs_fini(); #endif - - if (req_mem_cc_regs) { - if (irq_registered) { - free_irq(new_drvdata->res_irq->start, new_drvdata); - new_drvdata->res_irq = NULL; - iounmap(cc_base); - new_drvdata->cc_base = NULL; - } - release_mem_region(new_drvdata->res_mem->start, - resource_size(new_drvdata->res_mem)); - new_drvdata->res_mem = NULL; + if (irq_registered) { + free_irq(new_drvdata->res_irq->start, new_drvdata); + new_drvdata->res_irq = NULL; } dev_set_drvdata(&plat_dev->dev, NULL); } @@ -470,14 +448,6 @@ static void cleanup_cc_resources(struct platform_device *plat_dev) cc_clk_off(drvdata); free_irq(drvdata->res_irq->start, drvdata); drvdata->res_irq = NULL; - - if (drvdata->cc_base) { - iounmap(drvdata->cc_base); - release_mem_region(drvdata->res_mem->start, - resource_size(drvdata->res_mem)); - drvdata->cc_base = NULL; - drvdata->res_mem = NULL; - } dev_set_drvdata(&plat_dev->dev, NULL); } diff --git a/drivers/staging/ccree/ssi_driver.h b/drivers/staging/ccree/ssi_driver.h index b6ad89a..518c0bf 100644 --- a/drivers/staging/ccree/ssi_driver.h +++ b/drivers/staging/ccree/ssi_driver.h @@ -128,7 +128,6 @@ struct ssi_crypto_req { * @fw_ver: SeP loaded firmware version */ struct ssi_drvdata { - struct resource *res_mem; struct resource *res_irq; void __iomem *cc_base; unsigned int irq;