public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Adam Goldman <adamg@pobox.com>
Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 7/8] firewire: core: detect model name for legacy layout of configuration ROM
Date: Mon, 18 Dec 2023 21:50:26 +0900	[thread overview]
Message-ID: <20231218125026.GB46034@workstation.local> (raw)
In-Reply-To: <ZYAZPRt79Qa1YPS0@iguana.lan>

Hi,

On Mon, Dec 18, 2023 at 02:04:52AM -0800, Adam Goldman wrote:
> Hi,
> 
> On Sun, Dec 17, 2023 at 07:30:10PM +0900, Takashi Sakamoto wrote:
> > -	ret = fw_csr_string(dir, attr->key, buf, bufsize);
> > +	for (i = 0; i < ARRAY_SIZE(directories) && directories[i]; ++i)
> > +		ret = fw_csr_string(directories[i], attr->key, buf, bufsize);
> 
> I believe this is incorrect. If the attribute is in the first directory 
> searched, the loop will continue. The second loop iteration will set ret 
> to -ENOENT because the attribute isn't in the second directory. Then 
> show_text_leaf will return -ENOENT even though the attribute existed.

Exactly. It is a bug.

I think we can solve it by aligning the pointers of directory in reverse
order within the array, like:

```
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index d3fc3270a00b..adae3268291f 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -326,13 +326,17 @@ static ssize_t show_text_leaf(struct device *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);

-               directories[0] = root_directory;
-
-               // 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[1] = 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] = vendor_directory;
+                       directories[1] = root_directory;
+               }
        }

        if (buf) {
@@ -342,8 +346,11 @@ static ssize_t show_text_leaf(struct device *dev,
                bufsize = 1;
        }

-       for (i = 0; i < ARRAY_SIZE(directories) && directories[i]; ++i)
+       for (i = 0; i < ARRAY_SIZE(directories) && directories[i]; ++i) {
                ret = fw_csr_string(directories[i], attr->key, buf, bufsize);
+               if (ret >= 0)
+                       break;
+       }

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

Thanks

Takashi Sakamoto

  reply	other threads:[~2023-12-18 12:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-17 10:30 [RFC PATCH 0/8] firewire: core: support legacy layout of configuration ROM for AV/C device Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 1/8] firewire: core: adds constant qualifier for local helper functions Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 2/8] firewire: core: replace magic number with macro Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 3/8] firewire: test: add KUnit test for internal CSR API Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 4/8] firewire: test: add test of CSR API for simple AV/C device Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 5/8] firewire: test: add test of CSR API for legacy " Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 6/8] firewire: core: detect numeric model identifier for legacy layout of configuration ROM Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 7/8] firewire: core: detect model name " Takashi Sakamoto
2023-12-18 10:04   ` Adam Goldman
2023-12-18 12:50     ` Takashi Sakamoto [this message]
2023-12-17 10:30 ` [RFC PATCH 8/8] firewire: core: change modalias of unit device and loss of backward compatibility Takashi Sakamoto
2023-12-17 10:30 ` [RFC PATCH 8/8] firewire: core: change modalias of unit device with backward incompatibility Takashi Sakamoto
2023-12-18 10:11   ` Adam Goldman
2023-12-18 12:46     ` Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231218125026.GB46034@workstation.local \
    --to=o-takashi@sakamocchi.jp \
    --cc=adamg@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox