From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Zihuan Zhang <zhangzihuan@kylinos.cn>
Cc: "Rafael J . wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
zhenglifeng <zhenglifeng1@huawei.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] cpufreq: Add defensive checks during driver registration
Date: Fri, 19 Sep 2025 23:13:03 +0200 [thread overview]
Message-ID: <CAJZ5v0hgku5V-3GNVH2w8GT2JzkHOU2NZkfHdrRDT-Hb80tuuQ@mail.gmail.com> (raw)
In-Reply-To: <20250908085738.31602-1-zhangzihuan@kylinos.cn>
On Mon, Sep 8, 2025 at 10:57 AM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> Currently, cpufreq allows drivers to implement both has_target() and
> has_target_index(), which can lead to ambiguous or incorrect behavior.
>
> This patch adds defensive checks in the driver registration path to
> prevent invalid implementations. For example, a driver is no longer
> allowed to implement both has_target() and has_target_index() at the
> same time. These checks help catch driver mistakes early and improve
> overall robustness, without affecting existing valid drivers.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> drivers/cpufreq/cpufreq.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index a615c98d80ca..cead6d4fa1ad 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2922,6 +2922,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
> return -EPROBE_DEFER;
>
> if (!driver_data || !driver_data->verify || !driver_data->init ||
> + (driver_data->target_index && driver_data->target) ||
> (!!driver_data->setpolicy == (driver_data->target_index || driver_data->target)) ||
> (!driver_data->get_intermediate != !driver_data->target_intermediate) ||
> (!driver_data->online != !driver_data->offline) ||
> --
Applied as 6.18 material with edits in the subject and changelog, thanks!
prev parent reply other threads:[~2025-09-19 21:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 8:57 Zihuan Zhang
2025-09-19 21:13 ` Rafael J. Wysocki [this message]
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=CAJZ5v0hgku5V-3GNVH2w8GT2JzkHOU2NZkfHdrRDT-Hb80tuuQ@mail.gmail.com \
--to=rafael@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=zhangzihuan@kylinos.cn \
--cc=zhenglifeng1@huawei.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®