Skip to content

Commit 88d92fb

Browse files
committed
Merge tag 'firewire-fixes-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394
Pull firewire fixes Takashi Sakamoto: "The previous pull includes some regressions in some device attributes exposed to sysfs. They are fixed now" * tag 'firewire-fixes-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394: firewire: core: add memo about the caller of show functions for device attributes Revert "firewire: Kill unnecessary buf check in device_attribute.show"
2 parents 241590e + bfb1ad3 commit 88d92fb

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/firewire/core-device.c

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

325-
return sysfs_emit(buf, "0x%06x\n", value);
325+
// Note that this function is also called by init_fw_attribute_group() with NULL pointer.
326+
return buf ? sysfs_emit(buf, "0x%06x\n", value) : 0;
326327
}
327328

328329
#define IMMEDIATE_ATTR(name, key) \
@@ -334,6 +335,8 @@ static ssize_t show_text_leaf(struct device *dev,
334335
struct config_rom_attribute *attr =
335336
container_of(dattr, struct config_rom_attribute, attr);
336337
const u32 *directories[] = {NULL, NULL};
338+
size_t bufsize;
339+
char dummy_buf[2];
337340
int i, ret = -ENOENT;
338341

339342
down_read(&fw_device_rwsem);
@@ -355,9 +358,16 @@ static ssize_t show_text_leaf(struct device *dev,
355358
}
356359
}
357360

361+
// Note that this function is also called by init_fw_attribute_group() with NULL pointer.
362+
if (buf) {
363+
bufsize = PAGE_SIZE - 1;
364+
} else {
365+
buf = dummy_buf;
366+
bufsize = 1;
367+
}
368+
358369
for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) {
359-
int result = fw_csr_string(directories[i], attr->key, buf,
360-
PAGE_SIZE - 1);
370+
int result = fw_csr_string(directories[i], attr->key, buf, bufsize);
361371
// Detected.
362372
if (result >= 0) {
363373
ret = result;
@@ -366,7 +376,7 @@ static ssize_t show_text_leaf(struct device *dev,
366376
// in the root directory follows to the directory entry for vendor ID
367377
// instead of the immediate value for vendor ID.
368378
result = fw_csr_string(directories[i], CSR_DIRECTORY | attr->key, buf,
369-
PAGE_SIZE - 1);
379+
bufsize);
370380
if (result >= 0)
371381
ret = result;
372382
}

0 commit comments

Comments
 (0)