From patchwork Sun Sep 3 14:57:36 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: 111519 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp454073qge; Sun, 3 Sep 2017 07:58:03 -0700 (PDT) X-Google-Smtp-Source: ADKCNb4m1T4vEJ1HAjCCm815R8Lfw9KRvCIAlVgUyy6Xz/q/q9qAokLZccGzxjR0VfEch8LLAKv9 X-Received: by 10.84.225.5 with SMTP id t5mr8213171plj.333.1504450683557; Sun, 03 Sep 2017 07:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504450683; cv=none; d=google.com; s=arc-20160816; b=v9Dg07yTZaSa4Oo/j48ejv7ha6XGE7oAohx2MUp1WKpdSHfUkFanFJ4d1hPeK0E5AS i/rhOC4r1ZNG6NxOGz+C2zaa2MO9n/9ZggfGV40SCsknzJI/DJq6bxcIL4ZAwDM6nj3t qRmKwZH1OXaa/YDPjDgEsJkLOuhSmuyi8HTehVCnHx4WbLCKck4xQC0HwgJP0CX4cuTp 5s00364GvpjQ9vQanHzQZFHBXxtwT+MoqTpSHt/npeFE7qbLjSlDv/4US6DfOHSA2sA2 M0GCpMbPiOVg8WEJPdR7Qqqi3JARTUoj3WxcqQaeJrA+tLd734fZZSZM4EombTUWWZY9 np6A== 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=ILlRLXWNqvIBTMWDZljcCaKBkCHRa62pb422ncixL02d/U+M/Sp95jmDVrmC3Ro9Iq p4wNm5YwgFAxtUiMWRTW1qiUfn+fiFxRiWE+bqK1eEokEyNUD/043yeC4a/u0Zq4ezxu 7RsTSna86oTMKAxc1rn8hDcf8uQGVNfiNAcY5jGKteV70+fAwUHlpbgXQng8A3Fhy6g4 ZPfOdaEL9BoSTllIfK76fhZYN3depNY8ZlN864rl0FUL94mYBlD/ZZOGpTsZklpS9IeN xS/za0/UKrdJ/HFwBN4/0jbIAzfNpDzZu1jHpyPpWqOAvu4usX/1AsjI6bkMkZE39/4T 9n+g== 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 e68si3397070pfb.300.2017.09.03.07.58.03; Sun, 03 Sep 2017 07:58:03 -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 S1753165AbdICO55 (ORCPT + 26 others); Sun, 3 Sep 2017 10:57:57 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50852 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753142AbdICO5y (ORCPT ); Sun, 3 Sep 2017 10:57:54 -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 5EFD680D; Sun, 3 Sep 2017 07:57:54 -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 02AF93F3E1; Sun, 3 Sep 2017 07:57:51 -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 v2 1/8] staging: ccree: Replace kzalloc with devm_kzalloc Date: Sun, 3 Sep 2017 17:57:36 +0300 Message-Id: <1504450664-28252-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504450664-28252-1-git-send-email-gilad@benyossef.com> References: <1504450664-28252-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); }