Re: [PATCH v6 12/13] platform/x86: lenovo-wmi-helpers: Add helper for creating per-device debugfs dir
From: Rong Zhang
Date: Wed Apr 01 2026 - 14:42:06 EST
Hi Derek,
On Tue, 2026-03-31 at 18:12 +0000, Derek J. Clark wrote:
> From: Rong Zhang <i@xxxxxxxx>
>
> We are about to add debugfs support for lenovo-wmi-capdata. Let's setup
> a debugfs directory called "lenovo_wmi" for tidiness, so that any
> lenovo-wmi-* device can put its subdirectory under the directory.
> Subdirectories will be named after the corresponding WMI devices.
>
> Signed-off-by: Rong Zhang <i@xxxxxxxx>
> Signed-off-by: Derek J. Clark <derekjohn.clark@xxxxxxxxx>
> ---
> drivers/platform/x86/lenovo/wmi-helpers.c | 34 +++++++++++++++++++++++
> drivers/platform/x86/lenovo/wmi-helpers.h | 2 ++
> 2 files changed, 36 insertions(+)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
> index e1cf869224d2..52a0c6a5a4bf 100644
> --- a/drivers/platform/x86/lenovo/wmi-helpers.c
> +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
> @@ -17,6 +17,8 @@
> */
>
> #include <linux/acpi.h>
> +#include <linux/debugfs.h>
> +#include <linux/device.h>
> #include <linux/cleanup.h>
> #include <linux/errno.h>
> #include <linux/export.h>
> @@ -185,6 +187,38 @@ int lwmi_tm_notifier_call(enum thermal_mode *mode)
> }
> EXPORT_SYMBOL_NS_GPL(lwmi_tm_notifier_call, "LENOVO_WMI_HELPERS");
>
> +static struct dentry *lwmi_debugfs_dir;
> +
> +/**
> + * lwmi_debugfs_create_dir() - Helper function for creating a debugfs directory
> + * for a device.
> + * @wdev: Pointer to the WMI device to be called.
> + *
> + * Caller must remove the directory with debugfs_remove_recursive() on device
> + * removal.
> + *
> + * Return: Pointer to the created directory.
> + */
> +struct dentry *lwmi_debugfs_create_dir(struct wmi_device *wdev)
> +{
> + return debugfs_create_dir(dev_name(&wdev->dev), lwmi_debugfs_dir);
> +}
> +EXPORT_SYMBOL_NS_GPL(lwmi_debugfs_create_dir, "LENOVO_WMI_HELPERS");
> +
> +static int __init lwmi_helpers_init(void)
> +{
> + lwmi_debugfs_dir = debugfs_create_dir("lenovo_wmi", NULL);
> +
> + return 0;
> +}
> +module_init(lwmi_helpers_init)
I missed it before. This should be `subsys_initcall(lwmi_helpers_init)'
so that it can be initialized first if both wmi-helpers and wmi-capdata
are built into the kernel statically (i.e., =y).
Found by sashiko.dev.
https://sashiko.dev/#/patchset/20260331181208.421552-1-derekjohn.clark%40gmail.com
module_exit(lwmi_helpers_exit) has no effect when built into the kernel
so that's fine.
Thanks,
Rong
> +
> +static void __exit lwmi_helpers_exit(void)
> +{
> + debugfs_remove_recursive(lwmi_debugfs_dir);
> +}
> +module_exit(lwmi_helpers_exit)
> +
> MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@xxxxxxxxx>");
> MODULE_DESCRIPTION("Lenovo WMI Helpers Driver");
> MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x86/lenovo/wmi-helpers.h
> index ed7db3ebba6c..039fe61003ce 100644
> --- a/drivers/platform/x86/lenovo/wmi-helpers.h
> +++ b/drivers/platform/x86/lenovo/wmi-helpers.h
> @@ -16,6 +16,8 @@ struct wmi_method_args_32 {
> u32 arg1;
> };
>
> +struct dentry *lwmi_debugfs_create_dir(struct wmi_device *wdev);
> +
> enum lwmi_event_type {
> LWMI_GZ_GET_THERMAL_MODE = 0x01,
> };