Skip to contentSkip to conversation

lock warning cleanups

PATCH New Jules Irenge 1 participant 7 messages Mar 16, 2020 VFS

lore
Share & tools
lore
#0 lore raw

cover lock warning cleanups

This patch series adds missing annotations to various functions, that register warnings of context imbalance when built with Sparse tool. The adds fix the warnings, improve on readability of the code
and give better insight or directive on what the functions are actually doing.

Jules Irenge (6):
namei: Add missing annotation for unlazy_walk()
namei: Add missing annotation for unlazy_child()
fs: Add missing annotation for __wait_on_freeing_inode() fs/fs-writeback.c: Add missing annotation for
wbc_attach_and_unlock_inode()
fs/fs-writeback.c: replace two annotations for
__inode_wait_for_writeback()
fs: add missing annotation for pin_kill()

 fs/fs-writeback.c | 4 ++--
 fs/fs_pin.c       | 1 +
 fs/inode.c        | 2 ++
 fs/namei.c        | 2 ++
 4 files changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/6 namei: Add missing annotation for unlazy_walk()

Sparse reports a warning at unlazy_walk()

warning: context imbalance in unlazy_walk() - unexpected unlock

The root cause is the missing annotation at unlazy_walk()

Add the missing __releases(RCU) annotation

---
 fs/namei.c | 1 +
 1 file changed, 1 insertion(+)
fs/namei.c +1 -0
index db6565c99825..d80e1ac8c211 100644
@@ -678,6 +678,7 @@ static bool legitimize_root(struct nameidata *nd)
  * terminate_walk().
  */
 static int unlazy_walk(struct nameidata *nd)
+	__releases(RCU)
 {
 	struct dentry *parent = nd->path.dentry;
 
Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/6 namei: Add missing annotation for unlazy_child()

In reply to Jules Irenge

Sparse reports a warning at unlazy_child()

warning: context imbalance in unlazy_child() - unexpected unlock

The root cause is the missing annotation at unlazy_walk()

Add the missing __releases(RCU) annotation

---
 fs/namei.c | 1 +
 1 file changed, 1 insertion(+)
fs/namei.c +1 -0
index d80e1ac8c211..9af3e8e438a1 100644
@@ -717,6 +717,7 @@ static int unlazy_walk(struct nameidata *nd)
  * terminate_walk().
  */
 static int unlazy_child(struct nameidata *nd, struct dentry *dentry, unsigned seq)
+	__releases(RCU)
 {
 	BUG_ON(!(nd->flags & LOOKUP_RCU));
 
Signature · 1 line
2.24.1
#3 lore raw

PATCH 3/6 fs: Add missing annotation for __wait_on_freeing_inode()

In reply to Jules Irenge

Sparse reports a warning at __wait_on_freeing_inode()

warning: context imbalance in __wait_on_freeing_inode() - unexpected unlock

The root cause is the missing annotations at __wait_on_freeing_inode()

Add the missing __releases(&inode->i_lock)
and __must_hold(&inode_hash_lock) annotations

---
 fs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/inode.c +2 -0
index 7d57068b6b7a..3b06c5c59883 100644
@@ -1955,6 +1955,8 @@ EXPORT_SYMBOL(inode_needs_sync);
  * will DTRT.
  */
 static void __wait_on_freeing_inode(struct inode *inode)
+	__releases(&inode->i_lock)
+	__must_hold(&inode_hash_lock)
 {
 	wait_queue_head_t *wq;
 	DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW);
Signature · 1 line
2.24.1
#4 lore raw

PATCH 4/6 fs/fs-writeback.c: Add missing annotation for wbc_attach_and_unlock_inode()

In reply to Jules Irenge

Sparse reports a warning at wbc_attach_and_unlock_inode()

warning: context imbalance in wbc_attach_and_unlock_inode() - unexpected unlock

The root cause is the missing annotation at wbc_attach_and_unlock_inode() Add the missing __releases(&inode->i_lock) annotation

---
 fs/fs-writeback.c | 1 +
 1 file changed, 1 insertion(+)
fs/fs-writeback.c +1 -0
index 76ac9c7d32ec..008e572faf32 100644
@@ -556,6 +556,7 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id)
  */
 void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
 				 struct inode *inode)
+	__releases(&inode->i_lock)
 {
 	if (!inode_cgwb_enabled(inode)) {
 		spin_unlock(&inode->i_lock);
Signature · 1 line
2.24.1
#5 lore raw

PATCH 5/6 fs/fs-writeback.c: replace two annotations for __inode_wait_for_writeback()

In reply to Jules Irenge

To improve readability of the code, __releases(inode->i_lock) and __acquires(inode->i_lock) annotations here are replaced by one annotation __must_hold(inode->i_lock)

---
 fs/fs-writeback.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/fs-writeback.c +1 -2
index 008e572faf32..d0c0dc10526d 100644
@@ -1322,8 +1322,7 @@ static int write_inode(struct inode *inode, struct writeback_control *wbc)
  * Caller must make sure inode cannot go away when we drop i_lock.
  */
 static void __inode_wait_for_writeback(struct inode *inode)
-	__releases(inode->i_lock)
-	__acquires(inode->i_lock)
+	__must_hold(inode->i_lock)
 {
 	DEFINE_WAIT_BIT(wq, &inode->i_state, __I_SYNC);
 	wait_queue_head_t *wqh;
Signature · 1 line
2.24.1
#6 lore raw

PATCH 6/6 fs: add missing annotation for pin_kill()

In reply to Jules Irenge

Sparse reports a warning at pin_kill()

warning: context imbalance in pin_kill() - unexpected unlock

The root cause is the missing annotation at pin_kill()

Add the missing __releases(RCU)

---
 fs/fs_pin.c | 1 +
 1 file changed, 1 insertion(+)
fs/fs_pin.c +1 -0
index 47ef3c71ce90..ee57700740df 100644
@@ -28,6 +28,7 @@ void pin_insert(struct fs_pin *pin, struct vfsmount *m)
 }
 
 void pin_kill(struct fs_pin *p)
+	__releases(RCU)
 {
 	wait_queue_entry_t wait;
 
Signature · 1 line
2.24.1