From: Harry Wentland <harry.wentland@amd.com>
To: Roman.Li@amd.com, igt-dev@lists.freedesktop.org
Cc: alex.hung@amd.com
Subject: Re: [PATCH i-g-t] lib/igt_amd: improve link_settings parser for old kernel compatibility
Date: Thu, 10 Sep 2026 14:07:47 -0400 [thread overview]
Message-ID: <d93a23d9-d399-4ed2-8ba2-445573817f15@amd.com> (raw)
In-Reply-To: <20260909204408.936021-1-Roman.Li@amd.com>
On 2026-09-09 16:44, Roman.Li@amd.com wrote:
> From: Roman Li <Roman.Li@amd.com>
>
> The previous fix uses strstr() to locate each record label. However,
> strstr() stops at the first NUL byte (C string semantics), which breaks
> backward compatibility with old kernels that embed NUL bytes between
> records. Only the Current record would parse, leaving Verified, Reported,
> and Preferred unset (0), causing the same failure as the original bug.
>
> Use memmem() instead to search the raw buffer across NUL boundaries,
> combined with sscanf() for parsing. This works with both:
> - Old kernels: with embedded NUL separators
> - New kernels: with contiguous single string
>
> Also replace hardcoded loop bound '4' with ARRAY_SIZE(labels) for
> better maintainability.
>
> Tested on eDP with both kernel variants: amd_ilr passes in both cases.
>
> Fixes: f234bbd294f5 ("lib/igt_amd: don't rely on NUL separators parsing link_settings")
> Cc: Harry Wentland <harry.wentland@amd.com>
> Assisted-by: Claude Haiku 4.5
> Signed-off-by: Roman Li <Roman.Li@amd.com>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Harry
> ---
> lib/igt_amd.c | 35 ++++++++++++++++++++---------------
> 1 file changed, 20 insertions(+), 15 deletions(-)
>
> diff --git a/lib/igt_amd.c b/lib/igt_amd.c
> index 7d33ab658..ba1cfabcf 100644
> --- a/lib/igt_amd.c
> +++ b/lib/igt_amd.c
> @@ -836,10 +836,8 @@ void igt_amd_read_link_settings(
> static const char * const labels[] = {
> "Current:", "Verified:", "Reported:", "Preferred:"
> };
> - int fd, ret;
> + int fd, ret, i;
> char buf[101];
> - char *ptr;
> - int i;
>
> fd = igt_debugfs_connector_dir(drm_fd, connector_name, O_RDONLY);
> if (fd < 0) {
> @@ -853,22 +851,29 @@ void igt_amd_read_link_settings(
>
> close(fd);
>
> - /* The debugfs node returns a single NUL-terminated string of the form:
> + /* The debugfs node returns a string of the form:
> * "Current: %d 0x%x %d Verified: %d 0x%x %d "
> * "Reported: %d 0x%x %d Preferred: %d 0x%x %d\n"
> - * Locate each label and parse the three values that follow it. Do not
> - * rely on embedded NUL bytes (or any other delimiter) between records,
> - * as the kernel emits a single contiguous string. */
> - ptr = buf;
> - for (i = 0; i < 4; i++) {
> - ptr = strstr(ptr, labels[i]);
> - if (ptr == NULL)
> + * Old kernels embed NUL bytes between records; new kernels emit a
> + * contiguous string. Use memmem() to locate each label across NUL
> + * boundaries and sscanf() to parse values, so both layouts work.
> + */
> + for (i = 0; i < ARRAY_SIZE(labels); i++) {
> + const char *label = labels[i];
> + char *rec = memmem(buf, ret, label, strlen(label));
> + unsigned int rate;
> + int lanes, spread;
> +
> + if (!rec)
> + break;
> +
> + if (sscanf(rec + strlen(label), "%d %x %d",
> + &lanes, &rate, &spread) != 3)
> break;
>
> - ptr += strlen(labels[i]);
> - lane_count[i] = strtol(ptr, &ptr, 10);
> - link_rate[i] = strtol(ptr, &ptr, 16);
> - link_spread[i] = strtol(ptr, &ptr, 10);
> + lane_count[i] = lanes;
> + link_rate[i] = rate;
> + link_spread[i] = spread;
> }
> }
>
prev parent reply other threads:[~2026-09-10 18:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 20:44 [PATCH i-g-t] lib/igt_amd: improve link_settings parser for old kernel compatibility Roman.Li
2026-09-10 0:33 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-09-10 0:40 ` ✗ i915.CI.BAT: failure " Patchwork
2026-09-10 12:09 ` ✗ Xe.CI.FULL: " Patchwork
2026-09-10 18:07 ` Harry Wentland [this message]
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=d93a23d9-d399-4ed2-8ba2-445573817f15@amd.com \
--to=harry.wentland@amd.com \
--cc=Roman.Li@amd.com \
--cc=alex.hung@amd.com \
--cc=igt-dev@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.