Re: [PATCH 4/5] mfd: cros_ec: Add a helper to retrieve the EC device from the MFD parent

From: Lee Jones

Date: Fri Apr 24 2026 - 03:58:46 EST


On Sat, 04 Apr 2026, Thomas Weißschuh wrote:

> The 'struct cros_ec_dev' needs to be retrieved from the MFD parent
> device through a non-typesafe API. This logic is duplicated over all
> CrOS EC drivers and it is not obvious what is going on.

I don't agree with this at all.

dev_get_drvdata(pdev->dev.parent) is way more transparent than what is
being offered by cros_ec_mfd_get_ec_dev(pdev).

The aforementioned call clearly states that it's fetching the parent's
driver data. This is better.

> Add a dedicated helper function which makes clear what is happening.
>
> Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
> ---
> include/linux/mfd/cros_ec.h | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
> new file mode 100644
> index 000000000000..ea5b007accfc
> --- /dev/null
> +++ b/include/linux/mfd/cros_ec.h
> @@ -0,0 +1,16 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef __LINUX_MFD_CROS_EC_H
> +#define __LINUX_MFD_CROS_EC_H
> +
> +#include <linux/compiler_attributes.h>
> +
> +struct cros_ec_dev;
> +struct platform_device;
> +
> +static __always_inline struct cros_ec_dev *cros_ec_mfd_get_ec_dev(struct platform_device *pdev)
> +{
> + return dev_get_drvdata(pdev->dev.parent);
> +}
> +
> +#endif /* __LINUX_MFD_CROS_EC_H */
>
> --
> 2.53.0
>

--
Lee Jones