Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1120769rwl; Fri, 24 Mar 2023 06:36:39 -0700 (PDT) X-Google-Smtp-Source: AKy350ajxel4RtFV1kscjDM8KVHOBmqA4W6vU8bq5COkJScPflemM9Nc+d9Ju6KcJ/SGQ3cQMqVI X-Received: by 2002:a17:906:9f15:b0:92f:b47c:cefc with SMTP id fy21-20020a1709069f1500b0092fb47ccefcmr2341474ejc.24.1679664999504; Fri, 24 Mar 2023 06:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679664999; cv=none; d=google.com; s=arc-20160816; b=QbXAp9PPdS++3cO9M6i7QJIkgNbwW8D/ZXD163ZinGjukGXeU3fGCPDhc6bKcbPAXg WsEP+bf2Tz02c6qKQt8ENC9HhauqDGGynz6QiWWCy9GXmhCaJ5Xhs+8m8dFzhOL9QMZQ TjeketjnpVSMBAWNwOW9CHFJy6JfR+B8Ebd6RoAlJ8PDnRO1VJa0/uENHSu4uq5EhOwn qhpAPtKMLE75A/BtCWbtbl+dHF15jKmnVb4R78FcS4saag6NCvJFPZyRBn7n1OZ79RTx h6NYhUXhFEsroHtnSDWE/R++f8YiNzNft4McmsCi+gEqDdQA8yPdE5uE1Yi75QmmUQ3p zLyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wpsgv0KkvhRGAPOSzRX2sYw/gF6egFw3AhLvp8rj5ws=; b=bD6Jh0HwVZpeWOS2dheJ1D7ekK/Rhxw7krrVLf8TDyT0joRi35BZer+NRMo+wfyT+f 66gu4oatAEDo+GT7i5+K+EoEnS7MvwxYdCjVBbAsSei+7fLuIHXbQJXNkwrwEgAOC6s2 8Hr7aVvuTktEBbQCe7X27+bRj/JTzixKJcZGIShLcGKasPO2XLX63nZ5Fq63CdNzohAH acK2Yl3QRotqg+EDjeEYM8hfr2du4L6MiKtU3X5Yd9FprZ4AXDguOYV5x0RMaFUMz6Y5 iEwpmmPnMuDvZyTUv4ZsDa5waqM+xEUQ0ISmZAYtix9vDFSPSyoKzlMXurCeVGIAY1WO 6g/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RF58HTF7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id tx9-20020a1709078e8900b009334769e7ebsi14945736ejc.790.2023.03.24.06.36.05; Fri, 24 Mar 2023 06:36:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RF58HTF7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231411AbjCXNe7 (ORCPT + 99 others); Fri, 24 Mar 2023 09:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231718AbjCXNez (ORCPT ); Fri, 24 Mar 2023 09:34:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 951D617CF3; Fri, 24 Mar 2023 06:34:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E4EDFB82303; Fri, 24 Mar 2023 13:34:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5592C433D2; Fri, 24 Mar 2023 13:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679664883; bh=c2wu/Bm6WNJUHMK4Ot6Thtt09tmyqbq2bKCvZMjcFjg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RF58HTF7nUyUZJM+ewY5DWouIpgdEcA+xCCfNxfxKM8dJ97k22amzo5nBqLcGZ+gb 7V7yEoppzLj12owLbBoe7EL5B+qJwwOJ1BQCYh6/d27so9O40ZZvpWOLphxwDJrKur S2TtyUmiqq6w0xT9kp2Kn9S6TbhDIJtF8EDHSliOiCruS5da9k/SQYdDTrzDIp2LBK LdLMohgeBUhx0U6BSqNF4HhUNYEEdSrmdPyDGa+gFC2D3duadcY0vtAgr6kdWqFQLF egVQPYkZ1nk1oJpPkhXdsymD6bFARB0ajpG0ki1hlYnKvoxrA5AnpIc0Ju14x67IqO uuB9nky2OJc0g== Date: Fri, 24 Mar 2023 06:37:52 -0700 From: Bjorn Andersson To: Krzysztof Kozlowski Cc: Andy Gross , Konrad Dybcio , "Rafael J. Wysocki" , Viresh Kumar , Manivannan Sadhasivam , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] cpufreq: qcom-cpufreq-hw: fix double IO unmap and resource release on exit Message-ID: <20230324133752.owl5euvurik3t64q@ripper> References: <20230323174026.950622-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230323174026.950622-1-krzysztof.kozlowski@linaro.org> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 23, 2023 at 06:40:26PM +0100, Krzysztof Kozlowski wrote: > Commit 054a3ef683a1 ("cpufreq: qcom-hw: Allocate qcom_cpufreq_data > during probe") moved getting memory resource and iomap from > qcom_cpufreq_hw_cpu_init() to the probe function, however it left > untouched cleanup in qcom_cpufreq_hw_cpu_exit(). > > During device unbind this will lead to doule release of resource and > double iounmap(), first by qcom_cpufreq_hw_cpu_exit() and second via > managed resources: > > resource: Trying to free nonexistent resource <0x0000000018593000-0x0000000018593fff> > Trying to vunmap() nonexistent vm area (0000000088a7d4dc) > ... > vunmap (mm/vmalloc.c:2771 (discriminator 1)) > iounmap (mm/ioremap.c:60) > devm_ioremap_release (lib/devres.c:19) > devres_release_all (drivers/base/devres.c:506 drivers/base/devres.c:535) > device_unbind_cleanup (drivers/base/dd.c:523) > device_release_driver_internal (drivers/base/dd.c:1248 drivers/base/dd.c:1263) > device_driver_detach (drivers/base/dd.c:1300) > unbind_store (drivers/base/bus.c:243) > drv_attr_store (drivers/base/bus.c:127) > sysfs_kf_write (fs/sysfs/file.c:137) > kernfs_fop_write_iter (fs/kernfs/file.c:334) > vfs_write (include/linux/fs.h:1851 fs/read_write.c:491 fs/read_write.c:584) > ksys_write (fs/read_write.c:637) > __arm64_sys_write (fs/read_write.c:646) > invoke_syscall (arch/arm64/include/asm/current.h:19 arch/arm64/kernel/syscall.c:57) > el0_svc_common.constprop.0 (arch/arm64/include/asm/daifflags.h:28 arch/arm64/kernel/syscall.c:150) > do_el0_svc (arch/arm64/kernel/syscall.c:194) > el0_svc (arch/arm64/include/asm/daifflags.h:28 arch/arm64/kernel/entry-common.c:133 arch/arm64/kernel/entry-common.c:142 arch/arm64/kernel/entry-common.c:638) > el0t_64_sync_handler (arch/arm64/kernel/entry-common.c:656) > el0t_64_sync (arch/arm64/kernel/entry.S:591) > > Fixes: 054a3ef683a1 ("cpufreq: qcom-hw: Allocate qcom_cpufreq_data during probe") > Cc: > Cc: Manivannan Sadhasivam > Signed-off-by: Krzysztof Kozlowski Reviewed-by: Bjorn Andersson Regards, Bjorn > --- > drivers/cpufreq/qcom-cpufreq-hw.c | 11 ++--------- > 1 file changed, 2 insertions(+), 9 deletions(-) > > diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c > index 2f581d2d617d..b2d2907200a9 100644 > --- a/drivers/cpufreq/qcom-cpufreq-hw.c > +++ b/drivers/cpufreq/qcom-cpufreq-hw.c > @@ -43,7 +43,6 @@ struct qcom_cpufreq_soc_data { > > struct qcom_cpufreq_data { > void __iomem *base; > - struct resource *res; > > /* > * Mutex to synchronize between de-init sequence and re-starting LMh > @@ -590,16 +589,12 @@ static int qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) > { > struct device *cpu_dev = get_cpu_device(policy->cpu); > struct qcom_cpufreq_data *data = policy->driver_data; > - struct resource *res = data->res; > - void __iomem *base = data->base; > > dev_pm_opp_remove_all_dynamic(cpu_dev); > dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); > qcom_cpufreq_hw_lmh_exit(data); > kfree(policy->freq_table); > kfree(data); > - iounmap(base); > - release_mem_region(res->start, resource_size(res)); > > return 0; > } > @@ -718,17 +713,15 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev) > for (i = 0; i < num_domains; i++) { > struct qcom_cpufreq_data *data = &qcom_cpufreq.data[i]; > struct clk_init_data clk_init = {}; > - struct resource *res; > void __iomem *base; > > - base = devm_platform_get_and_ioremap_resource(pdev, i, &res); > + base = devm_platform_ioremap_resource(pdev, i); > if (IS_ERR(base)) { > - dev_err(dev, "Failed to map resource %pR\n", res); > + dev_err(dev, "Failed to map resource index %d\n", i); > return PTR_ERR(base); > } > > data->base = base; > - data->res = res; > > /* Register CPU clock for each frequency domain */ > clk_init.name = kasprintf(GFP_KERNEL, "qcom_cpufreq%d", i); > -- > 2.34.1 >