All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] net: ceph: messenger: replace uses of BUG_ON() with WARN_ON()
@ 2016-01-27 12:52 Ioana Ciornei
  2016-01-27 12:52 ` [PATCH 1/2] net: ceph: messenger: change BUG_ON() to WARN_ON() from ceph_con_in_msg_alloc() Ioana Ciornei
  2016-01-27 12:52 ` [PATCH 2/2] net: ceph: messenger: replace BUG_ON() with WARN_ON() in con_flag_* functions Ioana Ciornei
  0 siblings, 2 replies; 3+ messages in thread
From: Ioana Ciornei @ 2016-01-27 12:52 UTC (permalink / raw)
  To: ceph-devel; +Cc: elder, Ioana Ciornei

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(-)

-- 
2.6.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] net: ceph: messenger: change BUG_ON() to WARN_ON() from ceph_con_in_msg_alloc()
  2016-01-27 12:52 [PATCH 0/2] net: ceph: messenger: replace uses of BUG_ON() with WARN_ON() Ioana Ciornei
@ 2016-01-27 12:52 ` Ioana Ciornei
  2016-01-27 12:52 ` [PATCH 2/2] net: ceph: messenger: replace BUG_ON() with WARN_ON() in con_flag_* functions Ioana Ciornei
  1 sibling, 0 replies; 3+ messages in thread
From: Ioana Ciornei @ 2016-01-27 12:52 UTC (permalink / raw)
  To: ceph-devel; +Cc: elder, Ioana Ciornei

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.

Signed-off-by: Ioana Ciornei <ciorneiioana@gmail.com>
---
 net/ceph/messenger.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 9cfedf5..9a5e54c 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -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 {
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] net: ceph: messenger: replace BUG_ON() with WARN_ON() in con_flag_* functions
  2016-01-27 12:52 [PATCH 0/2] net: ceph: messenger: replace uses of BUG_ON() with WARN_ON() Ioana Ciornei
  2016-01-27 12:52 ` [PATCH 1/2] net: ceph: messenger: change BUG_ON() to WARN_ON() from ceph_con_in_msg_alloc() Ioana Ciornei
@ 2016-01-27 12:52 ` Ioana Ciornei
  1 sibling, 0 replies; 3+ messages in thread
From: Ioana Ciornei @ 2016-01-27 12:52 UTC (permalink / raw)
  To: ceph-devel; +Cc: elder, 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.

Signed-off-by: Ioana Ciornei <ciorneiioana@gmail.com>
---
 net/ceph/messenger.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 9a5e54c..1e5aac6 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -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);
 }
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-27 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-27 12:52 [PATCH 0/2] net: ceph: messenger: replace uses of BUG_ON() with WARN_ON() Ioana Ciornei
2016-01-27 12:52 ` [PATCH 1/2] net: ceph: messenger: change BUG_ON() to WARN_ON() from ceph_con_in_msg_alloc() Ioana Ciornei
2016-01-27 12:52 ` [PATCH 2/2] net: ceph: messenger: replace BUG_ON() with WARN_ON() in con_flag_* functions Ioana Ciornei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.