From 5a544405fc62e362308642a872a627be3be9d997 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 21 Jul 2007 17:10:35 +0200 Subject: [PATCH] --- yaml --- r: 62391 b: refs/heads/master c: f528e7ba28492e363a64c80c414ded4cadf48f89 h: refs/heads/master i: 62389: 37ebdb960b897a5817eeba2de73c2162c78e719b 62387: 55d5e50e5df2b75c4e9d3978d029b33597faea0d 62383: 66461cfbd9b476979c97195855f0f4d1fb1c213c v: v3 --- [refs] | 2 +- trunk/arch/x86_64/kernel/mce.c | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 232f55ab1e51..0d7a0c5eeefc 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: a5ba7971045a90a36cef8f7d5a3075600b475b74 +refs/heads/master: f528e7ba28492e363a64c80c414ded4cadf48f89 diff --git a/trunk/arch/x86_64/kernel/mce.c b/trunk/arch/x86_64/kernel/mce.c index f3fb8174559e..77fee481be4f 100644 --- a/trunk/arch/x86_64/kernel/mce.c +++ b/trunk/arch/x86_64/kernel/mce.c @@ -465,6 +465,40 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c) * Character device to read and clear the MCE log. */ +static DEFINE_SPINLOCK(mce_state_lock); +static int open_count; /* #times opened */ +static int open_exclu; /* already open exclusive? */ + +static int mce_open(struct inode *inode, struct file *file) +{ + spin_lock(&mce_state_lock); + + if (open_exclu || (open_count && (file->f_flags & O_EXCL))) { + spin_unlock(&mce_state_lock); + return -EBUSY; + } + + if (file->f_flags & O_EXCL) + open_exclu = 1; + open_count++; + + spin_unlock(&mce_state_lock); + + return 0; +} + +static int mce_release(struct inode *inode, struct file *file) +{ + spin_lock(&mce_state_lock); + + open_count--; + open_exclu = 0; + + spin_unlock(&mce_state_lock); + + return 0; +} + static void collect_tscs(void *data) { unsigned long *cpu_tsc = (unsigned long *)data; @@ -555,6 +589,8 @@ static int mce_ioctl(struct inode *i, struct file *f,unsigned int cmd, unsigned } static const struct file_operations mce_chrdev_ops = { + .open = mce_open, + .release = mce_release, .read = mce_read, .ioctl = mce_ioctl, };