firewire: core: detect model name for legacy layout of configuration ROM
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 24 Dec 2023 22:23:01 +0000 (07:23 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 8 Jan 2024 00:36:56 +0000 (09:36 +0900)
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 <adamg@pobox.com>
Link: https://lore.kernel.org/r/20231221134849.603857-8-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
drivers/firewire/core-device.c
drivers/firewire/device-attribute-test.c

index 2c8771305acafa767b6b324da914cded1b055061..fd4c025a3f70ff3c348e05374c6adda22a35c991 100644 (file)
@@ -317,17 +317,29 @@ static ssize_t show_text_leaf(struct device *dev,
 {
        struct config_rom_attribute *attr =
                container_of(dattr, struct config_rom_attribute, attr);
-       const u32 *dir;
+       const u32 *directories[] = {NULL, NULL};
        size_t bufsize;
        char dummy_buf[2];
-       int ret;
+       int i, ret = -ENOENT;
 
        down_read(&fw_device_rwsem);
 
-       if (is_fw_unit(dev))
-               dir = fw_unit(dev)->directory;
-       else
-               dir = fw_device(dev)->config_rom + ROOT_DIR_OFFSET;
+       if (is_fw_unit(dev)) {
+               directories[0] = fw_unit(dev)->directory;
+       } else {
+               const u32 *root_directory = fw_device(dev)->config_rom + ROOT_DIR_OFFSET;
+               const u32 *vendor_directory = search_directory(root_directory, CSR_VENDOR);
+
+               if (!vendor_directory) {
+                       directories[0] = root_directory;
+               } else {
+                       // Legacy layout of configuration ROM described in Annex 1 of
+                       // 'Configuration ROM for AV/C Devices 1.0 (December 12, 2000, 1394
+                       // Trading Association, TA Document 1999027)'.
+                       directories[0] = root_directory;
+                       directories[1] = vendor_directory;
+               }
+       }
 
        if (buf) {
                bufsize = PAGE_SIZE - 1;
@@ -336,7 +348,12 @@ static ssize_t show_text_leaf(struct device *dev,
                bufsize = 1;
        }
 
-       ret = fw_csr_string(dir, attr->key, buf, bufsize);
+       for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) {
+               int result = fw_csr_string(directories[i], attr->key, buf, bufsize);
+               // Detected.
+               if (result >= 0)
+                       ret = result;
+       }
 
        if (ret >= 0) {
                /* Strip trailing whitespace and add newline. */
index 689115433425f41b7f2c4802203f827d0e30bf99..da2a4a09bf840a863a41495a1ba3484184d93483 100644 (file)
@@ -206,8 +206,9 @@ static void device_attr_legacy_avc(struct kunit *test)
        // Descriptor leaf entry for vendor is not found.
        KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[5].attr, buf), 0);
 
-       // Descriptor leaf entry for model is not found.
-       KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0);
+       // Descriptor leaf entry for model is found.
+       KUNIT_EXPECT_GT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0);
+       KUNIT_EXPECT_STREQ(test, buf, "ABCDEFGHIJ\n");
 
        // For entries in unit 0 directory.