All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: Andrew Morton <akpm@osdl.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH 3/6] Char: stallion, brd struct locking
Date: Sat,  4 Nov 2006 18:26:39 +0100 (CET)	[thread overview]
Message-ID: <419597213138451@wsc.cz> (raw)

stallion, brd struct locking

Since assigning of stl_brds[brdnr] is racy, add locking to this critical
section.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 35d35cadc88b0f52cc4824fafc6a16f3c9301ef0
tree 4338edc3bf9671b1fafc18413cc08d3e631c7073
parent 47b4f5a42e198be7c2cf3606cf2681c04a42b197
author Jiri Slaby <jirislaby@gmail.com> Thu, 02 Nov 2006 19:31:31 +0100
committer Jiri Slaby <jirislaby@gmail.com> Thu, 02 Nov 2006 19:31:31 +0100

 drivers/char/stallion.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 048d2b0..072a226 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -136,6 +136,7 @@ static char		stl_unwanted[SC26198_RXFIFO
 
 /*****************************************************************************/
 
+static DEFINE_MUTEX(stl_brdslock);
 static struct stlbrd		*stl_brds[STL_MAXBRDS];
 
 /*
@@ -2305,7 +2306,6 @@ static int __devinit stl_brdinit(struct 
 		goto err;
 	}
 
-	stl_brds[brdp->brdnr] = brdp;
 	if ((brdp->state & BRD_FOUND) == 0) {
 		printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
 			stl_brdnames[brdp->brdtype], brdp->brdnr,
@@ -2331,8 +2331,6 @@ err_free:
 	release_region(brdp->ioaddr1, brdp->iosize1);
 	if (brdp->iosize2 > 0)
 		release_region(brdp->ioaddr2, brdp->iosize2);
-
-	stl_brds[brdp->brdnr] = NULL;
 err:
 	return retval;
 }
@@ -2385,12 +2383,17 @@ static int __devinit stl_pciprobe(struct
 		retval = -ENOMEM;
 		goto err;
 	}
+	mutex_lock(&stl_brdslock);
 	brdp->brdnr = stl_getbrdnr();
 	if (brdp->brdnr < 0) {
 		dev_err(&pdev->dev, "too many boards found, "
 			"maximum supported %d\n", STL_MAXBRDS);
+		mutex_unlock(&stl_brdslock);
 		goto err_fr;
 	}
+	stl_brds[brdp->brdnr] = brdp;
+	mutex_unlock(&stl_brdslock);
+
 	brdp->brdtype = brdtype;
 	brdp->state |= STL_PROBED;
 
@@ -2419,11 +2422,13 @@ static int __devinit stl_pciprobe(struct
 	brdp->irq = pdev->irq;
 	retval = stl_brdinit(brdp);
 	if (retval)
-		goto err_fr;
+		goto err_null;
 
 	pci_set_drvdata(pdev, brdp);
 
 	return 0;
+err_null:
+	stl_brds[brdp->brdnr] = NULL;
 err_fr:
 	kfree(brdp);
 err:
@@ -4737,10 +4742,13 @@ static int __init stallion_module_init(v
 		brdp->irqtype = conf.irqtype;
 		if (stl_brdinit(brdp))
 			kfree(brdp);
-		else
+		else {
+			stl_brds[brdp->brdnr] = brdp;
 			stl_nrbrds = i + 1;
+		}
 	}
 
+	/* this has to be _after_ isa finding because of locking */
 	retval = pci_register_driver(&stl_pcidriver);
 	if (retval && stl_nrbrds == 0)
 		goto err;

                 reply	other threads:[~2006-11-04 17:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=419597213138451@wsc.cz \
    --to=jirislaby@gmail.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.