All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Echo Zhang" <echo.zhang@mediatek.com>,
	devicetree@vger.kernel.org, linux-clk@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 3/7] soc: mediatek: add MMDVFS core driver
Date: Wed, 25 Nov 2026 06:18:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-232656@kernel.org> (raw)
In-Reply-To: <20261125060037.649659-4-echo.zhang@mediatek.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] soc: mediatek: mmdvfs: dependency on undefined Kconfig symbol
  MTK_VCP_RPROC
- [High] soc: mediatek: mmdvfs: premature MT8196 symbol references cause
  link failure
- [Medium] soc: mediatek: mmdvfs: UAF and teardown order bug in
  mmdvfs_remove()
- [Medium] soc: mediatek: mmdvfs: clocks remain active during
  deinit_hw() teardown
- [Low] soc: mediatek: mmdvfs: duplicate enum and declarations across
  headers
--

commit 5b3edaa4a79dffb92cf9cae0a066c56967485e24
Author: Echo Zhang <echo.zhang@mediatek.com>

soc: mediatek: add MMDVFS core driver

This commit adds the common MediaTek MMDVFS driver framework, including
device probing, SoC topology validation, clock provider registration,
power-management notification, and exported consumer helpers.

> diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
> index d7293977f06e8..bb273a4461f0a 100644
> --- a/drivers/soc/mediatek/Kconfig
> +++ b/drivers/soc/mediatek/Kconfig
> @@ -60,6 +60,25 @@ config MTK_REGULATOR_COUPLER
>  	default ARCH_MEDIATEK
>  	depends on REGULATOR
>  
> +config MTK_MMDVFS
> +	tristate "MediaTek MMDVFS support"
> +	depends on ARCH_MEDIATEK || COMPILE_TEST
> +	depends on MTK_VCP_RPROC

[Severity: High]
Is MTK_VCP_RPROC defined anywhere in the Kconfig tree?  Because that symbol
does not exist, CONFIG_MTK_MMDVFS and CONFIG_MTK_MMDVFS_MT8196 can never be
enabled, and the IS_ENABLED(CONFIG_MTK_VCP_RPROC) guard in
include/soc/mediatek/mmdvfs.h always selects the no-op inline stubs instead
of the public declarations.

> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
> new file mode 100644
> index 0000000000000..114f3148cf461
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
[ ... ]
> +/*
> + * mmdvfs_unregister_clocks - Unregister clock providers
> + * @mmdvfs: MMDVFS device structure
> + */
> +void mmdvfs_unregister_clocks(struct mmdvfs_device *mmdvfs)
> +{
> +	if (mmdvfs && mmdvfs->dev)
> +		mmdvfs_dbg(mmdvfs->dev, "MMDVFS clocks unregistered\n");
> +}

[Severity: Medium]
Can clock consumers still call mmdvfs_set_rate() -> data->ops->hw_vote()
while or after data->ops->deinit_hw() tears down the hardware?

mmdvfs_register_clocks() registers the clocks and OF provider with
devm_clk_hw_register() and devm_of_clk_add_hw_provider(), while
mmdvfs_unregister_clocks() only logs a debug message and leaves
data->init_done set to true.  When mmdvfs_remove() or the
err_unregister_clocks path in mmdvfs_probe() calls
mmdvfs_unregister_clocks() followed by data->ops->deinit_hw(), the devres-
managed clock provider remains active until mmdvfs_remove() or
mmdvfs_probe() returns.

> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
> new file mode 100644
> index 0000000000000..c32fa11557aff
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
[ ... ]
> +/* Platform data definitions for device match table */
> +#if IS_ENABLED(CONFIG_MTK_MMDVFS_MT8196)
> +static const struct mmdvfs_platform_data mmdvfs_mt8196_pdata = {
> +	.soc_data = &mmdvfs_mt8196_soc_data,
> +	.ops = &mmdvfs_mt8196_ops,
> +};
> +#endif

[Severity: High]
Does enabling CONFIG_MTK_MMDVFS_MT8196 at this commit fail to link due to
undefined references to mmdvfs_mt8196_soc_data and mmdvfs_mt8196_ops?

drivers/soc/mediatek/Kconfig already exposes CONFIG_MTK_MMDVFS_MT8196 here,
but drivers/soc/mediatek/mmdvfs/Makefile only links mmdvfs-core.o and
mmdvfs-clk.o until commit "soc: mediatek: mmdvfs: add MT8196 support" adds
mmdvfs-mt8196.c, breaking bisectability when CONFIG_MTK_MMDVFS_MT8196 is
selected.

[ ... ]

> +struct mmdvfs_device *mmdvfs_find_device_by_version(enum mmdvfs_version_type version)
> +{
> +	struct mmdvfs_device_node *node;
> +	struct mmdvfs_device *found = NULL;
> +
> +	mutex_lock(&mmdvfs_device_list_lock);
> +	list_for_each_entry(node, &mmdvfs_device_list, list) {
> +		if (node->mmdvfs && node->mmdvfs->data &&
> +		    node->mmdvfs->data->version == version) {
> +			found = node->mmdvfs;
> +			break;
> +		}
> +	}
> +	mutex_unlock(&mmdvfs_device_list_lock);
> +
> +	return found;
> +}
> +EXPORT_SYMBOL_GPL(mmdvfs_find_device_by_version);
[ ... ]
> +int mtk_mmdvfs_camera_notify(bool enable)
> +{
> +	struct mmdvfs_device *mmdvfs;
> +
> +	mmdvfs = mmdvfs_find_device_any();
> +	if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
> +	    !mmdvfs->data->ops->camera_notify)
> +		return -EOPNOTSUPP;
> +
> +	return mmdvfs->data->ops->camera_notify(mmdvfs, enable);
> +}
> +EXPORT_SYMBOL_GPL(mtk_mmdvfs_camera_notify);

[Severity: Medium]
Can concurrent callers of mtk_mmdvfs_camera_notify() and the other exported
helpers race with mmdvfs_remove() and hit a use-after-free?

CPU0                                    CPU1
mtk_mmdvfs_camera_notify()
  mmdvfs = mmdvfs_find_device_any()
    lock(&mmdvfs_device_list_lock)
    found = node->mmdvfs
    unlock(&mmdvfs_device_list_lock)
                                        mmdvfs_remove()
                                          data->ops->deinit_hw(mmdvfs)
                                          mmdvfs_unregister_device(mmdvfs)
                                        devres_release_all()
                                          /* frees mmdvfs and mmdvfs->data */
  mmdvfs->data->ops->camera_notify(...) <-- use-after-free

mmdvfs_find_device_by_version() drops mmdvfs_device_list_lock and returns a
raw pointer to devm-allocated memory without taking a reference or holding a
lock across the callback.  In addition, mmdvfs_remove() runs
data->ops->deinit_hw(mmdvfs) before mmdvfs_unregister_device(mmdvfs) unlinks
the device from mmdvfs_device_list, and mmdvfs_probe() has no teardown
callback for state allocated by data->ops->probe() if
mmdvfs_validate_topology() or data->ops->init_hw() fails.

> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
> new file mode 100644
> index 0000000000000..df16e38d78c89
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
> @@ -0,0 +1,305 @@
[ ... ]
> +/* MMDVFS voting mechanism types */
> +enum mmdvfs_version_type {
> +	MMDVFS_VERSION_NONE = 0,		/* No hardware voter */
> +	MMDVFS_VERSION_HWCCF_DVFS_VOTER = 1,	/* HWCCF DVFS voter */
> +};
[ ... ]
> +/* Platform-specific operations */
> +u32 mmdvfs_get_version(void);
> +int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx);
> +int mtk_mmdvfs_camera_notify(bool enable);
> +int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable);
> +int mtk_mmdvfs_genpd_notify(u8 idx, bool enable);
> +int mtk_mmdvfs_set_avs(u8 idx, u32 aging, u32 fresh);
> +int mmdvfs_set_lp_mode(bool enable);

[Severity: Low]
Should mmdvfs-internal.h include <soc/mediatek/mmdvfs.h> instead of
redefining enum mmdvfs_version_type and redeclaring these public API
functions?  Any file that includes both headers will fail to compile due to
the duplicate enum definition.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125060037.649659-1-echo.zhang@mediatek.com?part=3

  reply	other threads:[~2026-11-25  6:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
2026-11-25  6:00 ` [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs Echo Zhang
2026-11-25  6:13   ` sashiko-bot
2026-11-25 10:55   ` Krzysztof Kozlowski
2026-11-25  6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
2026-11-25  6:12   ` sashiko-bot
2026-11-25  8:32   ` Roman Vivchar
2026-11-25 10:58   ` Krzysztof Kozlowski
2026-11-25 11:58   ` Krzysztof Kozlowski
2026-11-27  3:05   ` CK Hu (胡俊光)
2026-11-25  6:00 ` [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang
2026-11-25  6:18   ` sashiko-bot [this message]
2026-11-25  8:35   ` Roman Vivchar
2026-11-25 10:54   ` Krzysztof Kozlowski
2026-11-25  6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
2026-11-25  6:21   ` sashiko-bot
2026-11-25  8:38   ` Roman Vivchar
2026-11-25 10:59   ` Krzysztof Kozlowski
2026-11-25 11:00   ` Krzysztof Kozlowski
2026-11-25 14:32   ` Ben Grisdale
2026-11-27  2:58     ` Echo Zhang (张玉)
2026-11-25  6:00 ` [PATCH 5/7] soc: mediatek: mmdvfs: add MT8196 support Echo Zhang
2026-11-25  6:15   ` sashiko-bot
2026-11-25  6:00 ` [PATCH 6/7] soc: mediatek: mmdvfs: add read-only status debug Echo Zhang
2026-11-25  6:00 ` [PATCH 7/7] MAINTAINERS: add MediaTek MMDVFS entry Echo Zhang
  -- strict thread matches above, loose matches on Subject: below --
2026-11-26  9:14 [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang (张玉)

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=sashiko-outbox-232656@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=echo.zhang@mediatek.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.