Skip to contentSkip to conversation

net: ceph: messenger: replace uses of BUG_ON() with WARN_ON()

PATCH New Ioana Ciornei 1 participant 3 messages Jan 27, 2016 Ceph common code (libceph)

lore
Share & tools
lore
#0 lore raw

cover net: ceph: messenger: replace uses of BUG_ON() with WARN_ON()

This patchset replaces some uses of BUG_ON() with WARN_ON() and an approapriate exit since it is advisable not to crash the machin in every case.

Ioana Ciornei (2):
net: ceph: messenger: change BUG_ON() to WARN_ON() from

    ceph_con_in_msg_alloc()

net: ceph: messenger: replace BUG_ON() with WARN_ON() in con_flag_*
functions

 net/ceph/messenger.c | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)
Signature · 1 line
2.6.4
#1 lore raw

PATCH 1/2 net: ceph: messenger: change BUG_ON() to WARN_ON() from ceph_con_in_msg_alloc()

This patch replaces the uses of BUG_ON() from the function ceph_con_in_msg_alloc() with WARN_ON() and an exit strategy. There is no reason to crash the kernel if we can warn the user and return an appropriate error code to the above layer in the calling hierarchy.

---
 net/ceph/messenger.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
net/ceph/messenger.c +12 -3
index 9cfedf5..9a5e54c 100644
@@ -3348,8 +3348,14 @@ static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip)
 	struct ceph_msg *msg;
 	int ret = 0;
 
-	BUG_ON(con->in_msg != NULL);
-	BUG_ON(!con->ops->alloc_msg);
+	if (WARN_ON(con->in_msg)) {
+		con->in_msg = NULL;
+		return -ENOENT;
+	}
+	if (WARN_ON(!con->ops->alloc_msg)) {
+		con->in_msg = NULL;
+		return -ENOENT;
+	}
 
 	mutex_unlock(&con->mutex);
 	msg = con->ops->alloc_msg(con, hdr, skip);
@@ -3360,7 +3366,10 @@ static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip)
 		return -EAGAIN;
 	}
 	if (msg) {
-		BUG_ON(*skip);
+		if (WARN_ON(*skip)) {
+			con->in_msg = NULL;
+			return -ENOENT;
+		}
 		msg_con_set(msg, con);
 		con->in_msg = msg;
 	} else {
Signature · 1 line
2.6.4
#2 lore raw

PATCH 2/2 net: ceph: messenger: replace BUG_ON() with WARN_ON() in con_flag_* functions

In reply to Ioana Ciornei

This patch replaces BUG_ON() with WARN_ON() and an appropriate warning message and exit since the condition verified is not influenced by user input.

---
 net/ceph/messenger.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
net/ceph/messenger.c +20 -5
index 9a5e54c..1e5aac6 100644
@@ -116,21 +116,30 @@ static bool con_flag_valid(unsigned long con_flag)
 
 static void con_flag_clear(struct ceph_connection *con, unsigned long con_flag)
 {
-	BUG_ON(!con_flag_valid(con_flag));
+	if (WARN_ON(!con_flag_valid(con_flag))) {
+		pr_warn("con_flag_clear called with an invalid flag\n");
+		return;
+	}
 
 	clear_bit(con_flag, &con->flags);
 }
 
 static void con_flag_set(struct ceph_connection *con, unsigned long con_flag)
 {
-	BUG_ON(!con_flag_valid(con_flag));
+	if (WARN_ON(!con_flag_valid(con_flag))) {
+		pr_warn("con_flag_set called with an invalid flag\n");
+		return;
+	}
 
 	set_bit(con_flag, &con->flags);
 }
 
 static bool con_flag_test(struct ceph_connection *con, unsigned long con_flag)
 {
-	BUG_ON(!con_flag_valid(con_flag));
+	if (WARN_ON(!con_flag_valid(con_flag))) {
+		pr_warn("con_flag_test called with an invalid flag\n");
+		return false;
+	}
 
 	return test_bit(con_flag, &con->flags);
 }
@@ -138,7 +147,10 @@ static bool con_flag_test(struct ceph_connection *con, unsigned long con_flag)
 static bool con_flag_test_and_clear(struct ceph_connection *con,
 					unsigned long con_flag)
 {
-	BUG_ON(!con_flag_valid(con_flag));
+	if (WARN_ON(!con_flag_valid(con_flag))) {
+		pr_warn("con_flag_test_and_clear called with an invalid flag\n");
+		return false;
+	}
 
 	return test_and_clear_bit(con_flag, &con->flags);
 }
@@ -146,7 +158,10 @@ static bool con_flag_test_and_clear(struct ceph_connection *con,
 static bool con_flag_test_and_set(struct ceph_connection *con,
 					unsigned long con_flag)
 {
-	BUG_ON(!con_flag_valid(con_flag));
+	if (WARN_ON(!con_flag_valid(con_flag))) {
+		pr_warn("con_flag_test_and_set called with an invalid flag\n");
+		return false;
+	}
 
 	return test_and_set_bit(con_flag, &con->flags);
 }
Signature · 1 line
2.6.4