From patchwork Thu Jul 13 18:19:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tai Nguyen X-Patchwork-Id: 9839589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 72AB8602A0 for ; Thu, 13 Jul 2017 18:22:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E66C42881F for ; Thu, 13 Jul 2017 21:24:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D89AA2882F; Thu, 13 Jul 2017 21:24:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F01642881F for ; Thu, 13 Jul 2017 21:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=OvZt7T9iqyQ+1BQx7/AV1q5qlbS9fVGhvy/ODqEVmLs=; b=nsM 0k/jpyNJuigtj9c0tFYMmmfrw8gVgaTum7cs+Of/pYodxTgtgWZXfX+da/9o3Bo2xVuqppU+MKMlm 69YlKBXkxg6yWP/+xayPUrS6EpqyE667aOiX2mJMCNT+DNHl1AbPLFhs88FcClBagawwnJi7DHyp5 4HSTvlXIwDqze4Y6OLum3pD+nHiKYkbJ2+ENBz4a5R9ZCWiwInt/X9wpCjnfBTqe2u5YCvEv5Vgqs HvM/CD+s9fuvFEFj3PysOsbOHuHmUH0BOtydo8nNG2e7Te/nPy02/mTgxJKafNZNgwrT8QCIXCxF0 kI+FapEGXkCENBD/JziZt0VWe3ql+5Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dVikD-00009G-FP; Thu, 13 Jul 2017 18:21:45 +0000 Received: from mail-pg0-x236.google.com ([2607:f8b0:400e:c05::236]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dVik9-00007q-9U for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2017 18:21:43 +0000 Received: by mail-pg0-x236.google.com with SMTP id k14so33612123pgr.0 for ; Thu, 13 Jul 2017 11:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id; bh=KQHfQUKt2o06/VVrEAhxKt+VLTDB3xGW/PyAGvrB1mA=; b=NGj/HPOJYtuX1FgmVqFTDWfGcNqV8OQUpXeHwcU12OxIzliYr0ww3AJ+Qy62mesQ73 DxGg6MT38jKh2hcYU1oSJYxjJk0jzDVD5m8sigdHuToBD5KednWkSyefK1ACa2QEtdX1 gl0jt0PfvDSVB219uAYSYNdHidrGb0gzgMCq0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KQHfQUKt2o06/VVrEAhxKt+VLTDB3xGW/PyAGvrB1mA=; b=W8T8Knqyla+Lzi0MzfhWI6rIwPN2ZWrNY+2i5weH8sqFqnygyr0tymn5mNzFOqCTzR JpM1NEWCD9rxpkjzGMGBcNxQhnlSqaNh8LOGxMhBDFBGdnyZ/g4OtrLhTUGQHs7uY3uc 4HvV0FOaoGhJ0hRPuuC7sGuERLKomtFPyi2SDDbcAQo37EHj1aW2RhVHoRLNLZ1KhYQ2 lTyEPkUMmisWLfB81umTAG81xa33r2LhbXlKpVDQKLvmMwixNSUiPRE9rngVjljDGolG 7mnVmT0wwatZngLz+MyUY8FTH6w9ntsEowdrZcz/WPTZOmQPKQj06EcJG12loVLosFPx e5UQ== X-Gm-Message-State: AIVw110EuyvlB/ARhokxhzlJopyxH5eB/2jUgQGk6RaJUcv4S0NdWxWH iIjcjYxQhXHzvySd X-Received: by 10.84.215.150 with SMTP id l22mr11817760pli.29.1499970079882; Thu, 13 Jul 2017 11:21:19 -0700 (PDT) Received: from ttnguyen-Ubuntu.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id r73sm15181705pgr.32.2017.07.13.11.21.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jul 2017 11:21:19 -0700 (PDT) From: Tai Nguyen To: mark.rutland@arm.com, will.deacon@arm.com Subject: [PATCH] perf: xgene: Remove unnecessary managed resources cleanup Date: Thu, 13 Jul 2017 11:19:08 -0700 Message-Id: <1499969948-24755-1-git-send-email-ttnguyen@apm.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170713_112141_419563_B938D713 X-CRM114-Status: GOOD ( 13.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hotran@apm.com, linux-kernel@vger.kernel.org, lho@apm.com, dan.carpenter@oracle.com, linux-arm-kernel@lists.infradead.org, Tai Nguyen MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Managed resources in the driver should be automatically cleaned up on driver detach. It's unnecessary to manually free/unmmap these resources. One of the manual cleanup causes static checkers to complain. The bug is reported by Dan Carpenter in [1] [1] https://www.spinics.net/lists/arm-kernel/msg593012.html This patch gets rid of all the unnecessary manual cleanup and properly unregister all the registered PMU devices by the driver on driver detach. Signed-off-by: Tai Nguyen --- drivers/perf/xgene_pmu.c | 74 ++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c index e841282..eb23311 100644 --- a/drivers/perf/xgene_pmu.c +++ b/drivers/perf/xgene_pmu.c @@ -1147,7 +1147,6 @@ static int xgene_init_perf(struct xgene_pmu_dev *pmu_dev, char *name) { struct device *dev = xgene_pmu->dev; struct xgene_pmu_dev *pmu; - int rc; pmu = devm_kzalloc(dev, sizeof(*pmu), GFP_KERNEL); if (!pmu) @@ -1159,7 +1158,7 @@ static int xgene_init_perf(struct xgene_pmu_dev *pmu_dev, char *name) switch (pmu->inf->type) { case PMU_TYPE_L3C: if (!(xgene_pmu->l3c_active_mask & pmu->inf->enable_mask)) - goto dev_err; + return -ENODEV; if (xgene_pmu->version == PCP_PMU_V3) pmu->attr_groups = l3c_pmu_v3_attr_groups; else @@ -1177,7 +1176,7 @@ static int xgene_init_perf(struct xgene_pmu_dev *pmu_dev, char *name) break; case PMU_TYPE_MCB: if (!(xgene_pmu->mcb_active_mask & pmu->inf->enable_mask)) - goto dev_err; + return -ENODEV; if (xgene_pmu->version == PCP_PMU_V3) pmu->attr_groups = mcb_pmu_v3_attr_groups; else @@ -1185,7 +1184,7 @@ static int xgene_init_perf(struct xgene_pmu_dev *pmu_dev, char *name) break; case PMU_TYPE_MC: if (!(xgene_pmu->mc_active_mask & pmu->inf->enable_mask)) - goto dev_err; + return -ENODEV; if (xgene_pmu->version == PCP_PMU_V3) pmu->attr_groups = mc_pmu_v3_attr_groups; else @@ -1195,19 +1194,14 @@ static int xgene_init_perf(struct xgene_pmu_dev *pmu_dev, char *name) return -EINVAL; } - rc = xgene_init_perf(pmu, ctx->name); - if (rc) { + if (xgene_init_perf(pmu, ctx->name)) { dev_err(dev, "%s PMU: Failed to init perf driver\n", ctx->name); - goto dev_err; + return -ENODEV; } dev_info(dev, "%s PMU registered\n", ctx->name); - return rc; - -dev_err: - devm_kfree(dev, pmu); - return -ENODEV; + return 0; } static void _xgene_pmu_isr(int irq, struct xgene_pmu_dev *pmu_dev) @@ -1515,13 +1509,13 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, acpi_dev_free_resource_list(&resource_list); if (rc < 0) { dev_err(dev, "PMU type %d: No resource address found\n", type); - goto err; + return NULL; } dev_csr = devm_ioremap_resource(dev, &res); if (IS_ERR(dev_csr)) { dev_err(dev, "PMU type %d: Fail to map resource\n", type); - goto err; + return NULL; } /* A PMU device node without enable-bit-index is always enabled */ @@ -1535,7 +1529,7 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, ctx->name = xgene_pmu_dev_name(dev, type, enable_bit); if (!ctx->name) { dev_err(dev, "PMU type %d: Fail to get device name\n", type); - goto err; + return NULL; } inf = &ctx->inf; inf->type = type; @@ -1543,9 +1537,6 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, inf->enable_mask = 1 << enable_bit; return ctx; -err: - devm_kfree(dev, ctx); - return NULL; } static const struct acpi_device_id xgene_pmu_acpi_type_match[] = { @@ -1663,20 +1654,20 @@ xgene_pmu_dev_ctx *fdt_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, void __iomem *dev_csr; struct resource res; int enable_bit; - int rc; ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); if (!ctx) return NULL; - rc = of_address_to_resource(np, 0, &res); - if (rc < 0) { + + if (of_address_to_resource(np, 0, &res) < 0) { dev_err(dev, "PMU type %d: No resource address found\n", type); - goto err; + return NULL; } + dev_csr = devm_ioremap_resource(dev, &res); if (IS_ERR(dev_csr)) { dev_err(dev, "PMU type %d: Fail to map resource\n", type); - goto err; + return NULL; } /* A PMU device node without enable-bit-index is always enabled */ @@ -1686,17 +1677,15 @@ xgene_pmu_dev_ctx *fdt_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu, ctx->name = xgene_pmu_dev_name(dev, type, enable_bit); if (!ctx->name) { dev_err(dev, "PMU type %d: Fail to get device name\n", type); - goto err; + return NULL; } + inf = &ctx->inf; inf->type = type; inf->csr = dev_csr; inf->enable_mask = 1 << enable_bit; return ctx; -err: - devm_kfree(dev, ctx); - return NULL; } static int fdt_pmu_probe_pmu_dev(struct xgene_pmu *xgene_pmu, @@ -1868,22 +1857,20 @@ static int xgene_pmu_probe(struct platform_device *pdev) xgene_pmu->pcppmu_csr = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(xgene_pmu->pcppmu_csr)) { dev_err(&pdev->dev, "ioremap failed for PCP PMU resource\n"); - rc = PTR_ERR(xgene_pmu->pcppmu_csr); - goto err; + return PTR_ERR(xgene_pmu->pcppmu_csr); } irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "No IRQ resource\n"); - rc = -EINVAL; - goto err; + return -EINVAL; } rc = devm_request_irq(&pdev->dev, irq, xgene_pmu_isr, IRQF_NOBALANCING | IRQF_NO_THREAD, dev_name(&pdev->dev), xgene_pmu); if (rc) { dev_err(&pdev->dev, "Could not request IRQ %d\n", irq); - goto err; + return rc; } raw_spin_lock_init(&xgene_pmu->lock); @@ -1903,42 +1890,29 @@ static int xgene_pmu_probe(struct platform_device *pdev) rc = irq_set_affinity(irq, &xgene_pmu->cpu); if (rc) { dev_err(&pdev->dev, "Failed to set interrupt affinity!\n"); - goto err; + return rc; } /* Walk through the tree for all PMU perf devices */ rc = xgene_pmu_probe_pmu_dev(xgene_pmu, pdev); if (rc) { dev_err(&pdev->dev, "No PMU perf devices found!\n"); - goto err; + return rc; } /* Enable interrupt */ xgene_pmu->ops->unmask_int(xgene_pmu); return 0; - -err: - if (xgene_pmu->pcppmu_csr) - devm_iounmap(&pdev->dev, xgene_pmu->pcppmu_csr); - devm_kfree(&pdev->dev, xgene_pmu); - - return rc; } static void xgene_pmu_dev_cleanup(struct xgene_pmu *xgene_pmu, struct list_head *pmus) { struct xgene_pmu_dev_ctx *ctx; - struct device *dev = xgene_pmu->dev; - struct xgene_pmu_dev *pmu_dev; list_for_each_entry(ctx, pmus, next) { - pmu_dev = ctx->pmu_dev; - if (pmu_dev->inf->csr) - devm_iounmap(dev, pmu_dev->inf->csr); - devm_kfree(dev, ctx); - devm_kfree(dev, pmu_dev); + perf_pmu_unregister(&ctx->pmu_dev->pmu); } } @@ -1951,10 +1925,6 @@ static int xgene_pmu_remove(struct platform_device *pdev) xgene_pmu_dev_cleanup(xgene_pmu, &xgene_pmu->mcbpmus); xgene_pmu_dev_cleanup(xgene_pmu, &xgene_pmu->mcpmus); - if (xgene_pmu->pcppmu_csr) - devm_iounmap(&pdev->dev, xgene_pmu->pcppmu_csr); - devm_kfree(&pdev->dev, xgene_pmu); - return 0; }