Re: [GIT PULL 20/22] intel_th: msu: Add a sysfs attribute showing possible modes

From: Greg Kroah-Hartman
Date: Fri May 03 2019 - 12:13:44 EST


On Fri, May 03, 2019 at 11:44:53AM +0300, Alexander Shishkin wrote:
> With the addition of dynamically loadable buffer drivers, there needs
> to be a way of knowing the currently available ones without having to
> scan the list of loaded modules or trial and error.
>
> Add a sysfs file that lists all the currently available "modes", listing
> both the MSC hardware operating modes and loaded buffer drivers.

sysfs files are to be only "one value per file". This violates that
rule by a lot.

> +static ssize_t
> +modes_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct msu_buffer *mbuf;
> + ssize_t ret = 0;
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(msc_mode); i++)
> + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
> + msc_mode[i]);

If you ever have to have a loop in a sysfs show function, you know you
are in trouble. And here you have two of them. Please do not do this.

thanks,

greg k-h