diff options
-rw-r--r-- | arch/x86_64/kernel/mce.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/arch/x86_64/kernel/mce.c b/arch/x86_64/kernel/mce.c index f3fb8174559e..77fee481be4f 100644 --- a/arch/x86_64/kernel/mce.c +++ b/arch/x86_64/kernel/mce.c | |||
@@ -465,6 +465,40 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c) | |||
465 | * Character device to read and clear the MCE log. | 465 | * Character device to read and clear the MCE log. |
466 | */ | 466 | */ |
467 | 467 | ||
468 | static DEFINE_SPINLOCK(mce_state_lock); | ||
469 | static int open_count; /* #times opened */ | ||
470 | static int open_exclu; /* already open exclusive? */ | ||
471 | |||
472 | static int mce_open(struct inode *inode, struct file *file) | ||
473 | { | ||
474 | spin_lock(&mce_state_lock); | ||
475 | |||
476 | if (open_exclu || (open_count && (file->f_flags & O_EXCL))) { | ||
477 | spin_unlock(&mce_state_lock); | ||
478 | return -EBUSY; | ||
479 | } | ||
480 | |||
481 | if (file->f_flags & O_EXCL) | ||
482 | open_exclu = 1; | ||
483 | open_count++; | ||
484 | |||
485 | spin_unlock(&mce_state_lock); | ||
486 | |||
487 | return 0; | ||
488 | } | ||
489 | |||
490 | static int mce_release(struct inode *inode, struct file *file) | ||
491 | { | ||
492 | spin_lock(&mce_state_lock); | ||
493 | |||
494 | open_count--; | ||
495 | open_exclu = 0; | ||
496 | |||
497 | spin_unlock(&mce_state_lock); | ||
498 | |||
499 | return 0; | ||
500 | } | ||
501 | |||
468 | static void collect_tscs(void *data) | 502 | static void collect_tscs(void *data) |
469 | { | 503 | { |
470 | unsigned long *cpu_tsc = (unsigned long *)data; | 504 | 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 | |||
555 | } | 589 | } |
556 | 590 | ||
557 | static const struct file_operations mce_chrdev_ops = { | 591 | static const struct file_operations mce_chrdev_ops = { |
592 | .open = mce_open, | ||
593 | .release = mce_release, | ||
558 | .read = mce_read, | 594 | .read = mce_read, |
559 | .ioctl = mce_ioctl, | 595 | .ioctl = mce_ioctl, |
560 | }; | 596 | }; |