#define NVRAM_VERSION "1.3"
#include <linux/module.h>
- #include <linux/smp_lock.h>
#include <linux/nvram.h>
#define PC 1
#include <linux/spinlock.h>
#include <linux/io.h>
#include <linux/uaccess.h>
+ +#include <linux/smp_lock.h>
#include <asm/system.h>
static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
{
- lock_kernel();
switch (origin) {
case 0:
/* nothing to do */
offset += NVRAM_BYTES;
break;
}
- unlock_kernel();
+
return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
}
unsigned char contents[NVRAM_BYTES];
unsigned i = *ppos;
unsigned char *tmp;
- - int len;
- - len = (NVRAM_BYTES - i) < count ? (NVRAM_BYTES - i) : count;
- - if (copy_from_user(contents, buf, len))
+ + if (i >= NVRAM_BYTES)
+ + return 0; /* Past EOF */
+ +
+ + if (count > NVRAM_BYTES - i)
+ + count = NVRAM_BYTES - i;
+ + if (count > NVRAM_BYTES)
+ + return -EFAULT; /* Can't happen, but prove it to gcc */
+ +
+ + if (copy_from_user(contents, buf, count))
return -EFAULT;
spin_lock_irq(&rtc_lock);
if (!__nvram_check_checksum())
goto checksum_err;
- - for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
+ + for (tmp = contents; count--; ++i, ++tmp)
__nvram_write_byte(*tmp, i);
__nvram_set_checksum();
static int nvram_open(struct inode *inode, struct file *file)
{
--- lock_kernel();
spin_lock(&nvram_state_lock);
if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
(nvram_open_mode & NVRAM_EXCL) ||
((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) {
spin_unlock(&nvram_state_lock);
--- unlock_kernel();
return -EBUSY;
}
nvram_open_cnt++;
spin_unlock(&nvram_state_lock);
--- unlock_kernel();
return 0;
}