All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 1/4] cnic: Fix occasional NULL pointer dereference during reboot.
@ 2012-06-28  1:08 Michael Chan
  2012-06-28  1:08 ` [PATCH net-next 2/4] cnic: Read bnx2x function number from internal register Michael Chan
  2012-06-28  4:28 ` [PATCH net-next 1/4] cnic: Fix occasional NULL pointer dereference during reboot David Miller
  0 siblings, 2 replies; 12+ messages in thread
From: Michael Chan @ 2012-06-28  1:08 UTC (permalink / raw)
  To: davem; +Cc: netdev

We register with bnx2x before we allocate ctx_tbl structure, so it is
possible for bnx2x to call cnic_ctl before the structure is allocated.
This can sometimes cause NULL pointer dereference of cp->ctx_tbl.  We
fix this by adding simple checking for valid state before proceeding.
The cnic_ctl call is RCU protected so we don't have to deal with race
conditions.

Because of the additional checking, we need to finish the shutdown
before clearing the CNIC_UP flag.

Signed-off-by: Michael Chan <mchan@broadcom.com>
---
 drivers/net/ethernet/broadcom/cnic.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/cnic.c b/drivers/net/ethernet/broadcom/cnic.c
index 0e9be2b..31b05ad 100644
--- a/drivers/net/ethernet/broadcom/cnic.c
+++ b/drivers/net/ethernet/broadcom/cnic.c
@@ -291,6 +291,9 @@ static int cnic_get_l5_cid(struct cnic_local *cp, u32 cid, u32 *l5_cid)
 {
 	u32 i;
 
+	if (!cp->ctx_tbl)
+		return -EINVAL;
+
 	for (i = 0; i < cp->max_cid_space; i++) {
 		if (cp->ctx_tbl[i].cid == cid) {
 			*l5_cid = i;
@@ -3220,6 +3223,9 @@ static int cnic_ctl(void *data, struct cnic_ctl_info *info)
 		u32 l5_cid;
 		struct cnic_local *cp = dev->cnic_priv;
 
+		if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
+			break;
+
 		if (cnic_get_l5_cid(cp, cid, &l5_cid) == 0) {
 			struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
 
@@ -4253,8 +4259,6 @@ static int cnic_cm_shutdown(struct cnic_dev *dev)
 	struct cnic_local *cp = dev->cnic_priv;
 	int i;
 
-	cp->stop_cm(dev);
-
 	if (!cp->csk_tbl)
 		return 0;
 
@@ -5290,6 +5294,7 @@ static void cnic_stop_hw(struct cnic_dev *dev)
 			i++;
 		}
 		cnic_shutdown_rings(dev);
+		cp->stop_cm(dev);
 		clear_bit(CNIC_F_CNIC_UP, &dev->flags);
 		RCU_INIT_POINTER(cp->ulp_ops[CNIC_ULP_L4], NULL);
 		synchronize_rcu();
-- 
1.7.1

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

end of thread, other threads:[~2012-06-28  4:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-28  1:08 [PATCH net-next 1/4] cnic: Fix occasional NULL pointer dereference during reboot Michael Chan
2012-06-28  1:08 ` [PATCH net-next 2/4] cnic: Read bnx2x function number from internal register Michael Chan
2012-06-28  1:08   ` [PATCH net-next 3/4] cnic: Remove uio mem[0] Michael Chan
2012-06-28  1:08     ` [PATCH net-next 4/4] cnic: Handle RAMROD_CMD_ID_CLOSE error Michael Chan
2012-06-28  1:08       ` [PATCH net-next 1/2] bnx2: Add "fall through" comments Michael Chan
2012-06-28  1:08         ` [PATCH net-next 2/2] bnx2: Add missing netif_tx_disable() in bnx2_close() Michael Chan
2012-06-28  4:28           ` David Miller
2012-06-28  4:28         ` [PATCH net-next 1/2] bnx2: Add "fall through" comments David Miller
2012-06-28  4:29       ` [PATCH net-next 4/4] cnic: Handle RAMROD_CMD_ID_CLOSE error David Miller
2012-06-28  4:29     ` [PATCH net-next 3/4] cnic: Remove uio mem[0] David Miller
2012-06-28  4:28   ` [PATCH net-next 2/4] cnic: Read bnx2x function number from internal register David Miller
2012-06-28  4:28 ` [PATCH net-next 1/4] cnic: Fix occasional NULL pointer dereference during reboot David Miller

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.