Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7959180rwl; Thu, 23 Mar 2023 10:43:01 -0700 (PDT) X-Google-Smtp-Source: AKy350ZhwstjsT3UcTllKmO2P1GfmKt7LH7z6uvefkNysuTEcSQ+xlrLvNyxmxH+SkPAIqLo/8a7 X-Received: by 2002:aa7:981c:0:b0:625:e3c0:8a58 with SMTP id e28-20020aa7981c000000b00625e3c08a58mr331925pfl.4.1679593381172; Thu, 23 Mar 2023 10:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679593381; cv=none; d=google.com; s=arc-20160816; b=tVYJnKPsuaVLs1navQ7EfCqfXglRs5efnqsaa+WSWDp+OJr53qeXXaKhrpGWcMCGL1 TI0f8Y6xx2yKlV8jHZAaODuIlQ3rPGI8KZ6x3YfvHbsQjSEaVjRHMJiNDNg4I9dB9X63 sXmwvulnbWO1JSSsCVqloPqc1uUjSt/vEgZzoZPjvndxcRZV6oafh3KgASkJi8pUNOY4 eRNMVtFt5HKt1nGhdP7W1OZSqMlqqIFfsSPq6xtI2cJDre5AAbFsK3C0KSGJZFvsEfGR ItLnS3AWhKJkKuEMdZwFapMFuNiNbH3CIhpxghVSnmWWVkxuNX5r9jRUMnBlek+9juml 8K6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ONmJsFn4VtTyqhV76hclBRWNA9ptPEzWzjO41FRshbk=; b=jrUL9k5ZkqmL0T56tZtcrqzeQM0MyxJrBYiZQvSVGApojjl0tBSKDtxaE/5+D9Uk5U zi5zdynowMvwvtnaRy7XVxBLylA32HQGBD5wjBlXSRo1QSrI8jHOZFJkK6rLZHNKFRwE c2a1fyg7s+cvQ0z64Z3hYjEy3aNzbwwr2GSummaQmmkNZBapEKPD3Lg8KKS+iuJVbLtL 5ihy0Bk+Bwwcj2kuJqqR8zQqWsqe2SSP74BJ7u/zPELb+8Z0bf4ape+ybCu/0EisGu8W 2eF3K8zFMi1Y0g/qYIM1jY9zON3M47Esye43IVkV/ykSCfdKWqVdxAD4WVPEmI3uwwix Dcfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZOOMx6qR; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h66-20020a628345000000b005a90e791de8si17403897pfe.296.2023.03.23.10.42.44; Thu, 23 Mar 2023 10:43:01 -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=@linaro.org header.s=google header.b=ZOOMx6qR; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbjCWRlG (ORCPT + 99 others); Thu, 23 Mar 2023 13:41:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjCWRkm (ORCPT ); Thu, 23 Mar 2023 13:40:42 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA0B9AF29 for ; Thu, 23 Mar 2023 10:40:33 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id b20so57201274edd.1 for ; Thu, 23 Mar 2023 10:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679593232; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ONmJsFn4VtTyqhV76hclBRWNA9ptPEzWzjO41FRshbk=; b=ZOOMx6qRt3g7nOII6cvvW0hyxEjWWWvDyB98rJc12tcsH6noQhIsqu5xLxTof0r+F6 Fk6ByrMV8UwbwL7tUhXCMW1/tQSupmgreeis3cnrbTucwxJBVGbIiXo47uHi1RmFtad0 NfcBboj+c0EQ0W89ocXkpz6EoGXfx8QSla2bJ2Yp79BR1UJTy1y9u77coZDKkC/wVe/o Iz1oE7G00uYZTSzJM9ApeuHNhP8WjV+yLj3GpTAYs4gp1Is9P5SwwM8n1y5WJVPzVR7l r1tuvwipZ6u/wfdNztLFTIOVgRjlAmxDsrgCPJjuKVfrWG4i2K3jtA8FZ3Ll3veAvA9K ZkkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679593232; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ONmJsFn4VtTyqhV76hclBRWNA9ptPEzWzjO41FRshbk=; b=JR/GIW2x/7BTP5EsndpxLcGRWHjrHcWyuUEQFVfkJIt6jjlFcJCibtCwA0pwl9B8KT /eFKhnw/cwUEojrapac0XpmCXNAQT4x2ig4mtGkwYYUJyBgJ/pMp2rmoZ0t+v5QML5VO GzSJ8uRx5dNvxoRwnG5UsAjvRSFOAhGLgqS7ydRDMVXeyd3QVA+Z5CSF3QJj5JmMJ23+ z0rDeglcUheJcKiyRRSg8EVnQWyx9yN83Myca3nE3jQhJ+GvopKqRJcKl8U/Df5SPpCS 3x6bkfsqkrvW2Rn4RLxW2eDBvcR1qYrCPdyVBhjzjBKJgbdkdPAL0ZR//FsMy9Lqec6/ saYw== X-Gm-Message-State: AO0yUKW2Ol8Qcs6IXNf+S2q6rXGHU3WBhfnAtYUr8xVy5ceiRlDm2eri oLc1RxNkziYsV2+0Aq0PUQqzoA== X-Received: by 2002:a17:906:378d:b0:930:7ae6:9ebd with SMTP id n13-20020a170906378d00b009307ae69ebdmr11866028ejc.70.1679593232231; Thu, 23 Mar 2023 10:40:32 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:d350:23b1:cb94:f39d]) by smtp.gmail.com with ESMTPSA id e5-20020a170906314500b009236ae669ecsm8890787eje.191.2023.03.23.10.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 10:40:31 -0700 (PDT) From: Krzysztof Kozlowski To: Andy Gross , Bjorn Andersson , 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 Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH] cpufreq: qcom-cpufreq-hw: fix double IO unmap and resource release on exit Date: Thu, 23 Mar 2023 18:40:26 +0100 Message-Id: <20230323174026.950622-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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 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 --- 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