From 1b86fda9adf1b691a76f8ceddfc59d0c8386257c Mon Sep 17 00:00:00 2001 From: Ed Cashin Date: Thu, 4 Oct 2012 17:16:34 -0700 Subject: [PATCH] aoe: increase net_device reference count while using it This change eliminates the danger that the user could rmmod the driver for a network interface that is being used for AoE by the aoe driver. Signed-off-by: Ed Cashin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/aoe/aoecmd.c | 4 ++++ drivers/block/aoe/aoedev.c | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c index cc692fee7ce1..2f19b9bba913 100644 --- a/drivers/block/aoe/aoecmd.c +++ b/drivers/block/aoe/aoecmd.c @@ -494,12 +494,15 @@ static void ejectif(struct aoetgt *t, struct aoeif *ifp) { struct aoeif *e; + struct net_device *nd; ulong n; + nd = ifp->nd; e = t->ifs + NAOEIFS - 1; n = (e - ifp) * sizeof *ifp; memmove(ifp, ifp+1, n); e->nd = NULL; + dev_put(nd); } static int @@ -1317,6 +1320,7 @@ setifbcnt(struct aoetgt *t, struct net_device *nd, int bcnt) pr_err("aoe: device setifbcnt failure; too many interfaces.\n"); return; } + dev_hold(nd); p->nd = nd; p->bcnt = bcnt; } diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c index 3968fe6c0077..6be7b3858340 100644 --- a/drivers/block/aoe/aoedev.c +++ b/drivers/block/aoe/aoedev.c @@ -295,6 +295,13 @@ freetgt(struct aoedev *d, struct aoetgt *t) { struct frame *f; struct list_head *pos, *nx, *head; + struct aoeif *ifp; + + for (ifp = t->ifs; ifp < &t->ifs[NAOEIFS]; ++ifp) { + if (!ifp->nd) + break; + dev_put(ifp->nd); + } head = &t->ffree; list_for_each_safe(pos, nx, head) { -- 2.20.1