Skip to content

Commit 2eab8bc

Browse files
committed
firewire: core: detect model name for legacy layout of configuration ROM
As the part of support for legacy layout of configuration ROM, this commit traverses vendor directory as well as root directory when showing device attribute for node device. This change expects 'model_name' attribute appears in node device, however it is probable to see the other types of descriptor leaf if the vendor directory includes. Suggested-by: Adam Goldman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Sakamoto <[email protected]>
1 parent b6a3805 commit 2eab8bc

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

drivers/firewire/core-device.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,29 @@ static ssize_t show_text_leaf(struct device *dev,
317317
{
318318
struct config_rom_attribute *attr =
319319
container_of(dattr, struct config_rom_attribute, attr);
320-
const u32 *dir;
320+
const u32 *directories[] = {NULL, NULL};
321321
size_t bufsize;
322322
char dummy_buf[2];
323-
int ret;
323+
int i, ret = -ENOENT;
324324

325325
down_read(&fw_device_rwsem);
326326

327-
if (is_fw_unit(dev))
328-
dir = fw_unit(dev)->directory;
329-
else
330-
dir = fw_device(dev)->config_rom + ROOT_DIR_OFFSET;
327+
if (is_fw_unit(dev)) {
328+
directories[0] = fw_unit(dev)->directory;
329+
} else {
330+
const u32 *root_directory = fw_device(dev)->config_rom + ROOT_DIR_OFFSET;
331+
const u32 *vendor_directory = search_directory(root_directory, CSR_VENDOR);
332+
333+
if (!vendor_directory) {
334+
directories[0] = root_directory;
335+
} else {
336+
// Legacy layout of configuration ROM described in Annex 1 of
337+
// 'Configuration ROM for AV/C Devices 1.0 (December 12, 2000, 1394
338+
// Trading Association, TA Document 1999027)'.
339+
directories[0] = root_directory;
340+
directories[1] = vendor_directory;
341+
}
342+
}
331343

332344
if (buf) {
333345
bufsize = PAGE_SIZE - 1;
@@ -336,7 +348,12 @@ static ssize_t show_text_leaf(struct device *dev,
336348
bufsize = 1;
337349
}
338350

339-
ret = fw_csr_string(dir, attr->key, buf, bufsize);
351+
for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) {
352+
int result = fw_csr_string(directories[i], attr->key, buf, bufsize);
353+
// Detected.
354+
if (result >= 0)
355+
ret = result;
356+
}
340357

341358
if (ret >= 0) {
342359
/* Strip trailing whitespace and add newline. */

drivers/firewire/device-attribute-test.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ static void device_attr_legacy_avc(struct kunit *test)
206206
// Descriptor leaf entry for vendor is not found.
207207
KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[5].attr, buf), 0);
208208

209-
// Descriptor leaf entry for model is not found.
210-
KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0);
209+
// Descriptor leaf entry for model is found.
210+
KUNIT_EXPECT_GT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0);
211+
KUNIT_EXPECT_STREQ(test, buf, "ABCDEFGHIJ\n");
211212

212213
// For entries in unit 0 directory.
213214

0 commit comments

Comments
 (0)