Commit 973c3911 authored by Joe Perches's avatar Joe Perches Committed by Greg Kroah-Hartman

drivers core: Remove strcat uses around sysfs_emit and neaten

strcat is no longer necessary for sysfs_emit and sysfs_emit_at uses.

Convert the strcat uses to sysfs_emit calls and neaten other block
uses of direct returns to use an intermediate const char *.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Link: https://lore.kernel.org/r/5d606519698ce4c8f1203a2b35797d8254c6050a.1600285923.git.joe@perches.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent aa838896
...@@ -404,17 +404,23 @@ static ssize_t type_show(struct device *dev, ...@@ -404,17 +404,23 @@ static ssize_t type_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct cacheinfo *this_leaf = dev_get_drvdata(dev); struct cacheinfo *this_leaf = dev_get_drvdata(dev);
const char *output;
switch (this_leaf->type) { switch (this_leaf->type) {
case CACHE_TYPE_DATA: case CACHE_TYPE_DATA:
return sysfs_emit(buf, "Data\n"); output = "Data";
break;
case CACHE_TYPE_INST: case CACHE_TYPE_INST:
return sysfs_emit(buf, "Instruction\n"); output = "Instruction";
break;
case CACHE_TYPE_UNIFIED: case CACHE_TYPE_UNIFIED:
return sysfs_emit(buf, "Unified\n"); output = "Unified";
break;
default: default:
return -EINVAL; return -EINVAL;
} }
return sysfs_emit(buf, "%s\n", output);
} }
static ssize_t allocation_policy_show(struct device *dev, static ssize_t allocation_policy_show(struct device *dev,
...@@ -422,15 +428,18 @@ static ssize_t allocation_policy_show(struct device *dev, ...@@ -422,15 +428,18 @@ static ssize_t allocation_policy_show(struct device *dev,
{ {
struct cacheinfo *this_leaf = dev_get_drvdata(dev); struct cacheinfo *this_leaf = dev_get_drvdata(dev);
unsigned int ci_attr = this_leaf->attributes; unsigned int ci_attr = this_leaf->attributes;
int n = 0; const char *output;
if ((ci_attr & CACHE_READ_ALLOCATE) && (ci_attr & CACHE_WRITE_ALLOCATE)) if ((ci_attr & CACHE_READ_ALLOCATE) && (ci_attr & CACHE_WRITE_ALLOCATE))
n = sysfs_emit(buf, "ReadWriteAllocate\n"); output = "ReadWriteAllocate";
else if (ci_attr & CACHE_READ_ALLOCATE) else if (ci_attr & CACHE_READ_ALLOCATE)
n = sysfs_emit(buf, "ReadAllocate\n"); output = "ReadAllocate";
else if (ci_attr & CACHE_WRITE_ALLOCATE) else if (ci_attr & CACHE_WRITE_ALLOCATE)
n = sysfs_emit(buf, "WriteAllocate\n"); output = "WriteAllocate";
return n; else
return 0;
return sysfs_emit(buf, "%s\n", output);
} }
static ssize_t write_policy_show(struct device *dev, static ssize_t write_policy_show(struct device *dev,
......
...@@ -268,16 +268,16 @@ static ssize_t auto_remove_on_show(struct device *dev, ...@@ -268,16 +268,16 @@ static ssize_t auto_remove_on_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct device_link *link = to_devlink(dev); struct device_link *link = to_devlink(dev);
char *str; const char *output;
if (link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER) if (link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
str = "supplier unbind"; output = "supplier unbind";
else if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) else if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER)
str = "consumer unbind"; output = "consumer unbind";
else else
str = "never"; output = "never";
return sysfs_emit(buf, "%s\n", str); return sysfs_emit(buf, "%s\n", output);
} }
static DEVICE_ATTR_RO(auto_remove_on); static DEVICE_ATTR_RO(auto_remove_on);
......
...@@ -139,7 +139,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, ...@@ -139,7 +139,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct memory_block *mem = to_memory_block(dev); struct memory_block *mem = to_memory_block(dev);
ssize_t len = 0; const char *output;
/* /*
* We can probably put these states in a nice little array * We can probably put these states in a nice little array
...@@ -147,22 +147,20 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, ...@@ -147,22 +147,20 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
*/ */
switch (mem->state) { switch (mem->state) {
case MEM_ONLINE: case MEM_ONLINE:
len = sysfs_emit(buf, "online\n"); output = "online";
break; break;
case MEM_OFFLINE: case MEM_OFFLINE:
len = sysfs_emit(buf, "offline\n"); output = "offline";
break; break;
case MEM_GOING_OFFLINE: case MEM_GOING_OFFLINE:
len = sysfs_emit(buf, "going-offline\n"); output = "going-offline";
break; break;
default: default:
len = sysfs_emit(buf, "ERROR-UNKNOWN-%ld\n",
mem->state);
WARN_ON(1); WARN_ON(1);
break; return sysfs_emit(buf, "ERROR-UNKNOWN-%ld\n", mem->state);
} }
return len; return sysfs_emit(buf, "%s\n", output);
} }
int memory_notify(unsigned long val, void *v) int memory_notify(unsigned long val, void *v)
...@@ -307,17 +305,16 @@ static ssize_t phys_device_show(struct device *dev, ...@@ -307,17 +305,16 @@ static ssize_t phys_device_show(struct device *dev,
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
static void print_allowed_zone(char *buf, int nid, unsigned long start_pfn, static int print_allowed_zone(char *buf, int len, int nid,
unsigned long nr_pages, int online_type, unsigned long start_pfn, unsigned long nr_pages,
struct zone *default_zone) int online_type, struct zone *default_zone)
{ {
struct zone *zone; struct zone *zone;
zone = zone_for_pfn_range(online_type, nid, start_pfn, nr_pages); zone = zone_for_pfn_range(online_type, nid, start_pfn, nr_pages);
if (zone != default_zone) { if (zone == default_zone)
strcat(buf, " "); return 0;
strcat(buf, zone->name); return sysfs_emit_at(buf, len, " %s", zone->name);
}
} }
static ssize_t valid_zones_show(struct device *dev, static ssize_t valid_zones_show(struct device *dev,
...@@ -327,6 +324,7 @@ static ssize_t valid_zones_show(struct device *dev, ...@@ -327,6 +324,7 @@ static ssize_t valid_zones_show(struct device *dev,
unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr);
unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
struct zone *default_zone; struct zone *default_zone;
int len = 0;
int nid; int nid;
/* /*
...@@ -341,24 +339,23 @@ static ssize_t valid_zones_show(struct device *dev, ...@@ -341,24 +339,23 @@ static ssize_t valid_zones_show(struct device *dev,
default_zone = test_pages_in_a_zone(start_pfn, default_zone = test_pages_in_a_zone(start_pfn,
start_pfn + nr_pages); start_pfn + nr_pages);
if (!default_zone) if (!default_zone)
return sysfs_emit(buf, "none\n"); return sysfs_emit(buf, "%s\n", "none");
strcat(buf, default_zone->name); len += sysfs_emit_at(buf, len, "%s", default_zone->name);
goto out; goto out;
} }
nid = mem->nid; nid = mem->nid;
default_zone = zone_for_pfn_range(MMOP_ONLINE, nid, start_pfn, default_zone = zone_for_pfn_range(MMOP_ONLINE, nid, start_pfn,
nr_pages); nr_pages);
strcat(buf, default_zone->name);
print_allowed_zone(buf, nid, start_pfn, nr_pages, MMOP_ONLINE_KERNEL, len += sysfs_emit_at(buf, len, "%s", default_zone->name);
default_zone); len += print_allowed_zone(buf, len, nid, start_pfn, nr_pages,
print_allowed_zone(buf, nid, start_pfn, nr_pages, MMOP_ONLINE_MOVABLE, MMOP_ONLINE_KERNEL, default_zone);
default_zone); len += print_allowed_zone(buf, len, nid, start_pfn, nr_pages,
MMOP_ONLINE_MOVABLE, default_zone);
out: out:
strcat(buf, "\n"); len += sysfs_emit_at(buf, len, "%s", "\n");
return len;
return strlen(buf);
} }
static DEVICE_ATTR_RO(valid_zones); static DEVICE_ATTR_RO(valid_zones);
#endif #endif
......
...@@ -255,9 +255,9 @@ static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev, ...@@ -255,9 +255,9 @@ static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev,
s32 value = dev_pm_qos_get_user_latency_tolerance(dev); s32 value = dev_pm_qos_get_user_latency_tolerance(dev);
if (value < 0) if (value < 0)
return sysfs_emit(buf, "auto\n"); return sysfs_emit(buf, "%s\n", "auto");
if (value == PM_QOS_LATENCY_ANY) if (value == PM_QOS_LATENCY_ANY)
return sysfs_emit(buf, "any\n"); return sysfs_emit(buf, "%s\n", "any");
return sysfs_emit(buf, "%d\n", value); return sysfs_emit(buf, "%d\n", value);
} }
...@@ -538,13 +538,18 @@ static DEVICE_ATTR_RO(runtime_active_kids); ...@@ -538,13 +538,18 @@ static DEVICE_ATTR_RO(runtime_active_kids);
static ssize_t runtime_enabled_show(struct device *dev, static ssize_t runtime_enabled_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
if (dev->power.disable_depth && (dev->power.runtime_auto == false)) const char *output;
return sysfs_emit(buf, "disabled & forbidden\n");
if (dev->power.disable_depth) if (dev->power.disable_depth && !dev->power.runtime_auto)
return sysfs_emit(buf, "disabled\n"); output = "disabled & forbidden";
if (dev->power.runtime_auto == false) else if (dev->power.disable_depth)
return sysfs_emit(buf, "forbidden\n"); output = "disabled";
return sysfs_emit(buf, "enabled\n"); else if (!dev->power.runtime_auto)
output = "forbidden";
else
output = "enabled";
return sysfs_emit(buf, "%s\n", output);
} }
static DEVICE_ATTR_RO(runtime_enabled); static DEVICE_ATTR_RO(runtime_enabled);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment