From patchwork Thu Oct 12 23:09:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10003211 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 DA5FB6028A for ; Thu, 12 Oct 2017 23:10:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8D1D28CEE for ; Thu, 12 Oct 2017 23:10:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDCD728DCD; Thu, 12 Oct 2017 23:10:15 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68D7728CEE for ; Thu, 12 Oct 2017 23:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753283AbdJLXKB (ORCPT ); Thu, 12 Oct 2017 19:10:01 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:56763 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752065AbdJLXKA (ORCPT ); Thu, 12 Oct 2017 19:10:00 -0400 Received: by mail-pf0-f194.google.com with SMTP id b85so7053097pfj.13; Thu, 12 Oct 2017 16:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=YkFJZ/1vFpoLoV/xrh7mH5KFMjGArv6Cc/NfYpS0/Q0=; b=L1MgqVxbZ/9t0AfRuQ/ppw7lqFPIAJ++C5atPT4Z4X2PRBJ7bkdLGUuumbFax1sccc tUD7/OsFARKpP8c+G2N18w6WTLnkiSWV7eOU2hgC4PK9r1jdJiiIxU6VWGfEgczhUBDJ ivxUmjZcq2j3vkqNCf+9ufJB3c8BkuOXer3dnsCWb7b+aoG653Sx1a0BejUU7evPLzwJ gIfEYNbPQajvqsk4t0W7xFEFnLxus8bQMtKpzsFaCY2jd4ji9yxRG3eVh0ojsjmNk7Jj Cbii3nsGZe56NaHPfuoOS7+Wv6tE5AS+NXpVdyUyD/hYtAnXcZ73LVJnIWviGmhS4urM yCIQ== 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=YkFJZ/1vFpoLoV/xrh7mH5KFMjGArv6Cc/NfYpS0/Q0=; b=MRFVnJ9i2QLSA1jDNmK+4NVdiNqQb/AL1pUzw++srFpCM3fKGGccZXo11G8V3NaVwH eMfECurJ4SRmO100TO1+kmdcRiTEOVgan8i9CLRW3us173pq7RjXg0Q0frofYnXjdBYR RvDMZQnKYaMgUREEi1a/HzybLJAKN0nVvQCDnQkdzFaWGwC6TRErtdztU5qZJq8w51aO QBcOmwBFD9J3QHcZCjMpalL+ddQTno8M4az3+ycVsMqA+MHMIKIxFn74gqlgVa5bkdXm 20MttPPRnBxgm6QEdVi1xTK7HiUji2tzIcmZMZs4Dj97S4I9EJfoFfSPhe45UMYDs4A8 Gzeg== X-Gm-Message-State: AMCzsaUG9J3wDdzJlldt5nu5YiKOWeye0Xd0WZfOfhBPZpt/Bd9P4ynC 6uw3SkVACYbnVPflv3I+s1o= X-Google-Smtp-Source: AOwi7QBro9x101ELElyYiR0cHeJvTncQ0ct8NYSQs5n+LmxHYhUYfHFXvl98gFWA3CWP5J+1KtpwiQ== X-Received: by 10.84.198.164 with SMTP id p33mr1416806pld.89.1507849799838; Thu, 12 Oct 2017 16:09:59 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id k126sm34638352pfc.45.2017.10.12.16.09.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 16:09:59 -0700 (PDT) From: Nicolin Chen To: pdeschrijver@nvidia.com Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org, jonathanh@nvidia.com, thierry.reding@gmail.com, sboyd@codeaurora.org, mturquette@baylibre.com, pgaikwad@nvidia.com Subject: [PATCH] clk: tegra: dfll: Fix drvdata overwriting issue Date: Thu, 12 Oct 2017 16:09:59 -0700 Message-Id: <1507849799-4256-1-git-send-email-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.1.4 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Both tegra124-dfll and clk-dfll are using platform_set_drvdata to set drvdata of the exact same pdev while they use different pointers for the drvdata. Once the drvdata has been overwritten by tegra124-dfll, clk-dfll will never get its td pointer as it expects. Since tegra124-dfll merely needs its soc pointer in its remove function, this patch fixes the bug by removing the overwriting in the tegra124-dfll file and letting the tegra_dfll_unregister return an soc pointer for it. Signed-off-by: Nicolin Chen Acked-By: Peter De Schrijver --- As I don't have a T124 platform, I can't verify it on a board. If someone could provide a Tested-by, it would be very helpful. The test could be a simple system suspend/resume that activates runtime_suspend/resume() where a platform_get_drvdata() would be called. -- Nicolin drivers/clk/tegra/clk-dfll.c | 10 +++++----- drivers/clk/tegra/clk-dfll.h | 2 +- drivers/clk/tegra/clk-tegra124-dfll-fcpu.c | 12 +++++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/clk/tegra/clk-dfll.c b/drivers/clk/tegra/clk-dfll.c index 2c44aeb..0a7deee 100644 --- a/drivers/clk/tegra/clk-dfll.c +++ b/drivers/clk/tegra/clk-dfll.c @@ -1728,10 +1728,10 @@ EXPORT_SYMBOL(tegra_dfll_register); * @pdev: DFLL platform_device * * * Unbind this driver from the DFLL hardware device represented by - * @pdev. The DFLL must be disabled for this to succeed. Returns 0 - * upon success or -EBUSY if the DFLL is still active. + * @pdev. The DFLL must be disabled for this to succeed. Returns a + * soc pointer upon success or -EBUSY if the DFLL is still active. */ -int tegra_dfll_unregister(struct platform_device *pdev) +struct tegra_dfll_soc_data *tegra_dfll_unregister(struct platform_device *pdev) { struct tegra_dfll *td = platform_get_drvdata(pdev); @@ -1739,7 +1739,7 @@ int tegra_dfll_unregister(struct platform_device *pdev) if (td->mode != DFLL_DISABLED) { dev_err(&pdev->dev, "must disable DFLL before removing driver\n"); - return -EBUSY; + return ERR_PTR(-EBUSY); } debugfs_remove_recursive(td->debugfs_dir); @@ -1753,6 +1753,6 @@ int tegra_dfll_unregister(struct platform_device *pdev) reset_control_assert(td->dvco_rst); - return 0; + return td->soc; } EXPORT_SYMBOL(tegra_dfll_unregister); diff --git a/drivers/clk/tegra/clk-dfll.h b/drivers/clk/tegra/clk-dfll.h index ed2ad88..83352c8 100644 --- a/drivers/clk/tegra/clk-dfll.h +++ b/drivers/clk/tegra/clk-dfll.h @@ -43,7 +43,7 @@ struct tegra_dfll_soc_data { int tegra_dfll_register(struct platform_device *pdev, struct tegra_dfll_soc_data *soc); -int tegra_dfll_unregister(struct platform_device *pdev); +struct tegra_dfll_soc_data *tegra_dfll_unregister(struct platform_device *pdev); int tegra_dfll_runtime_suspend(struct device *dev); int tegra_dfll_runtime_resume(struct device *dev); diff --git a/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c b/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c index ad1c1cc..269d359 100644 --- a/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c +++ b/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c @@ -125,19 +125,17 @@ static int tegra124_dfll_fcpu_probe(struct platform_device *pdev) return err; } - platform_set_drvdata(pdev, soc); - return 0; } static int tegra124_dfll_fcpu_remove(struct platform_device *pdev) { - struct tegra_dfll_soc_data *soc = platform_get_drvdata(pdev); - int err; + struct tegra_dfll_soc_data *soc; - err = tegra_dfll_unregister(pdev); - if (err < 0) - dev_err(&pdev->dev, "failed to unregister DFLL: %d\n", err); + soc = tegra_dfll_unregister(pdev); + if (IS_ERR(soc)) + dev_err(&pdev->dev, "failed to unregister DFLL: %ld\n", + PTR_ERR(soc)); tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq);