Skip to content

Commit 0980bb1

Browse files
committed
ALSA: aoa: Replace sprintf() with sysfs_emit()
For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces such sprintf() calls with sysfs_emit() while simplifying the open code in modalias_show(); as modalias[] is a NUL-terminated string, we can pass it straightly to a printf() argument. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 7450320 commit 0980bb1

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

sound/aoa/soundbus/sysfs.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
1010
{
1111
struct soundbus_dev *sdev = to_soundbus_device(dev);
1212
struct platform_device *of = &sdev->ofdev;
13-
int length;
1413

15-
if (*sdev->modalias) {
16-
strscpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1);
17-
strcat(buf, "\n");
18-
length = strlen(buf);
19-
} else {
20-
length = sprintf(buf, "of:N%pOFn%c%s\n",
21-
of->dev.of_node, 'T',
22-
of_node_get_device_type(of->dev.of_node));
23-
}
24-
25-
return length;
14+
if (*sdev->modalias)
15+
return sysfs_emit(buf, "%s\n", sdev->modalias);
16+
else
17+
return sysfs_emit(buf, "of:N%pOFn%c%s\n",
18+
of->dev.of_node, 'T',
19+
of_node_get_device_type(of->dev.of_node));
2620
}
2721
static DEVICE_ATTR_RO(modalias);
2822

@@ -32,7 +26,7 @@ static ssize_t name_show(struct device *dev,
3226
struct soundbus_dev *sdev = to_soundbus_device(dev);
3327
struct platform_device *of = &sdev->ofdev;
3428

35-
return sprintf(buf, "%pOFn\n", of->dev.of_node);
29+
return sysfs_emit(buf, "%pOFn\n", of->dev.of_node);
3630
}
3731
static DEVICE_ATTR_RO(name);
3832

@@ -42,7 +36,7 @@ static ssize_t type_show(struct device *dev,
4236
struct soundbus_dev *sdev = to_soundbus_device(dev);
4337
struct platform_device *of = &sdev->ofdev;
4438

45-
return sprintf(buf, "%s\n", of_node_get_device_type(of->dev.of_node));
39+
return sysfs_emit(buf, "%s\n", of_node_get_device_type(of->dev.of_node));
4640
}
4741
static DEVICE_ATTR_RO(type);
4842

0 commit comments

Comments
 (0)