Re: [PATCH 4/9] platform/x86: asus-wmi: reduce code duplication with macros

From: Ilpo Järvinen
Date: Tue May 28 2024 - 05:03:52 EST


On Tue, 28 May 2024, Luke D. Jones wrote:

> Over time many default patterns have emerged while adding functionality.
> This patch consolidates those patterns in to a few macros to remove a lot
> of copy/paste, and make it easier to add more of the same style of
> features in the future.
>
> Signed-off-by: Luke D. Jones <luke@xxxxxxxxxx>
> ---

> +#define WMI_SIMPLE_SHOW(_fname, _fmt, _wmi) \
> +static ssize_t _fname##_show(struct device *dev, \
> + struct device_attribute *attr, char *buf) \
> +{ \
> + struct asus_wmi *asus = dev_get_drvdata(dev); \
> + u32 result; \
> + asus_wmi_get_devstate(asus, _wmi, &result); \
> + if (result < 0) \
> + return result; \
> + return sysfs_emit(buf, _fmt, result & ~ASUS_WMI_DSTS_PRESENCE_BIT); \
> +}

One more thing. To improve readability further, add also normal newlines
into macros like this (obviously with the continuation backslashes far
right as already mentioned).

--
i.