Re: [PATCH v3 1/6] platform/x86: lenovo-wmi-other: Add LWMI_ATTR_ID Macro

Ilpo Järvinen
2026-02-24T08:43:23Z

On Tue, 24 Feb 2026, Derek J. Clark wrote:

> Adds LWMI_ATTR_ID macro. In the same vein as LWMI_ATTR_ID_FAN_RPM,

Add () after any function (or like).

> but as a generic, to de-duplicate attribute_id assignment biolerplate.
>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> drivers/platform/x86/lenovo/wmi-capdata.h | 6 ++++
> drivers/platform/x86/lenovo/wmi-gamezone.h | 1 +
> drivers/platform/x86/lenovo/wmi-other.c | 36 ++++++----------------
> 3 files changed, 17 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-capdata.h b/drivers/platform/x86/lenovo/wmi-capdata.h
> index 8c1df3efcc55..27202e2dc8a5 100644
> --- a/drivers/platform/x86/lenovo/wmi-capdata.h
> +++ b/drivers/platform/x86/lenovo/wmi-capdata.h
> @@ -17,6 +17,12 @@
> #define LWMI_ATTR_MODE_ID_MASK GENMASK(15, 8)
> #define LWMI_ATTR_TYPE_ID_MASK GENMASK(7, 0)
>
> +#define LWMI_ATTR_ID(dev, feat, mode, type) \
> + (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, dev) | \
> + FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, feat) | \
> + FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) | \
> + FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, type))
> +
> #define LWMI_DEVICE_ID_FAN 0x04
>
> struct component_match;
> diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.h b/drivers/platform/x86/lenovo/wmi-gamezone.h
> index 6b163a5eeb95..ddb919cf6c36 100644
> --- a/drivers/platform/x86/lenovo/wmi-gamezone.h
> +++ b/drivers/platform/x86/lenovo/wmi-gamezone.h
> @@ -10,6 +10,7 @@ enum gamezone_events_type {
> };
>
> enum thermal_mode {
> + LWMI_GZ_THERMAL_MODE_NONE = 0x00,
> LWMI_GZ_THERMAL_MODE_QUIET = 0x01,
> LWMI_GZ_THERMAL_MODE_BALANCED = 0x02,
> LWMI_GZ_THERMAL_MODE_PERFORMANCE = 0x03,
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> index 6040f45aa2b0..95886df39c8d 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -71,10 +71,9 @@
> #define LWMI_FAN_NR 4
> #define LWMI_FAN_ID(x) ((x) + LWMI_FAN_ID_BASE)
>
> -#define LWMI_ATTR_ID_FAN_RPM(x) \
> - (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, LWMI_DEVICE_ID_FAN) | \
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, LWMI_FEATURE_ID_FAN_RPM) | \
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, LWMI_FAN_ID(x)))
> +#define LWMI_ATTR_ID_FAN_RPM(x) \
> + LWMI_ATTR_ID(LWMI_DEVICE_ID_FAN, LWMI_FEATURE_ID_FAN_RPM, \
> + LWMI_GZ_THERMAL_MODE_NONE, LWMI_FAN_ID(x))
>
> #define LWMI_FAN_DIV 100
>
> @@ -716,12 +715,8 @@ static ssize_t attr_capdata01_show(struct kobject *kobj,
> u32 attribute_id;
> int value, ret;
>
> - attribute_id =
> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK,
> - LWMI_GZ_THERMAL_MODE_CUSTOM) |
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
> + attribute_id = LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature_id,
> + LWMI_GZ_THERMAL_MODE_CUSTOM, tunable_attr->type_id);
>
> ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
> if (ret)
> @@ -776,7 +771,6 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> struct wmi_method_args_32 args;
> struct capdata01 capdata;
> enum thermal_mode mode;
> - u32 attribute_id;
> u32 value;
> int ret;
>
> @@ -787,13 +781,10 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> if (mode != LWMI_GZ_THERMAL_MODE_CUSTOM)
> return -EBUSY;
>
> - attribute_id =
> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
> + args.arg0 = LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature_id,
> + mode, tunable_attr->type_id);
>
> - ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
> + ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
> if (ret)
> return ret;
>
> @@ -804,7 +795,6 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> if (value < capdata.min_value || value > capdata.max_value)
> return -EINVAL;
>
> - args.arg0 = attribute_id;
> args.arg1 = value;
>
> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET,
> @@ -838,7 +828,6 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
> struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> struct wmi_method_args_32 args;
> enum thermal_mode mode;
> - u32 attribute_id;
> int retval;
> int ret;
>
> @@ -846,13 +835,8 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
> if (ret)
> return ret;
>
> - attribute_id =
> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
> -
> - args.arg0 = attribute_id;
> + args.arg0 = LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature_id,
> + mode, tunable_attr->type_id);
>
> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
> (unsigned char *)&args, sizeof(args),
>

--
i.