Skip to content

Commit ad8f1c8

Browse files
kwilczynskikelvin-cao
authored andcommitted
PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related commit: ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions"). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Logan Gunthorpe <[email protected]>
1 parent eb0603b commit ad8f1c8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

switchtec.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static ssize_t device_version_show(struct device *dev,
328328

329329
ver = ioread32(&stdev->mmio_sys_info->device_version);
330330

331-
return sprintf(buf, "%x\n", ver);
331+
return sysfs_emit(buf, "%x\n", ver);
332332
}
333333
static DEVICE_ATTR_RO(device_version);
334334

@@ -340,7 +340,7 @@ static ssize_t fw_version_show(struct device *dev,
340340

341341
ver = ioread32(&stdev->mmio_sys_info->firmware_version);
342342

343-
return sprintf(buf, "%08x\n", ver);
343+
return sysfs_emit(buf, "%08x\n", ver);
344344
}
345345
static DEVICE_ATTR_RO(fw_version);
346346

@@ -392,7 +392,7 @@ static ssize_t component_vendor_show(struct device *dev,
392392

393393
/* component_vendor field not supported after gen3 */
394394
if (stdev->gen != SWITCHTEC_GEN3)
395-
return sprintf(buf, "none\n");
395+
return sysfs_emit(buf, "none\n");
396396

397397
return io_string_show(buf, &si->gen3.component_vendor,
398398
sizeof(si->gen3.component_vendor));
@@ -407,9 +407,9 @@ static ssize_t component_id_show(struct device *dev,
407407

408408
/* component_id field not supported after gen3 */
409409
if (stdev->gen != SWITCHTEC_GEN3)
410-
return sprintf(buf, "none\n");
410+
return sysfs_emit(buf, "none\n");
411411

412-
return sprintf(buf, "PM%04X\n", id);
412+
return sysfs_emit(buf, "PM%04X\n", id);
413413
}
414414
static DEVICE_ATTR_RO(component_id);
415415

@@ -421,9 +421,9 @@ static ssize_t component_revision_show(struct device *dev,
421421

422422
/* component_revision field not supported after gen3 */
423423
if (stdev->gen != SWITCHTEC_GEN3)
424-
return sprintf(buf, "255\n");
424+
return sysfs_emit(buf, "255\n");
425425

426-
return sprintf(buf, "%d\n", rev);
426+
return sysfs_emit(buf, "%d\n", rev);
427427
}
428428
static DEVICE_ATTR_RO(component_revision);
429429

@@ -432,7 +432,7 @@ static ssize_t partition_show(struct device *dev,
432432
{
433433
struct switchtec_dev *stdev = to_stdev(dev);
434434

435-
return sprintf(buf, "%d\n", stdev->partition);
435+
return sysfs_emit(buf, "%d\n", stdev->partition);
436436
}
437437
static DEVICE_ATTR_RO(partition);
438438

@@ -441,7 +441,7 @@ static ssize_t partition_count_show(struct device *dev,
441441
{
442442
struct switchtec_dev *stdev = to_stdev(dev);
443443

444-
return sprintf(buf, "%d\n", stdev->partition_count);
444+
return sysfs_emit(buf, "%d\n", stdev->partition_count);
445445
}
446446
static DEVICE_ATTR_RO(partition_count);
447447

0 commit comments

Comments
 (0)