All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leif Lindholm <leif@nuviainc.com>
To: Javier Martinez Canillas <javierm@redhat.com>
Cc: grub-devel@gnu.org, Daniel Axtens <dja@axtens.net>,
	Daniel Kiper <daniel.kiper@oracle.com>
Subject: Re: [PATCH v2] net: break out nested function
Date: Tue, 19 May 2020 17:18:11 +0100	[thread overview]
Message-ID: <20200519161811.GD1923@vanye> (raw)
In-Reply-To: <20200519155303.1516941-1-javierm@redhat.com>

On Tue, May 19, 2020 at 17:53:03 +0200, Javier Martinez Canillas wrote:
> Nested functions are not supported in C, but are permitted as an extension
> in the GNU C dialect. Commit cb2f15c5448 ("normal/main: Search for specific
> config files for netboot") added a nested function which caused the build
> to break when compiling with clang.
> 
> Break that out into a static helper function to make the code portable
> again.

Works for me.
Acked-by: Leif Lindholm <leif@nuviainc.com>

> Reported-by: Daniel Axtens <dja@axtens.net>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> Tested-by: Daniel Axtens <dja@axtens.net>
> ---
> 
> Changes in v2:
> - Reword subject and commit message as suggested by Leif Lindholm.
> - Fix code style issue on function definition.
> - Add Daniel Axtens Tested-by tag (thanks!).
> 
>  grub-core/net/net.c | 65 +++++++++++++++++++++++----------------------
>  1 file changed, 33 insertions(+), 32 deletions(-)
> 
> diff --git a/grub-core/net/net.c b/grub-core/net/net.c
> index c42f0f4f71d..3a310c939b5 100644
> --- a/grub-core/net/net.c
> +++ b/grub-core/net/net.c
> @@ -1735,42 +1735,43 @@ grub_net_restore_hw (void)
>    return GRUB_ERR_NONE;
>  }
>  
> -grub_err_t
> -grub_net_search_config_file (char *config)
> +static int
> +grub_config_search_through (char *config, char *suffix,
> +			    grub_size_t num_tries, grub_size_t slice_size)
>  {
> -  grub_size_t config_len;
> -  char *suffix;
> +  while (num_tries-- > 0)
> +    {
> +      grub_file_t file;
>  
> -  auto int search_through (grub_size_t num_tries, grub_size_t slice_size);
> -  int search_through (grub_size_t num_tries, grub_size_t slice_size)
> -  {
> -    while (num_tries-- > 0)
> -      {
> -        grub_file_t file;
> +      grub_dprintf ("net", "attempt to fetch config %s\n", config);
>  
> -        grub_dprintf ("net", "attempt to fetch config %s\n", config);
> +      file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
>  
> -        file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
> +      if (file)
> +        {
> +          grub_file_close (file);
> +          return 0;
> +        }
> +      else
> +        {
> +          if (grub_errno == GRUB_ERR_IO)
> +            grub_errno = GRUB_ERR_NONE;
> +        }
>  
> -        if (file)
> -          {
> -            grub_file_close (file);
> -            return 0;
> -          }
> -        else
> -          {
> -            if (grub_errno == GRUB_ERR_IO)
> -              grub_errno = GRUB_ERR_NONE;
> -          }
> +      if (grub_strlen (suffix) < slice_size)
> +        break;
>  
> -        if (grub_strlen (suffix) < slice_size)
> -          break;
> +      config[grub_strlen (config) - slice_size] = '\0';
> +    }
>  
> -        config[grub_strlen (config) - slice_size] = '\0';
> -      }
> +  return 1;
> +}
>  
> -    return 1;
> -  }
> +grub_err_t
> +grub_net_search_config_file (char *config)
> +{
> +  grub_size_t config_len;
> +  char *suffix;
>  
>    config_len = grub_strlen (config);
>    config[config_len] = '-';
> @@ -1801,7 +1802,7 @@ grub_net_search_config_file (char *config)
>        if (client_uuid)
>          {
>            grub_strcpy (suffix, client_uuid);
> -          if (search_through (1, 0) == 0)
> +          if (grub_config_search_through (config, suffix, 1, 0) == 0)
>              return GRUB_ERR_NONE;
>          }
>  
> @@ -1816,7 +1817,7 @@ grub_net_search_config_file (char *config)
>          if (*ptr == ':')
>            *ptr = '-';
>  
> -      if (search_through (1, 0) == 0)
> +      if (grub_config_search_through (config, suffix, 1, 0) == 0)
>          return GRUB_ERR_NONE;
>  
>        /* By IP address */
> @@ -1831,7 +1832,7 @@ grub_net_search_config_file (char *config)
>                             ((n >> 24) & 0xff), ((n >> 16) & 0xff),      \
>                             ((n >> 8) & 0xff), ((n >> 0) & 0xff));
>  
> -            if (search_through (8, 1) == 0)
> +            if (grub_config_search_through (config, suffix, 8, 1) == 0)
>                return GRUB_ERR_NONE;
>              break;
>            }
> @@ -1848,7 +1849,7 @@ grub_net_search_config_file (char *config)
>                  *ptr = '-';
>  
>              grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf);
> -            if (search_through (1, 0) == 0)
> +            if (grub_config_search_through (config, suffix, 1, 0) == 0)
>                return GRUB_ERR_NONE;
>              break;
>            }
> -- 
> 2.26.2
> 


  reply	other threads:[~2020-05-19 16:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19 15:53 [PATCH v2] net: break out nested function Javier Martinez Canillas
2020-05-19 16:18 ` Leif Lindholm [this message]
2020-05-20 13:16   ` Daniel Kiper

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=20200519161811.GD1923@vanye \
    --to=leif@nuviainc.com \
    --cc=daniel.kiper@oracle.com \
    --cc=dja@axtens.net \
    --cc=grub-devel@gnu.org \
    --cc=javierm@redhat.com \
    /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.