diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2009-11-03 15:14:39 -0500 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2009-11-03 15:14:39 -0500 |
commit | 2058297d2d045cb57138c33b87cfabcc80e65186 (patch) | |
tree | 7ccffd0e162cbd7471f643561e79f23abb989a62 /drivers/oprofile/event_buffer.c | |
parent | 150e6c67f4bf6ab51e62defc41bd19a2eefe5709 (diff) | |
parent | 4b27e1bb442e964903f8a3fa6bdf33a602dc0941 (diff) |
Merge branch 'for-linus' into for-2.6.33
Conflicts:
block/cfq-iosched.c
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/oprofile/event_buffer.c')
-rw-r--r-- | drivers/oprofile/event_buffer.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c index 2b7ae366ceb1..5df60a6b6776 100644 --- a/drivers/oprofile/event_buffer.c +++ b/drivers/oprofile/event_buffer.c | |||
@@ -35,12 +35,23 @@ static size_t buffer_pos; | |||
35 | /* atomic_t because wait_event checks it outside of buffer_mutex */ | 35 | /* atomic_t because wait_event checks it outside of buffer_mutex */ |
36 | static atomic_t buffer_ready = ATOMIC_INIT(0); | 36 | static atomic_t buffer_ready = ATOMIC_INIT(0); |
37 | 37 | ||
38 | /* Add an entry to the event buffer. When we | 38 | /* |
39 | * get near to the end we wake up the process | 39 | * Add an entry to the event buffer. When we get near to the end we |
40 | * sleeping on the read() of the file. | 40 | * wake up the process sleeping on the read() of the file. To protect |
41 | * the event_buffer this function may only be called when buffer_mutex | ||
42 | * is set. | ||
41 | */ | 43 | */ |
42 | void add_event_entry(unsigned long value) | 44 | void add_event_entry(unsigned long value) |
43 | { | 45 | { |
46 | /* | ||
47 | * This shouldn't happen since all workqueues or handlers are | ||
48 | * canceled or flushed before the event buffer is freed. | ||
49 | */ | ||
50 | if (!event_buffer) { | ||
51 | WARN_ON_ONCE(1); | ||
52 | return; | ||
53 | } | ||
54 | |||
44 | if (buffer_pos == buffer_size) { | 55 | if (buffer_pos == buffer_size) { |
45 | atomic_inc(&oprofile_stats.event_lost_overflow); | 56 | atomic_inc(&oprofile_stats.event_lost_overflow); |
46 | return; | 57 | return; |
@@ -69,7 +80,6 @@ void wake_up_buffer_waiter(void) | |||
69 | 80 | ||
70 | int alloc_event_buffer(void) | 81 | int alloc_event_buffer(void) |
71 | { | 82 | { |
72 | int err = -ENOMEM; | ||
73 | unsigned long flags; | 83 | unsigned long flags; |
74 | 84 | ||
75 | spin_lock_irqsave(&oprofilefs_lock, flags); | 85 | spin_lock_irqsave(&oprofilefs_lock, flags); |
@@ -80,21 +90,22 @@ int alloc_event_buffer(void) | |||
80 | if (buffer_watershed >= buffer_size) | 90 | if (buffer_watershed >= buffer_size) |
81 | return -EINVAL; | 91 | return -EINVAL; |
82 | 92 | ||
93 | buffer_pos = 0; | ||
83 | event_buffer = vmalloc(sizeof(unsigned long) * buffer_size); | 94 | event_buffer = vmalloc(sizeof(unsigned long) * buffer_size); |
84 | if (!event_buffer) | 95 | if (!event_buffer) |
85 | goto out; | 96 | return -ENOMEM; |
86 | 97 | ||
87 | err = 0; | 98 | return 0; |
88 | out: | ||
89 | return err; | ||
90 | } | 99 | } |
91 | 100 | ||
92 | 101 | ||
93 | void free_event_buffer(void) | 102 | void free_event_buffer(void) |
94 | { | 103 | { |
104 | mutex_lock(&buffer_mutex); | ||
95 | vfree(event_buffer); | 105 | vfree(event_buffer); |
96 | 106 | buffer_pos = 0; | |
97 | event_buffer = NULL; | 107 | event_buffer = NULL; |
108 | mutex_unlock(&buffer_mutex); | ||
98 | } | 109 | } |
99 | 110 | ||
100 | 111 | ||
@@ -167,6 +178,12 @@ static ssize_t event_buffer_read(struct file *file, char __user *buf, | |||
167 | 178 | ||
168 | mutex_lock(&buffer_mutex); | 179 | mutex_lock(&buffer_mutex); |
169 | 180 | ||
181 | /* May happen if the buffer is freed during pending reads. */ | ||
182 | if (!event_buffer) { | ||
183 | retval = -EINTR; | ||
184 | goto out; | ||
185 | } | ||
186 | |||
170 | atomic_set(&buffer_ready, 0); | 187 | atomic_set(&buffer_ready, 0); |
171 | 188 | ||
172 | retval = -EFAULT; | 189 | retval = -EFAULT; |