[PATCH v2] net: atm: Add annotation for lec_priv_walk() and lec_seq_stop()

From: Jules Irenge
Date: Wed Apr 29 2020 - 11:00:29 EST


Sparse reports a warning at lec_priv_walk() and lec_seq_stop()

warning: context imbalance in lec_priv_walk() - unexpected unlock
warning: context imbalance in lec_seq_stop() - unexpected unlock

The root cause is the missing annotation at lec_priv_walk()
and lec_seq_stop()
To fix this, __acquire() and __release() annotations
are added in case conditions are not met.
This only instruct Sparse to shutdown the warning

Add the __acquire(&priv->lec_arp_lock)
Add __release(&priv->lec_arp_lock) annotation
Add __releases(&state->locked->lec_arp_lock) annotation
Add __release(&state->locked->lec_arp_lock) annotation

Signed-off-by: Jules Irenge <jbi.octave@xxxxxxxxx>
---
Changes since v2
- merge patch No 6 and No 4 into one

net/atm/lec.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/net/atm/lec.c b/net/atm/lec.c
index 25fa3a7b72bd..7947abb17af2 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -886,12 +886,18 @@ static void *lec_priv_walk(struct lec_state *state, loff_t *l,
if (!state->locked) {
state->locked = priv;
spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
+ } else {
+ /* annotation for sparse */
+ __acquire(&priv->lec_arp_lock);
}
if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
state->locked = NULL;
/* Partial state reset for the next time we get called */
state->arp_table = state->misc_table = 0;
+ } else {
+ /* annotation for sparse */
+ __release(&priv->lec_arp_lock);
}
return state->locked;
}
@@ -940,6 +946,7 @@ static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
}

static void lec_seq_stop(struct seq_file *seq, void *v)
+ __releases(&state->locked->lec_arp_lock)
{
struct lec_state *state = seq->private;

@@ -947,6 +954,9 @@ static void lec_seq_stop(struct seq_file *seq, void *v)
spin_unlock_irqrestore(&state->locked->lec_arp_lock,
state->flags);
dev_put(state->dev);
+ } else {
+ /* annotation for sparse */
+ __release(&state->locked->lec_arp_lock);
}
}

--
2.25.3