From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jb4YQ-0005Mm-Ce for mharc-grub-devel@gnu.org; Tue, 19 May 2020 11:53:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jb4YO-0005Ix-OO for grub-devel@gnu.org; Tue, 19 May 2020 11:53:16 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:20183 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jb4YN-0000mR-9m for grub-devel@gnu.org; Tue, 19 May 2020 11:53:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589903593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gsixFYNxTM0SQyBLijZRt4leZKfjb3sW1eg6elGzsjk=; b=W7Abscjm9QaDS2eYJuWVigFyldnpm+SLcT4xFvvii80iylhJveVKQCOfqsqUuhn7znMhK3 L9H/MRj2irycDEapg7BCA8u8qzXqhV4TqGC43S7mTIzXTkSsL+4rAS0vQGL2x3cG2xWiek zyIqU+MZgJD8/zUXCiLQ/QumKhal0tA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-ZAauXFbkO2S2yiZ93rQ_mg-1; Tue, 19 May 2020 11:53:11 -0400 X-MC-Unique: ZAauXFbkO2S2yiZ93rQ_mg-1 Received: by mail-wr1-f69.google.com with SMTP id h12so13803wrr.19 for ; Tue, 19 May 2020 08:53:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gsixFYNxTM0SQyBLijZRt4leZKfjb3sW1eg6elGzsjk=; b=HNVcb+MbDfGrKaTejkiXv/rku4yPsKXaBmzjOee/mDHOxNSCb4wQdj+G3hPyVmWBZZ XzWLF3a7IrHG5kEx3rMnrrbGYhyWxTJWnH6obgKcl8NDJUqMQV2whuRw48nKQSjETMDT lY5LdXK7CjtVpbB5RjQzncmjLzBF4kW4K4dVJdX93QVGEs3d58V47RA3FW6tvNGWPC3f /woiSzQ3iDmvLUCAm2SYfbAA5hw3XqxNpom4i6zEkq70hv6ehXpOeZDwfpjsfobmxZyj 6Ot8j2TPQcKAQ+Ns7jqheJDsWib+/FznjWLPt5hqn8ZsBRNglTE9uqlH8nBza4wOdYDY rCYA== X-Gm-Message-State: AOAM533334WgYBEKFjA0fDjw3Wj2EuCFLb3JIcOEndoM0W0BaXM3zXi0 ODlqFq3tfzsaH5kKyibhVQe0GAOx94kbTCqcKzxh+jc6US7E0h8WQOPMtbbt4ikmXtwyh703kJw +yIj/M/immTA= X-Received: by 2002:a1c:1d4d:: with SMTP id d74mr78213wmd.48.1589903590422; Tue, 19 May 2020 08:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmTeSfHPeGCATCUB7fpoWj3JjytVlXWqgpzkIfb3qSuifDinwjeiltY08S8jUXr96+0sNEog== X-Received: by 2002:a1c:1d4d:: with SMTP id d74mr78200wmd.48.1589903590185; Tue, 19 May 2020 08:53:10 -0700 (PDT) Received: from minerva.redhat.com ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id b65sm108842wmc.30.2020.05.19.08.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 08:53:09 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Javier Martinez Canillas , Daniel Axtens , Daniel Kiper , Leif Lindholm Subject: [PATCH v2] net: break out nested function Date: Tue, 19 May 2020 17:53:03 +0200 Message-Id: <20200519155303.1516941-1-javierm@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=205.139.110.61; envelope-from=javierm@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/18 23:19:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 15:53:17 -0000 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. Reported-by: Daniel Axtens Signed-off-by: Javier Martinez Canillas Tested-by: Daniel Axtens --- 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