[PATCH 1/2] proc/insterrupts: make it cpu hotplug safe

From: Yong Zhang
Date: Wed Jul 27 2011 - 00:56:39 EST


KOSAKI Motonhiro noticed that the reader of /proc/interrupts
could be preempted by cpu hotplug, thus the reader can get
broken result due to show_interrupts() iterate every online
cpu without any protection.

Signed-off-by: Yong Zhang <yong.zhang0@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Keika Kobayashi <kobayashi.kk@xxxxxxxxxxxxxx>
Cc: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx>
Cc: Heiko Carstens <heiko.carstens@xxxxxxxxxx>
---
fs/proc/interrupts.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
index 05029c0..d5642a6 100644
--- a/fs/proc/interrupts.c
+++ b/fs/proc/interrupts.c
@@ -4,6 +4,7 @@
#include <linux/irqnr.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
+#include <linux/cpu.h>

/*
* /proc/interrupts
@@ -35,14 +36,21 @@ static const struct seq_operations int_seq_ops = {

static int interrupts_open(struct inode *inode, struct file *filp)
{
+ get_online_cpus();
return seq_open(filp, &int_seq_ops);
}

+static int interrupts_release(struct inode *inode, struct file *filp)
+{
+ put_online_cpus();
+ return seq_release(inode, filp);
+}
+
static const struct file_operations proc_interrupts_operations = {
.open = interrupts_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = seq_release,
+ .release = interrupts_release,
};

static int __init proc_interrupts_init(void)
--
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/