Skip to content

Commit 973c391

Browse files
JoePerchesgregkh
authored andcommitted
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: Joe Perches <[email protected]> Link: https://lore.kernel.org/r/5d606519698ce4c8f1203a2b35797d8254c6050a.1600285923.git.joe@perches.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent aa83889 commit 973c391

File tree

4 files changed

+58
-47
lines changed

4 files changed

+58
-47
lines changed

drivers/base/cacheinfo.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,33 +404,42 @@ static ssize_t type_show(struct device *dev,
404404
struct device_attribute *attr, char *buf)
405405
{
406406
struct cacheinfo *this_leaf = dev_get_drvdata(dev);
407+
const char *output;
407408

408409
switch (this_leaf->type) {
409410
case CACHE_TYPE_DATA:
410-
return sysfs_emit(buf, "Data\n");
411+
output = "Data";
412+
break;
411413
case CACHE_TYPE_INST:
412-
return sysfs_emit(buf, "Instruction\n");
414+
output = "Instruction";
415+
break;
413416
case CACHE_TYPE_UNIFIED:
414-
return sysfs_emit(buf, "Unified\n");
417+
output = "Unified";
418+
break;
415419
default:
416420
return -EINVAL;
417421
}
422+
423+
return sysfs_emit(buf, "%s\n", output);
418424
}
419425

420426
static ssize_t allocation_policy_show(struct device *dev,
421427
struct device_attribute *attr, char *buf)
422428
{
423429
struct cacheinfo *this_leaf = dev_get_drvdata(dev);
424430
unsigned int ci_attr = this_leaf->attributes;
425-
int n = 0;
431+
const char *output;
426432

427433
if ((ci_attr & CACHE_READ_ALLOCATE) && (ci_attr & CACHE_WRITE_ALLOCATE))
428-
n = sysfs_emit(buf, "ReadWriteAllocate\n");
434+
output = "ReadWriteAllocate";
429435
else if (ci_attr & CACHE_READ_ALLOCATE)
430-
n = sysfs_emit(buf, "ReadAllocate\n");
436+
output = "ReadAllocate";
431437
else if (ci_attr & CACHE_WRITE_ALLOCATE)
432-
n = sysfs_emit(buf, "WriteAllocate\n");
433-
return n;
438+
output = "WriteAllocate";
439+
else
440+
return 0;
441+
442+
return sysfs_emit(buf, "%s\n", output);
434443
}
435444

436445
static ssize_t write_policy_show(struct device *dev,

drivers/base/core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,16 @@ static ssize_t auto_remove_on_show(struct device *dev,
268268
struct device_attribute *attr, char *buf)
269269
{
270270
struct device_link *link = to_devlink(dev);
271-
char *str;
271+
const char *output;
272272

273273
if (link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
274-
str = "supplier unbind";
274+
output = "supplier unbind";
275275
else if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER)
276-
str = "consumer unbind";
276+
output = "consumer unbind";
277277
else
278-
str = "never";
278+
output = "never";
279279

280-
return sysfs_emit(buf, "%s\n", str);
280+
return sysfs_emit(buf, "%s\n", output);
281281
}
282282
static DEVICE_ATTR_RO(auto_remove_on);
283283

drivers/base/memory.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,30 +139,28 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
139139
char *buf)
140140
{
141141
struct memory_block *mem = to_memory_block(dev);
142-
ssize_t len = 0;
142+
const char *output;
143143

144144
/*
145145
* We can probably put these states in a nice little array
146146
* so that they're not open-coded
147147
*/
148148
switch (mem->state) {
149149
case MEM_ONLINE:
150-
len = sysfs_emit(buf, "online\n");
150+
output = "online";
151151
break;
152152
case MEM_OFFLINE:
153-
len = sysfs_emit(buf, "offline\n");
153+
output = "offline";
154154
break;
155155
case MEM_GOING_OFFLINE:
156-
len = sysfs_emit(buf, "going-offline\n");
156+
output = "going-offline";
157157
break;
158158
default:
159-
len = sysfs_emit(buf, "ERROR-UNKNOWN-%ld\n",
160-
mem->state);
161159
WARN_ON(1);
162-
break;
160+
return sysfs_emit(buf, "ERROR-UNKNOWN-%ld\n", mem->state);
163161
}
164162

165-
return len;
163+
return sysfs_emit(buf, "%s\n", output);
166164
}
167165

168166
int memory_notify(unsigned long val, void *v)
@@ -307,17 +305,16 @@ static ssize_t phys_device_show(struct device *dev,
307305
}
308306

309307
#ifdef CONFIG_MEMORY_HOTREMOVE
310-
static void print_allowed_zone(char *buf, int nid, unsigned long start_pfn,
311-
unsigned long nr_pages, int online_type,
312-
struct zone *default_zone)
308+
static int print_allowed_zone(char *buf, int len, int nid,
309+
unsigned long start_pfn, unsigned long nr_pages,
310+
int online_type, struct zone *default_zone)
313311
{
314312
struct zone *zone;
315313

316314
zone = zone_for_pfn_range(online_type, nid, start_pfn, nr_pages);
317-
if (zone != default_zone) {
318-
strcat(buf, " ");
319-
strcat(buf, zone->name);
320-
}
315+
if (zone == default_zone)
316+
return 0;
317+
return sysfs_emit_at(buf, len, " %s", zone->name);
321318
}
322319

323320
static ssize_t valid_zones_show(struct device *dev,
@@ -327,6 +324,7 @@ static ssize_t valid_zones_show(struct device *dev,
327324
unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr);
328325
unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
329326
struct zone *default_zone;
327+
int len = 0;
330328
int nid;
331329

332330
/*
@@ -341,24 +339,23 @@ static ssize_t valid_zones_show(struct device *dev,
341339
default_zone = test_pages_in_a_zone(start_pfn,
342340
start_pfn + nr_pages);
343341
if (!default_zone)
344-
return sysfs_emit(buf, "none\n");
345-
strcat(buf, default_zone->name);
342+
return sysfs_emit(buf, "%s\n", "none");
343+
len += sysfs_emit_at(buf, len, "%s", default_zone->name);
346344
goto out;
347345
}
348346

349347
nid = mem->nid;
350348
default_zone = zone_for_pfn_range(MMOP_ONLINE, nid, start_pfn,
351349
nr_pages);
352-
strcat(buf, default_zone->name);
353350

354-
print_allowed_zone(buf, nid, start_pfn, nr_pages, MMOP_ONLINE_KERNEL,
355-
default_zone);
356-
print_allowed_zone(buf, nid, start_pfn, nr_pages, MMOP_ONLINE_MOVABLE,
357-
default_zone);
351+
len += sysfs_emit_at(buf, len, "%s", default_zone->name);
352+
len += print_allowed_zone(buf, len, nid, start_pfn, nr_pages,
353+
MMOP_ONLINE_KERNEL, default_zone);
354+
len += print_allowed_zone(buf, len, nid, start_pfn, nr_pages,
355+
MMOP_ONLINE_MOVABLE, default_zone);
358356
out:
359-
strcat(buf, "\n");
360-
361-
return strlen(buf);
357+
len += sysfs_emit_at(buf, len, "%s", "\n");
358+
return len;
362359
}
363360
static DEVICE_ATTR_RO(valid_zones);
364361
#endif

drivers/base/power/sysfs.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev,
255255
s32 value = dev_pm_qos_get_user_latency_tolerance(dev);
256256

257257
if (value < 0)
258-
return sysfs_emit(buf, "auto\n");
258+
return sysfs_emit(buf, "%s\n", "auto");
259259
if (value == PM_QOS_LATENCY_ANY)
260-
return sysfs_emit(buf, "any\n");
260+
return sysfs_emit(buf, "%s\n", "any");
261261

262262
return sysfs_emit(buf, "%d\n", value);
263263
}
@@ -538,13 +538,18 @@ static DEVICE_ATTR_RO(runtime_active_kids);
538538
static ssize_t runtime_enabled_show(struct device *dev,
539539
struct device_attribute *attr, char *buf)
540540
{
541-
if (dev->power.disable_depth && (dev->power.runtime_auto == false))
542-
return sysfs_emit(buf, "disabled & forbidden\n");
543-
if (dev->power.disable_depth)
544-
return sysfs_emit(buf, "disabled\n");
545-
if (dev->power.runtime_auto == false)
546-
return sysfs_emit(buf, "forbidden\n");
547-
return sysfs_emit(buf, "enabled\n");
541+
const char *output;
542+
543+
if (dev->power.disable_depth && !dev->power.runtime_auto)
544+
output = "disabled & forbidden";
545+
else if (dev->power.disable_depth)
546+
output = "disabled";
547+
else if (!dev->power.runtime_auto)
548+
output = "forbidden";
549+
else
550+
output = "enabled";
551+
552+
return sysfs_emit(buf, "%s\n", output);
548553
}
549554
static DEVICE_ATTR_RO(runtime_enabled);
550555

0 commit comments

Comments
 (0)