From: Marc Zyngier <maz@kernel.org>
To: Jerome Brunet <jbrunet@baylibre.com>
Cc: Neil Armstrong <narmstrong@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Kevin Hilman <khilman@baylibre.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
Guillaume Tucker <guillaume.tucker@collabora.com>,
linux-amlogic@lists.infradead.org, kernel-team@android.com,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/2] drm/meson: dw-hdmi: Disable clocks on driver teardown
Date: Mon, 23 Nov 2020 14:15:45 +0000 [thread overview]
Message-ID: <763f505eececa3b02bd794aec5e36d22@kernel.org> (raw)
In-Reply-To: <1jwnyc41c6.fsf@starbuckisacylon.baylibre.com>
On 2020-11-23 14:03, Jerome Brunet wrote:
> On Fri 20 Nov 2020 at 10:42, Marc Zyngier <maz@kernel.org> wrote:
>
>> The HDMI driver request clocks early, but never disable them, leaving
>> the clocks on even when the driver is removed.
>>
>> Fix it by slightly refactoring the clock code, and register a devm
>> action that will eventually disable/unprepare the enabled clocks.
>>
>> Signed-off-by: Marc Zyngier <maz@kernel.org>
>> ---
>> drivers/gpu/drm/meson/meson_dw_hdmi.c | 43
>> ++++++++++++++++++---------
>> 1 file changed, 29 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c
>> b/drivers/gpu/drm/meson/meson_dw_hdmi.c
>> index 7f8eea494147..29623b309cb1 100644
>> --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c
>> +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c
>> @@ -145,8 +145,6 @@ struct meson_dw_hdmi {
>> struct reset_control *hdmitx_apb;
>> struct reset_control *hdmitx_ctrl;
>> struct reset_control *hdmitx_phy;
>> - struct clk *hdmi_pclk;
>> - struct clk *venci_clk;
>> struct regulator *hdmi_supply;
>> u32 irq_stat;
>> struct dw_hdmi *hdmi;
>> @@ -946,6 +944,29 @@ static void meson_disable_regulator(void *data)
>> regulator_disable(data);
>> }
>>
>> +static void meson_disable_clk(void *data)
>> +{
>> + clk_disable_unprepare(data);
>> +}
>> +
>> +static int meson_enable_clk(struct device *dev, char *name)
>> +{
>> + struct clk *clk;
>> + int ret;
>> +
>> + clk = devm_clk_get(dev, name);
>> + if (IS_ERR(clk)) {
>> + dev_err(dev, "Unable to get %s pclk\n", name);
>> + return PTR_ERR(clk);
>> + }
>> +
>> + ret = clk_prepare_enable(clk);
>> + if (!ret)
>> + ret = devm_add_action_or_reset(dev, meson_disable_clk,
>> clk);
>
> Thanks for fixing this Marc.
>
> FYI, while it is fine to declare a function to disable the clocks, a
> quick
> cast may avoid it
>
> devm_add_action_or_reset(dev, (void(*)(void *))clk_disable_unprepare,
> clk);
While this works for now, a change to the clk_disable_unprepare()
prototype (such as adding a second argument) would now go completely
unnoticed (after all, you've cast the function, it *must* be correct,
right?), and someone would spend a few hours trying to track down memory
corruption or some other interesting results.
Yes, casting C functions can be hilarious.
I can see a few uses of this hack in the tree, and I have my pop-corn
ready.
Thanks,
M.
--
Jazz is not dead. It just smells funny...
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-11-23 14:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 9:42 [PATCH 0/2] More meson HDMI fixes Marc Zyngier
2020-11-20 9:42 ` [PATCH 1/2] drm/meson: dw-hdmi: Disable clocks on driver teardown Marc Zyngier
2020-11-20 12:26 ` Neil Armstrong
2020-11-23 14:03 ` Jerome Brunet
2020-11-23 14:15 ` Marc Zyngier [this message]
2020-11-20 9:42 ` [PATCH 2/2] drm/meson: dw-hdmi: Enable the iahb clock early enough Marc Zyngier
2020-11-20 10:54 ` Guillaume Tucker
2020-11-20 11:10 ` Marc Zyngier
2020-11-20 12:18 ` Neil Armstrong
2020-11-20 12:27 ` Neil Armstrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=763f505eececa3b02bd794aec5e36d22@kernel.org \
--to=maz@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=guillaume.tucker@collabora.com \
--cc=jbrunet@baylibre.com \
--cc=kernel-team@android.com \
--cc=khilman@baylibre.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=narmstrong@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).