On Fri, Feb 13, 2026 at 07:18:35PM -0500, Nicholas Vinson wrote:
> With C23, strstr() returns a 'const char *' if its first agrument is
> 'const char *', and these changes are implemented in glibc-2.43.
>
> As a result, the first strstr() call in check_sas() now returns a 'const
> char *' instead of 'char *' because sysfs_path is a 'const char *'. This
> triggers a "discards qualifiers" warning, that is later promoted to an
> error and ultimately causes the build to fail.
>
> To fix the issue, this patch converts 'ed', the pointer that stores
> strstr()'s return value, to a 'const char *'. Removes the xstrdup()
> call and cleans up the rest of the function by updating the *printf()
> calls and using pointer arthimetic to compute lengths instead of
> strlen().
>
> Signed-off-by: Nicholas Vinson <[email protected]>
> ---
>  grub-core/osdep/linux/ofpath.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
> index 24a4d5c8d..8dd311651 100644
> --- a/grub-core/osdep/linux/ofpath.c
> +++ b/grub-core/osdep/linux/ofpath.c
> @@ -488,8 +488,11 @@ check_hba_identifiers (const char *sysfs_path, int 
> *vendor, int *device_id)
>  static void
>  check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address)
>  {
> -  char *ed = strstr (sysfs_path, "end_device");
> -  char *p, *q, *path;
> +  const char *ed = strstr (sysfs_path, "end_device");
> +  int p_len;
> +  int ed_len;
> +  const char *q;
> +  char *path;
>    char phy[21];
>    int fd;
>    size_t path_size;
> @@ -498,20 +501,16 @@ check_sas (const char *sysfs_path, int *tgt, unsigned 
> long int *sas_address)
>      return;
>
>    /* SAS devices are identified using disk@$PHY_ID */
> -  p = xstrdup (sysfs_path);
> -  ed = strstr(p, "end_device");
> -  if (!ed)
> -    return;
> -
>    q = ed;

You blindly assume the "ed" is not NULL here. It is not true after
"if" removal above.

>    while (*q && *q != '/')
>      q++;
> -  *q = '\0';
> +  p_len = (int)(q - sysfs_path);
> +  ed_len = (int)(q - ed);

Missing spaces after (int)...

> -  path_size = (strlen (p) + strlen (ed)
> -            + sizeof ("%s/sas_device/%s/phy_identifier"));
> +  path_size = (p_len + ed_len + sizeof ("/sas_device//phy_identifier"));

This sizof() change makes sens for me but it has to be reflected in the
commit message.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to