Skip to content

Commit

Permalink
ALSA: aoa: Replace sprintf() with sysfs_emit()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tiwai committed Aug 2, 2022
1 parent 7450320 commit 0980bb1
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions sound/aoa/soundbus/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
{
struct soundbus_dev *sdev = to_soundbus_device(dev);
struct platform_device *of = &sdev->ofdev;
int length;

if (*sdev->modalias) {
strscpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1);
strcat(buf, "\n");
length = strlen(buf);
} else {
length = sprintf(buf, "of:N%pOFn%c%s\n",
of->dev.of_node, 'T',
of_node_get_device_type(of->dev.of_node));
}

return length;
if (*sdev->modalias)
return sysfs_emit(buf, "%s\n", sdev->modalias);
else
return sysfs_emit(buf, "of:N%pOFn%c%s\n",
of->dev.of_node, 'T',
of_node_get_device_type(of->dev.of_node));
}
static DEVICE_ATTR_RO(modalias);

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

return sprintf(buf, "%pOFn\n", of->dev.of_node);
return sysfs_emit(buf, "%pOFn\n", of->dev.of_node);
}
static DEVICE_ATTR_RO(name);

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

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

Expand Down

0 comments on commit 0980bb1

Please sign in to comment.