From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH] intervals: Simplify element sanity checks
Date: Thu, 14 Apr 2022 13:39:24 +0200 [thread overview]
Message-ID: <20220414113924.15553-1-phil@nwl.cc> (raw)
Since setelem_delete() assigns to 'prev' pointer only if it doesn't have
EXPR_F_REMOVE flag set, there is no need to check that flag in called
functions.
Fixes: 3e8d934e4f722 ("intervals: support to partial deletion with automerge")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
src/intervals.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/src/intervals.c b/src/intervals.c
index 451bc4dd4dd45..c0077c06880ff 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -265,14 +265,12 @@ static void remove_elem(struct expr *prev, struct set *set, struct expr *purge)
{
struct expr *clone;
- if (!(prev->flags & EXPR_F_REMOVE)) {
- if (prev->flags & EXPR_F_KERNEL) {
- clone = expr_clone(prev);
- list_move_tail(&clone->list, &purge->expressions);
- } else {
- list_del(&prev->list);
- expr_free(prev);
- }
+ if (prev->flags & EXPR_F_KERNEL) {
+ clone = expr_clone(prev);
+ list_move_tail(&clone->list, &purge->expressions);
+ } else {
+ list_del(&prev->list);
+ expr_free(prev);
}
}
@@ -360,18 +358,15 @@ static int setelem_adjust(struct set *set, struct expr *add, struct expr *purge,
{
if (mpz_cmp(prev_range->low, range->low) == 0 &&
mpz_cmp(prev_range->high, range->high) > 0) {
- if (!(prev->flags & EXPR_F_REMOVE) &&
- i->flags & EXPR_F_REMOVE)
+ if (i->flags & EXPR_F_REMOVE)
adjust_elem_left(set, prev, i, add, purge);
} else if (mpz_cmp(prev_range->low, range->low) < 0 &&
mpz_cmp(prev_range->high, range->high) == 0) {
- if (!(prev->flags & EXPR_F_REMOVE) &&
- i->flags & EXPR_F_REMOVE)
+ if (i->flags & EXPR_F_REMOVE)
adjust_elem_right(set, prev, i, add, purge);
} else if (mpz_cmp(prev_range->low, range->low) < 0 &&
mpz_cmp(prev_range->high, range->high) > 0) {
- if (!(prev->flags & EXPR_F_REMOVE) &&
- i->flags & EXPR_F_REMOVE)
+ if (i->flags & EXPR_F_REMOVE)
split_range(set, prev, i, add, purge);
} else {
return -1;
@@ -417,8 +412,7 @@ static int setelem_delete(struct list_head *msgs, struct set *set,
if (mpz_cmp(prev_range.low, range.low) == 0 &&
mpz_cmp(prev_range.high, range.high) == 0) {
- if (!(prev->flags & EXPR_F_REMOVE) &&
- i->flags & EXPR_F_REMOVE) {
+ if (i->flags & EXPR_F_REMOVE) {
list_move_tail(&prev->list, &purge->expressions);
list_del(&i->list);
expr_free(i);
--
2.34.1
next reply other threads:[~2022-04-14 11:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-14 11:39 Phil Sutter [this message]
2022-04-14 16:22 ` [nft PATCH] intervals: Simplify element sanity checks Pablo Neira Ayuso
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=20220414113924.15553-1-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).