patch-2.2.18 linux/drivers/char/nvram.c
Next file: linux/drivers/char/pc_keyb.c
Previous file: linux/drivers/char/n_hdlc.c
Back to the patch index
Back to the overall index
- Lines: 146
- Date:
Wed Nov 1 16:54:42 2000
- Orig file:
v2.2.17/drivers/char/nvram.c
- Orig date:
Sun Jun 11 21:44:13 2000
diff -u --new-file --recursive --exclude-from /usr/src/exclude v2.2.17/drivers/char/nvram.c linux/drivers/char/nvram.c
@@ -25,9 +25,10 @@
* the kernel and is not a module. Since the functions are used by some Atari
* drivers, this is the case on the Atari.
*
+ * 1.0a Paul Gortmaker: use rtc_lock, fix get/put_user in cli bugs.
*/
-#define NVRAM_VERSION "1.0"
+#define NVRAM_VERSION "1.0a"
#include <linux/module.h>
#include <linux/config.h>
@@ -78,10 +79,12 @@
#define mach_set_checksum atari_set_checksum
#define mach_proc_infos atari_proc_infos
+static spinlock_t rtc_lock; /* optimized away; no SMP m68K */
+
#endif
/* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
- * interrupts disabled. Due to the index-port/data-port design of the RTC, we
+ * rtc_lock held. Due to the index-port/data-port design of the RTC, we
* don't want two different things trying to get to it at once. (e.g. the
* periodic 11 min sync from time.c vs. this driver.)
*/
@@ -233,23 +236,28 @@
unsigned long flags;
unsigned i = *ppos;
char *tmp = buf;
+ int checksum;
if (i != *ppos)
return -EINVAL;
- save_flags(flags);
- cli();
-
- if (!nvram_check_checksum_int()) {
- restore_flags(flags);
+ spin_lock_irqsave(&rtc_lock, flags);
+ checksum = nvram_check_checksum_int();
+ spin_unlock_irqrestore(&rtc_lock, flags);
+
+ if (!checksum)
return( -EIO );
- }
for( ; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp )
- put_user( nvram_read_int(i), tmp );
+ {
+ int val;
+ spin_lock_irqsave(&rtc_lock, flags);
+ val = nvram_read_int(i);
+ spin_unlock_irqrestore(&rtc_lock, flags);
+ put_user( val, tmp );
+ }
*ppos = i;
- restore_flags(flags);
return( tmp - buf );
}
@@ -260,26 +268,31 @@
unsigned i = *ppos;
const char *tmp = buf;
char c;
+ int checksum;
if (i != *ppos)
return -EINVAL;
- save_flags(flags);
- cli();
-
- if (!nvram_check_checksum_int()) {
- restore_flags(flags);
+ spin_lock_irqsave(&rtc_lock, flags);
+ checksum = nvram_check_checksum_int();
+ spin_unlock_irqrestore(&rtc_lock, flags);
+
+ if (!checksum)
return( -EIO );
- }
for( ; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp ) {
get_user( c, tmp );
+ spin_lock_irqsave(&rtc_lock, flags);
nvram_write_int( c, i );
+ spin_unlock_irqrestore(&rtc_lock, flags);
}
+
+ spin_lock_irqsave(&rtc_lock, flags);
nvram_set_checksum_int();
+ spin_unlock_irqrestore(&rtc_lock, flags);
+
*ppos = i;
- restore_flags(flags);
return( tmp - buf );
}
@@ -295,14 +308,13 @@
if (!capable(CAP_SYS_ADMIN))
return( -EACCES );
- save_flags(flags);
- cli();
+ spin_lock_irqsave(&rtc_lock, flags);
for( i = 0; i < NVRAM_BYTES; ++i )
nvram_write_int( 0, i );
nvram_set_checksum_int();
- restore_flags(flags);
+ spin_unlock_irqrestore(&rtc_lock, flags);
return( 0 );
case NVRAM_SETCKS: /* just set checksum, contents unchanged
@@ -311,10 +323,9 @@
if (!capable(CAP_SYS_ADMIN))
return( -EACCES );
- save_flags(flags);
- cli();
+ spin_lock_irqsave(&rtc_lock, flags);
nvram_set_checksum_int();
- restore_flags(flags);
+ spin_unlock_irqrestore(&rtc_lock, flags);
return( 0 );
default:
@@ -363,11 +374,10 @@
int i, len = 0;
off_t begin = 0;
- save_flags(flags);
- cli();
+ spin_lock_irqsave(&rtc_lock, flags);
for( i = 0; i < NVRAM_BYTES; ++i )
contents[i] = nvram_read_int( i );
- restore_flags(flags);
+ spin_unlock_irqrestore(&rtc_lock, flags);
*eof = mach_proc_infos( contents, buffer, &len, &begin, offset, size );
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)