Skip to contentSkip to conversation

staging: lustre/lustre/obdclass/llog_cat.c: get rid of sparse context imbalance warning

PATCH In review Tolga Ceylan 2 participants 4 messages Jun 2, 2015 – Jun 3, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lustre/lustre/obdclass/llog_cat.c: get rid of sparse context imbalance warning

In llog_cat_new_log(), sparse emits a context imbalance (unexpected lock) warning due its inability to detect the noreturn attribute in lbug_with_lock() function inside LBUG macro. Adding a never reached return statement suppresses this warning.

---
 drivers/staging/lustre/lustre/obdclass/llog_cat.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/lustre/lustre/obdclass/llog_cat.c +1 -0
index c8f6ab0..259947c 100644
@@ -108,6 +108,7 @@ static int llog_cat_new_log(const struct lu_env *env,
 		       index);
 		spin_unlock(&loghandle->lgh_hdr_lock);
 		LBUG(); /* should never happen */
+		return -EINVAL;
 	}
 	spin_unlock(&loghandle->lgh_hdr_lock);
 
Signature · 1 line
2.4.2
#1 lore raw
Quoted 4 lines · Tolga Ceylan

In llog_cat_new_log(), sparse emits a context imbalance (unexpected lock) warning due its inability to detect the noreturn attribute in lbug_with_lock() function inside LBUG macro. Adding a never reached return statement suppresses this warning.

but adding a statement which never executes, is that the correct solution? what about :

drivers/staging/lustre/lustre/obdclass/llog_cat.c +4 -5
index c8f6ab0..1cb3495 100644
@@ -103,13 +103,12 @@ static int llog_cat_new_log(const struct lu_env *env,
 
 	spin_lock(&loghandle->lgh_hdr_lock);
 	llh->llh_count++;
-	if (ext2_set_bit(index, llh->llh_bitmap)) {
-		CERROR("argh, index %u already set in log bitmap?\n",
-		       index);
-		spin_unlock(&loghandle->lgh_hdr_lock);
+	rc = ext2_set_bit(index, llh->llh_bitmap);
+	spin_unlock(&loghandle->lgh_hdr_lock);
+	if (rc) {
+		CERROR("argh, index %u already set in log bitmap?\n", index);
 		LBUG(); /* should never happen */
 	}
-	spin_unlock(&loghandle->lgh_hdr_lock);
 
 	cathandle->lgh_last_idx = index;
 	llh->llh_tail.lrt_index = index;

regards
sudip

#2 lore raw

The second patch is better (it also keeps the lock locked shorter.) Do I need to resend?

Quoted 35 lines · Sudip Mukherjee
Quoted 4 lines · Tolga Ceylan

In llog_cat_new_log(), sparse emits a context imbalance (unexpected lock) warning due its inability to detect the noreturn attribute in lbug_with_lock() function inside LBUG macro. Adding a never reached return statement suppresses this warning.

but adding a statement which never executes, is that the correct solution? what about :

drivers/staging/lustre/lustre/obdclass/llog_cat.c +4 -5
index c8f6ab0..1cb3495 100644
@@ -103,13 +103,12 @@ static int llog_cat_new_log(const struct lu_env *env,
 
        spin_lock(&loghandle->lgh_hdr_lock);
        llh->llh_count++;
-       if (ext2_set_bit(index, llh->llh_bitmap)) {
-               CERROR("argh, index %u already set in log bitmap?\n",
-                      index);
-               spin_unlock(&loghandle->lgh_hdr_lock);
+       rc = ext2_set_bit(index, llh->llh_bitmap);
+       spin_unlock(&loghandle->lgh_hdr_lock);
+       if (rc) {
+               CERROR("argh, index %u already set in log bitmap?\n", index);
                LBUG(); /* should never happen */
        }
-       spin_unlock(&loghandle->lgh_hdr_lock);
 
        cathandle->lgh_last_idx = index;
        llh->llh_tail.lrt_index = index;

regards
sudip

#3 lore raw
Quoted 2 lines · Tolga Ceylan

The second patch is better (it also keeps the lock locked shorter.) Do I need to resend?

yes, please, it was not formally submitted.

regards
sudip