Netfilter-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH nft] scanner: use list_is_first() from scanner_pop_indesc()
@ 2020-02-13 12:32 Pablo Neira Ayuso
  0 siblings, 0 replies; only message in thread
From: Pablo Neira Ayuso @ 2020-02-13 12:32 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fasnacht

!list_empty() always stands true since the list is never empty
when calling scanner_pop_indesc().

Check for list_is_first() which actually tells us this is the
initial input file, hence, state->indesc is set to NULL.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
@Fasnacht: this is a follow up on top of your patchset, that is already
           in git.netfilter.org/nftables.

 include/list.h | 11 +++++++++++
 src/scanner.l  |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/list.h b/include/list.h
index 75d292124010..9c4da81749de 100644
--- a/include/list.h
+++ b/include/list.h
@@ -33,6 +33,17 @@ static inline void init_list_head(struct list_head *list)
 	list->prev = list;
 }
 
+/**
+ * list_is_first -- tests whether @list is the first entry in list @head
+ * @list: the entry to test
+ * @head: the head of the list
+ */
+static inline int list_is_first(const struct list_head *list,
+				const struct list_head *head)
+{
+	return list->prev == head;
+}
+
 /*
  * Insert a new entry between two known consecutive entries.
  *
diff --git a/src/scanner.l b/src/scanner.l
index ed29833b6fc4..3932883b9ade 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -678,7 +678,7 @@ static void scanner_push_indesc(struct parser_state *state,
 
 static void scanner_pop_indesc(struct parser_state *state)
 {
-	if (!list_empty(&state->indesc_list)) {
+	if (!list_is_first(&state->indesc->list, &state->indesc_list)) {
 		state->indesc = list_entry(state->indesc->list.prev,
 					   struct input_descriptor, list);
 	} else {
-- 
2.11.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-13 12:32 [PATCH nft] scanner: use list_is_first() from scanner_pop_indesc() Pablo Neira Ayuso

Netfilter-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netfilter-devel/0 netfilter-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netfilter-devel netfilter-devel/ https://lore.kernel.org/netfilter-devel \
		netfilter-devel@vger.kernel.org
	public-inbox-index netfilter-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netfilter-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git