Commit 948b3edb authored by Joe Perches's avatar Joe Perches Committed by Greg Kroah-Hartman
Browse files

drivers core: Miscellaneous changes for sysfs_emit



Change additional instances that could use sysfs_emit and sysfs_emit_at
that the coccinelle script could not convert.

o macros creating show functions with ## concatenation
o unbound sprintf uses with buf+len for start of output to sysfs_emit_at
o returns with ?: tests and sprintf to sysfs_emit
o sysfs output with struct class * not struct device * arguments

Miscellanea:

o remove unnecessary initializations around these changes
o consistently use int len for return length of show functions
o use octal permissions and not S_<FOO>
o rename a few show function names so DEVICE_ATTR_<FOO> can be used
o use DEVICE_ATTR_ADMIN_RO where appropriate
o consistently use const char *output for strings
o checkpatch/style neatening

Signed-off-by: default avatarJoe Perches <joe@perches.com>
Link: https://lore.kernel.org/r/8bc24444fe2049a9b2de6127389b57edfdfe324d.1600285923.git.joe@perches.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 27275d30
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ static DRIVER_ATTR_IGNORE_LOCKDEP(bind, S_IWUSR, NULL, bind_store);

static ssize_t drivers_autoprobe_show(struct bus_type *bus, char *buf)
{
	return sprintf(buf, "%d\n", bus->p->drivers_autoprobe);
	return sysfs_emit(buf, "%d\n", bus->p->drivers_autoprobe);
}

static ssize_t drivers_autoprobe_store(struct bus_type *bus,
+1 −1
Original line number Diff line number Diff line
@@ -362,7 +362,7 @@ static ssize_t file_name##_show(struct device *dev, \
		struct device_attribute *attr, char *buf)	\
{								\
	struct cacheinfo *this_leaf = dev_get_drvdata(dev);	\
	return sprintf(buf, "%u\n", this_leaf->object);		\
	return sysfs_emit(buf, "%u\n", this_leaf->object);	\
}

show_one(id, id);
+1 −1
Original line number Diff line number Diff line
@@ -478,7 +478,7 @@ ssize_t show_class_attr_string(struct class *class,
	struct class_attribute_string *cs;

	cs = container_of(attr, struct class_attribute_string, attr);
	return snprintf(buf, PAGE_SIZE, "%s\n", cs->str);
	return sysfs_emit(buf, "%s\n", cs->str);
}

EXPORT_SYMBOL_GPL(show_class_attr_string);
+21 −13
Original line number Diff line number Diff line
@@ -242,25 +242,33 @@ void device_pm_move_to_tail(struct device *dev)
static ssize_t status_show(struct device *dev,
			   struct device_attribute *attr, char *buf)
{
	char *status;
	const char *output;

	switch (to_devlink(dev)->status) {
	case DL_STATE_NONE:
		status = "not tracked"; break;
		output = "not tracked";
		break;
	case DL_STATE_DORMANT:
		status = "dormant"; break;
		output = "dormant";
		break;
	case DL_STATE_AVAILABLE:
		status = "available"; break;
		output = "available";
		break;
	case DL_STATE_CONSUMER_PROBE:
		status = "consumer probing"; break;
		output = "consumer probing";
		break;
	case DL_STATE_ACTIVE:
		status = "active"; break;
		output = "active";
		break;
	case DL_STATE_SUPPLIER_UNBIND:
		status = "supplier unbinding"; break;
		output = "supplier unbinding";
		break;
	default:
		status = "unknown"; break;
		output = "unknown";
		break;
	}
	return sysfs_emit(buf, "%s\n", status);

	return sysfs_emit(buf, "%s\n", output);
}
static DEVICE_ATTR_RO(status);

@@ -1934,7 +1942,7 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
	struct kset *kset;
	struct kobj_uevent_env *env = NULL;
	int i;
	size_t count = 0;
	int len = 0;
	int retval;

	/* search the kset, the device belongs to */
@@ -1964,10 +1972,10 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,

	/* copy keys to file */
	for (i = 0; i < env->envp_idx; i++)
		count += sprintf(&buf[count], "%s\n", env->envp[i]);
		len += sysfs_emit_at(buf, len, "%s\n", env->envp[i]);
out:
	kfree(env);
	return count;
	return len;
}

static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
+30 −32
Original line number Diff line number Diff line
@@ -139,11 +139,11 @@ EXPORT_SYMBOL_GPL(cpu_subsys);
#ifdef CONFIG_KEXEC
#include <linux/kexec.h>

static ssize_t show_crash_notes(struct device *dev, struct device_attribute *attr,
static ssize_t crash_notes_show(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct cpu *cpu = container_of(dev, struct cpu, dev);
	ssize_t rc;
	unsigned long long addr;
	int cpunum;

@@ -156,21 +156,18 @@ static ssize_t show_crash_notes(struct device *dev, struct device_attribute *att
	 * operation should be safe. No locking required.
	 */
	addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpunum));
	rc = sysfs_emit(buf, "%Lx\n", addr);
	return rc;

	return sysfs_emit(buf, "%llx\n", addr);
}
static DEVICE_ATTR(crash_notes, 0400, show_crash_notes, NULL);
static DEVICE_ATTR_ADMIN_RO(crash_notes);

static ssize_t show_crash_notes_size(struct device *dev,
static ssize_t crash_notes_size_show(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{
	ssize_t rc;

	rc = sysfs_emit(buf, "%zu\n", sizeof(note_buf_t));
	return rc;
	return sysfs_emit(buf, "%zu\n", sizeof(note_buf_t));
}
static DEVICE_ATTR(crash_notes_size, 0400, show_crash_notes_size, NULL);
static DEVICE_ATTR_ADMIN_RO(crash_notes_size);

static struct attribute *crash_note_cpu_attrs[] = {
	&dev_attr_crash_notes.attr,
@@ -241,37 +238,37 @@ unsigned int total_cpus;
static ssize_t print_cpus_offline(struct device *dev,
				  struct device_attribute *attr, char *buf)
{
	int n = 0, len = PAGE_SIZE-2;
	int len = 0;
	cpumask_var_t offline;

	/* display offline cpus < nr_cpu_ids */
	if (!alloc_cpumask_var(&offline, GFP_KERNEL))
		return -ENOMEM;
	cpumask_andnot(offline, cpu_possible_mask, cpu_online_mask);
	n = scnprintf(buf, len, "%*pbl", cpumask_pr_args(offline));
	len += sysfs_emit_at(buf, len, "%*pbl", cpumask_pr_args(offline));
	free_cpumask_var(offline);

	/* display offline cpus >= nr_cpu_ids */
	if (total_cpus && nr_cpu_ids < total_cpus) {
		if (n && n < len)
			buf[n++] = ',';
		len += sysfs_emit_at(buf, len, ",");

		if (nr_cpu_ids == total_cpus-1)
			n += scnprintf(&buf[n], len - n, "%u", nr_cpu_ids);
			len += sysfs_emit_at(buf, len, "%u", nr_cpu_ids);
		else
			n += scnprintf(&buf[n], len - n, "%u-%d",
			len += sysfs_emit_at(buf, len, "%u-%d",
					     nr_cpu_ids, total_cpus - 1);
	}

	n += scnprintf(&buf[n], len - n, "\n");
	return n;
	len += sysfs_emit_at(buf, len, "\n");

	return len;
}
static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL);

static ssize_t print_cpus_isolated(struct device *dev,
				  struct device_attribute *attr, char *buf)
{
	int n;
	int len;
	cpumask_var_t isolated;

	if (!alloc_cpumask_var(&isolated, GFP_KERNEL))
@@ -279,11 +276,11 @@ static ssize_t print_cpus_isolated(struct device *dev,

	cpumask_andnot(isolated, cpu_possible_mask,
		       housekeeping_cpumask(HK_FLAG_DOMAIN));
	n = sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(isolated));
	len = sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(isolated));

	free_cpumask_var(isolated);

	return n;
	return len;
}
static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);

@@ -320,22 +317,23 @@ static ssize_t print_cpu_modalias(struct device *dev,
				  struct device_attribute *attr,
				  char *buf)
{
	ssize_t n;
	int len = 0;
	u32 i;

	n = sysfs_emit(buf, "cpu:type:" CPU_FEATURE_TYPEFMT ":feature:",
	len += sysfs_emit_at(buf, len,
			     "cpu:type:" CPU_FEATURE_TYPEFMT ":feature:",
			     CPU_FEATURE_TYPEVAL);

	for (i = 0; i < MAX_CPU_FEATURES; i++)
		if (cpu_have_feature(i)) {
			if (PAGE_SIZE < n + sizeof(",XXXX\n")) {
			if (len + sizeof(",XXXX\n") >= PAGE_SIZE) {
				WARN(1, "CPU features overflow page\n");
				break;
			}
			n += sprintf(&buf[n], ",%04X", i);
			len += sysfs_emit_at(buf, len, ",%04X", i);
		}
	buf[n++] = '\n';
	return n;
	len += sysfs_emit_at(buf, len, "\n");
	return len;
}

static int cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
Loading