Re: [PATCH] firewire: convert sysfs sprintf/snprintf family to sysfs_emit

From: Joe Perches
Date: Thu Feb 04 2021 - 02:06:15 EST


On Thu, 2021-02-04 at 14:50 +0800, Jiapeng Chong wrote:
> Fix the following coccicheck warning:
>
> ./drivers/firewire/core-device.c:375:8-16: WARNING: use scnprintf or
> sprintf.
[]
> diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
[]
> @@ -372,8 +372,7 @@ static ssize_t rom_index_show(struct device *dev,
>   struct fw_device *device = fw_device(dev->parent);
>   struct fw_unit *unit = fw_unit(dev);
>  
>
> - return snprintf(buf, PAGE_SIZE, "%d\n",
> - (int)(unit->directory - device->config_rom));
> + return sysfs_emit(buf, "%d\n", (int)(unit->directory - device->config_rom));

Perhaps this should use the ptrdiff_t qualifier '%td' instead:

return sysfs_emit(buf, "%td\n", unit->directory - device->config_rom);