diff options
Diffstat (limited to 'drivers/char/nvram.c')
-rw-r--r-- | drivers/char/nvram.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index 88cee4099be9..5eb83c3ca20d 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 |
@@ -111,6 +110,7 @@ | |||
111 | #include <linux/spinlock.h> | 110 | #include <linux/spinlock.h> |
112 | #include <linux/io.h> | 111 | #include <linux/io.h> |
113 | #include <linux/uaccess.h> | 112 | #include <linux/uaccess.h> |
113 | #include <linux/smp_lock.h> | ||
114 | 114 | ||
115 | #include <asm/system.h> | 115 | #include <asm/system.h> |
116 | 116 | ||
@@ -214,7 +214,6 @@ void nvram_set_checksum(void) | |||
214 | 214 | ||
215 | static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) | 215 | static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) |
216 | { | 216 | { |
217 | lock_kernel(); | ||
218 | switch (origin) { | 217 | switch (origin) { |
219 | case 0: | 218 | case 0: |
220 | /* nothing to do */ | 219 | /* nothing to do */ |
@@ -226,7 +225,7 @@ static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) | |||
226 | offset += NVRAM_BYTES; | 225 | offset += NVRAM_BYTES; |
227 | break; | 226 | break; |
228 | } | 227 | } |
229 | unlock_kernel(); | 228 | |
230 | return (offset >= 0) ? (file->f_pos = offset) : -EINVAL; | 229 | return (offset >= 0) ? (file->f_pos = offset) : -EINVAL; |
231 | } | 230 | } |
232 | 231 | ||
@@ -265,10 +264,16 @@ static ssize_t nvram_write(struct file *file, const char __user *buf, | |||
265 | unsigned char contents[NVRAM_BYTES]; | 264 | unsigned char contents[NVRAM_BYTES]; |
266 | unsigned i = *ppos; | 265 | unsigned i = *ppos; |
267 | unsigned char *tmp; | 266 | unsigned char *tmp; |
268 | int len; | ||
269 | 267 | ||
270 | len = (NVRAM_BYTES - i) < count ? (NVRAM_BYTES - i) : count; | 268 | if (i >= NVRAM_BYTES) |
271 | if (copy_from_user(contents, buf, len)) | 269 | return 0; /* Past EOF */ |
270 | |||
271 | if (count > NVRAM_BYTES - i) | ||
272 | count = NVRAM_BYTES - i; | ||
273 | if (count > NVRAM_BYTES) | ||
274 | return -EFAULT; /* Can't happen, but prove it to gcc */ | ||
275 | |||
276 | if (copy_from_user(contents, buf, count)) | ||
272 | return -EFAULT; | 277 | return -EFAULT; |
273 | 278 | ||
274 | spin_lock_irq(&rtc_lock); | 279 | spin_lock_irq(&rtc_lock); |
@@ -276,7 +281,7 @@ static ssize_t nvram_write(struct file *file, const char __user *buf, | |||
276 | if (!__nvram_check_checksum()) | 281 | if (!__nvram_check_checksum()) |
277 | goto checksum_err; | 282 | goto checksum_err; |
278 | 283 | ||
279 | for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp) | 284 | for (tmp = contents; count--; ++i, ++tmp) |
280 | __nvram_write_byte(*tmp, i); | 285 | __nvram_write_byte(*tmp, i); |
281 | 286 | ||
282 | __nvram_set_checksum(); | 287 | __nvram_set_checksum(); |
@@ -331,14 +336,12 @@ static int nvram_ioctl(struct inode *inode, struct file *file, | |||
331 | 336 | ||
332 | static int nvram_open(struct inode *inode, struct file *file) | 337 | static int nvram_open(struct inode *inode, struct file *file) |
333 | { | 338 | { |
334 | lock_kernel(); | ||
335 | spin_lock(&nvram_state_lock); | 339 | spin_lock(&nvram_state_lock); |
336 | 340 | ||
337 | if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || | 341 | if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || |
338 | (nvram_open_mode & NVRAM_EXCL) || | 342 | (nvram_open_mode & NVRAM_EXCL) || |
339 | ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) { | 343 | ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) { |
340 | spin_unlock(&nvram_state_lock); | 344 | spin_unlock(&nvram_state_lock); |
341 | unlock_kernel(); | ||
342 | return -EBUSY; | 345 | return -EBUSY; |
343 | } | 346 | } |
344 | 347 | ||
@@ -349,7 +352,6 @@ static int nvram_open(struct inode *inode, struct file *file) | |||
349 | nvram_open_cnt++; | 352 | nvram_open_cnt++; |
350 | 353 | ||
351 | spin_unlock(&nvram_state_lock); | 354 | spin_unlock(&nvram_state_lock); |
352 | unlock_kernel(); | ||
353 | 355 | ||
354 | return 0; | 356 | return 0; |
355 | } | 357 | } |