Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752401AbdL0TAq (ORCPT ); Wed, 27 Dec 2017 14:00:46 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36000 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751187AbdL0TAo (ORCPT ); Wed, 27 Dec 2017 14:00:44 -0500 X-Google-Smtp-Source: ACJfBoshSs+4GGnofoBp0vEYAkNVMaKTpEvs9dYIeCj9c961Ed11nIpiB0Wd3dGPIJrYr5h4EUt7aA== Date: Wed, 27 Dec 2017 11:00:43 -0800 From: Alexei Starovoitov To: Eric Leblond Cc: netdev@vger.kernel.org, daniel@iogearbox.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] libbpf: break loop earlier Message-ID: <20171227190042.hwxk6ccazdtnob77@ast-mbp> References: <20171227022730.y27gwva2u2ilyrul@ast-mbp> <20171227180229.1926-1-eric@regit.org> <20171227180229.1926-4-eric@regit.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171227180229.1926-4-eric@regit.org> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 886 Lines: 26 On Wed, Dec 27, 2017 at 07:02:28PM +0100, Eric Leblond wrote: > Get out of the loop when we have a match. > > Signed-off-by: Eric Leblond > --- > tools/lib/bpf/libbpf.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 5fe8aaa2123e..d263748aa341 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -412,6 +412,7 @@ bpf_object__init_prog_names(struct bpf_object *obj) > prog->section_name); > return -LIBBPF_ERRNO__LIBELF; > } > + break; why this is needed? The top of the loop is: for (si = 0; si < symbols->d_size / sizeof(GElf_Sym) && !name; so as soon as name is found the loop will exit. I agree that the loop structure is non-standard is confusing, but adding break here will make it even more so. If 'break' is added then '&& !name' should be removed.