From: Miche Baker-Harvey <miche@google.com>
To: ppc-dev <linuxppc-dev@lists.ozlabs.org>
Subject: [PATCH v2 2/3] hvc_init(): Enforce one-time initialization.
Date: Tue, 08 Nov 2011 11:30:17 -0800 [thread overview]
Message-ID: <20111108193016.30707.95497.stgit@miche.sea.corp.google.com> (raw)
In-Reply-To: <20111108193005.30707.23990.stgit@miche.sea.corp.google.com>
hvc_init() must only be called once, and no thread should continue with hvc_alloc()
until after initialization is complete. The original code does not enforce either
of these requirements. A new mutex limits entry to hvc_init() to a single thread,
and blocks all later comers until it has completed.
This patch fixes multiple crash symptoms.
Signed-off-by: Miche Baker-Harvey <miche@google.com>
---
drivers/tty/hvc/hvc_console.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index b6b2d18..09a6159 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -29,8 +29,9 @@
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/list.h>
-#include <linux/module.h>
#include <linux/major.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/sysrq.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
@@ -84,6 +85,10 @@ static LIST_HEAD(hvc_structs);
* list traversal.
*/
static DEFINE_SPINLOCK(hvc_structs_lock);
+/*
+ * only one task does allocation at a time.
+ */
+static DEFINE_MUTEX(hvc_ports_mutex);
/*
* This value is used to assign a tty->index value to a hvc_struct based
@@ -825,11 +830,15 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
int i;
/* We wait until a driver actually comes along */
+ mutex_lock(&hvc_ports_mutex);
if (!hvc_driver) {
int err = hvc_init();
- if (err)
+ if (err) {
+ mutex_unlock(&hvc_ports_mutex);
return ERR_PTR(err);
+ }
}
+ mutex_unlock(&hvc_ports_mutex);
hp = kzalloc(ALIGN(sizeof(*hp), sizeof(long)) + outbuf_size,
GFP_KERNEL);
next prev parent reply other threads:[~2011-11-08 19:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-08 19:30 [PATCH RFC v2 0/3] Support multiple VirtioConsoles Miche Baker-Harvey
2011-11-08 19:30 ` [PATCH v2 1/3] virtio_console: Fix locking of vtermno Miche Baker-Harvey
2011-11-08 19:30 ` Miche Baker-Harvey [this message]
2011-11-08 19:30 ` [PATCH v2 3/3] Use separate struct console structure for each hvc_console Miche Baker-Harvey
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=20111108193016.30707.95497.stgit@miche.sea.corp.google.com \
--to=miche@google.com \
--cc=linuxppc-dev@lists.ozlabs.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox