aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/nvram.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/nvram.c')
-rw-r--r--drivers/char/nvram.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 88cee4099be9..47e8f7b0e4c1 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -38,7 +38,6 @@
38#define NVRAM_VERSION "1.3" 38#define NVRAM_VERSION "1.3"
39 39
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/smp_lock.h>
42#include <linux/nvram.h> 41#include <linux/nvram.h>
43 42
44#define PC 1 43#define PC 1
@@ -101,7 +100,6 @@
101#include <linux/types.h> 100#include <linux/types.h>
102#include <linux/errno.h> 101#include <linux/errno.h>
103#include <linux/miscdevice.h> 102#include <linux/miscdevice.h>
104#include <linux/slab.h>
105#include <linux/ioport.h> 103#include <linux/ioport.h>
106#include <linux/fcntl.h> 104#include <linux/fcntl.h>
107#include <linux/mc146818rtc.h> 105#include <linux/mc146818rtc.h>
@@ -111,6 +109,7 @@
111#include <linux/spinlock.h> 109#include <linux/spinlock.h>
112#include <linux/io.h> 110#include <linux/io.h>
113#include <linux/uaccess.h> 111#include <linux/uaccess.h>
112#include <linux/smp_lock.h>
114 113
115#include <asm/system.h> 114#include <asm/system.h>
116 115
@@ -214,7 +213,6 @@ void nvram_set_checksum(void)
214 213
215static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 214static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
216{ 215{
217 lock_kernel();
218 switch (origin) { 216 switch (origin) {
219 case 0: 217 case 0:
220 /* nothing to do */ 218 /* nothing to do */
@@ -226,7 +224,7 @@ static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
226 offset += NVRAM_BYTES; 224 offset += NVRAM_BYTES;
227 break; 225 break;
228 } 226 }
229 unlock_kernel(); 227
230 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL; 228 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
231} 229}
232 230
@@ -265,10 +263,16 @@ static ssize_t nvram_write(struct file *file, const char __user *buf,
265 unsigned char contents[NVRAM_BYTES]; 263 unsigned char contents[NVRAM_BYTES];
266 unsigned i = *ppos; 264 unsigned i = *ppos;
267 unsigned char *tmp; 265 unsigned char *tmp;
268 int len;
269 266
270 len = (NVRAM_BYTES - i) < count ? (NVRAM_BYTES - i) : count; 267 if (i >= NVRAM_BYTES)
271 if (copy_from_user(contents, buf, len)) 268 return 0; /* Past EOF */
269
270 if (count > NVRAM_BYTES - i)
271 count = NVRAM_BYTES - i;
272 if (count > NVRAM_BYTES)
273 return -EFAULT; /* Can't happen, but prove it to gcc */
274
275 if (copy_from_user(contents, buf, count))
272 return -EFAULT; 276 return -EFAULT;
273 277
274 spin_lock_irq(&rtc_lock); 278 spin_lock_irq(&rtc_lock);
@@ -276,7 +280,7 @@ static ssize_t nvram_write(struct file *file, const char __user *buf,
276 if (!__nvram_check_checksum()) 280 if (!__nvram_check_checksum())
277 goto checksum_err; 281 goto checksum_err;
278 282
279 for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp) 283 for (tmp = contents; count--; ++i, ++tmp)
280 __nvram_write_byte(*tmp, i); 284 __nvram_write_byte(*tmp, i);
281 285
282 __nvram_set_checksum(); 286 __nvram_set_checksum();
@@ -331,14 +335,12 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
331 335
332static int nvram_open(struct inode *inode, struct file *file) 336static int nvram_open(struct inode *inode, struct file *file)
333{ 337{
334 lock_kernel();
335 spin_lock(&nvram_state_lock); 338 spin_lock(&nvram_state_lock);
336 339
337 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || 340 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
338 (nvram_open_mode & NVRAM_EXCL) || 341 (nvram_open_mode & NVRAM_EXCL) ||
339 ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) { 342 ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) {
340 spin_unlock(&nvram_state_lock); 343 spin_unlock(&nvram_state_lock);
341 unlock_kernel();
342 return -EBUSY; 344 return -EBUSY;
343 } 345 }
344 346
@@ -349,7 +351,6 @@ static int nvram_open(struct inode *inode, struct file *file)
349 nvram_open_cnt++; 351 nvram_open_cnt++;
350 352
351 spin_unlock(&nvram_state_lock); 353 spin_unlock(&nvram_state_lock);
352 unlock_kernel();
353 354
354 return 0; 355 return 0;
355} 356}