Skip to content

Commit 4a2b06c

Browse files
zhijianli88takaswie
authored andcommitted
firewire: Kill unnecessary buf check in device_attribute.show
Per Documentation/filesystems/sysfs.rst: > sysfs allocates a buffer of size (PAGE_SIZE) and passes it to the > method. So we can kill the unnecessary buf check safely. Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> Link: https://lore.kernel.org/r/20240122053942.80648-1-lizhijian@fujitsu.com Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent e8f897f commit 4a2b06c

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

drivers/firewire/core-device.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static ssize_t show_immediate(struct device *dev,
322322
if (value < 0)
323323
return -ENOENT;
324324

325-
return snprintf(buf, buf ? PAGE_SIZE : 0, "0x%06x\n", value);
325+
return snprintf(buf, PAGE_SIZE, "0x%06x\n", value);
326326
}
327327

328328
#define IMMEDIATE_ATTR(name, key) \
@@ -334,8 +334,6 @@ static ssize_t show_text_leaf(struct device *dev,
334334
struct config_rom_attribute *attr =
335335
container_of(dattr, struct config_rom_attribute, attr);
336336
const u32 *directories[] = {NULL, NULL};
337-
size_t bufsize;
338-
char dummy_buf[2];
339337
int i, ret = -ENOENT;
340338

341339
down_read(&fw_device_rwsem);
@@ -357,15 +355,9 @@ static ssize_t show_text_leaf(struct device *dev,
357355
}
358356
}
359357

360-
if (buf) {
361-
bufsize = PAGE_SIZE - 1;
362-
} else {
363-
buf = dummy_buf;
364-
bufsize = 1;
365-
}
366-
367358
for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) {
368-
int result = fw_csr_string(directories[i], attr->key, buf, bufsize);
359+
int result = fw_csr_string(directories[i], attr->key, buf,
360+
PAGE_SIZE - 1);
369361
// Detected.
370362
if (result >= 0) {
371363
ret = result;

0 commit comments

Comments
 (0)