From: Choi Chanwoo <cwchoi00@gmail.com>
To: Bean Huo <beanhuo@iokpp.de>,
linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
MyungJoo Ham <myungjoo.ham@samsung.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
"Martin K . Petersen" <mkp@kernel.org>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
Avri Altman <avri.altman@sandisk.com>,
Bart Van Assche <bvanassche@acm.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Stanley Jhu <stanleyjhu@google.com>,
Bean Huo <beanhuo@micron.com>
Subject: Re: [PATCH v2 1/4] PM / devfreq: Fall back to previous_freq when get_cur_freq() fails
Date: Sun, 15 Nov 2026 09:25:12 +0900 [thread overview]
Message-ID: <a813b1ea-6971-4fde-b310-659a03963fba@gmail.com> (raw)
In-Reply-To: <20260907192140.2701755-2-beanhuo@iokpp.de>
On 9/8/2026 4:21 AM, Bean Huo wrote:
> From: Bean Huo <beanhuo@micron.com>
>
> devfreq_set_target() calls the optional ->get_cur_freq() callback to get
> the frequency that is passed as freqs.old to the DEVFREQ_PRECHANGE and
> DEVFREQ_POSTCHANGE notifiers, but it does not check the return value. If
> the callback fails without setting @freq, cur_freq is never assigned, and
> an uninitialized stack value is passed to the notifiers.
>
> hisi_uncore_get_cur_freq() can hit this. It returns -ENODEV without
> setting @freq when its PCC channel is missing. On the mailbox error path
> it sets @freq to 0 instead, so that the core does not read a random
> value.
>
> The other two callers, cur_freq_show() and devfreq_monitor_resume(),
> already check the return value and use devfreq->previous_freq when the
> callback fails. Do the same in devfreq_set_target().
>
> This does not seem to cause a visible problem today. The passive governor
> is the only DEVFREQ_TRANSITION_NOTIFIER user in the tree, and it only
> reads freqs.new. So this patch is not marked for stable.
>
> Fixes: 0fe3a66410a3 ("PM / devfreq: Add new DEVFREQ_TRANSITION_NOTIFIER notifier")
> Signed-off-by: Bean Huo <beanhuo@micron.com>
> Reviewed-by: Avri Altman <avri.altman@sandisk.com>
> ---
> drivers/devfreq/devfreq.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index f08fc6966eae..f20d9a660779 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -348,9 +348,8 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
> unsigned long cur_freq;
> int err = 0;
>
> - if (devfreq->profile->get_cur_freq)
> - devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
> - else
> + if (!devfreq->profile->get_cur_freq ||
> + devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq))
> cur_freq = devfreq->previous_freq;
>
> freqs.old = cur_freq;
I agree this patch.
But, I don't recommend to execute to function on if statement.
In order to improve the readability, could you please update it as following:
unsigned long cur_freq = devfreq->previous_freq;
unsigned long freq;
...
if (devfreq->profile->get_cur_freq) {
err = devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq);
if (!err)
cur_freq = freq;
}
--
Best Regards,
Chanwoo Choi
Principal Engineer, Samsung Electronics
next prev parent reply other threads:[~2026-11-15 0:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 19:21 [PATCH v2 0/4] devfreq: check the get_cur_freq() return value and use it in ufshcd Bean Huo
2026-09-07 19:21 ` [PATCH v2 1/4] PM / devfreq: Fall back to previous_freq when get_cur_freq() fails Bean Huo
2026-09-14 6:24 ` Jie Zhan
2026-11-15 0:25 ` Choi Chanwoo [this message]
2026-09-07 19:21 ` [PATCH v2 2/4] PM / devfreq: Add more details to the get_cur_freq() comment Bean Huo
2026-09-14 6:25 ` Jie Zhan
2026-11-15 0:27 ` Choi Chanwoo
2026-09-07 19:21 ` [PATCH v2 3/4] scsi: ufs: core: Record the frequency the controller starts at Bean Huo
2026-09-07 19:21 ` [PATCH v2 4/4] scsi: ufs: core: Report the current clock frequency to devfreq Bean Huo
2026-09-08 1:34 ` [PATCH v2 0/4] devfreq: check the get_cur_freq() return value and use it in ufshcd Stanley Jhu
2026-09-10 2:28 ` Martin K. Petersen (Oracle)
2026-09-14 13:12 ` Bean Huo
2026-10-06 11:07 ` Bean Huo
2026-09-17 2:28 ` Martin K. Petersen (Oracle)
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=a813b1ea-6971-4fde-b310-659a03963fba@gmail.com \
--to=cwchoi00@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=beanhuo@iokpp.de \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=chanwoo@kernel.org \
--cc=cw00.choi@samsung.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=stanleyjhu@google.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
all inboxes | Powered by JetHome®