X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=arch%2Falpha%2Fkernel%2Fsrmcons.c;h=3b30d4f1fc42d5d438082b82f20a3dee5acad56e;hb=f7f1b0f1e2fbadeab12d24236000e778aa9b1ead;hp=1a9b4c64593505971a5472583117d990d97773f5;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c index 1a9b4c645..3b30d4f1f 100644 --- a/arch/alpha/kernel/srmcons.c +++ b/arch/alpha/kernel/srmcons.c @@ -22,7 +22,7 @@ #include -static spinlock_t srmcons_callback_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(srmcons_callback_lock); static int srm_is_registered_console = 0; /* @@ -91,15 +91,15 @@ srmcons_receive_chars(unsigned long data) /* called with callback_lock held */ static int -srmcons_do_write(struct tty_struct *tty, const unsigned char *buf, int count) +srmcons_do_write(struct tty_struct *tty, const char *buf, int count) { - unsigned char *str_cr = "\r"; + static char str_cr[1] = "\r"; long c, remaining = count; srmcons_result result; - unsigned char *cur; + char *cur; int need_cr; - for (cur = (unsigned char *)buf; remaining > 0; ) { + for (cur = (char *)buf; remaining > 0; ) { need_cr = 0; /* * Break it up into reasonable size chunks to allow a chance @@ -132,42 +132,13 @@ srmcons_do_write(struct tty_struct *tty, const unsigned char *buf, int count) } static int -srmcons_write(struct tty_struct *tty, int from_user, +srmcons_write(struct tty_struct *tty, const unsigned char *buf, int count) { unsigned long flags; - if (from_user) { - unsigned char tmp[512]; - int ret = 0; - size_t c; - - while ((c = count) > 0) { - if (c > sizeof(tmp)) - c = sizeof(tmp); - - c -= copy_from_user(tmp, buf, c); - - if (!c) { - printk("%s: EFAULT (count %d)\n", - __FUNCTION__, count); - return -EFAULT; - } - - spin_lock_irqsave(&srmcons_callback_lock, flags); - srmcons_do_write(tty, tmp, c); - spin_unlock_irqrestore(&srmcons_callback_lock, flags); - - buf += c; - count -= c; - ret += c; - } - - return ret; - } - spin_lock_irqsave(&srmcons_callback_lock, flags); - srmcons_do_write(tty, buf, count); + srmcons_do_write(tty, (const char *) buf, count); spin_unlock_irqrestore(&srmcons_callback_lock, flags); return count; @@ -189,33 +160,26 @@ static int srmcons_get_private_struct(struct srmcons_private **ps) { static struct srmcons_private *srmconsp = NULL; - static spinlock_t srmconsp_lock = SPIN_LOCK_UNLOCKED; + static DEFINE_SPINLOCK(srmconsp_lock); unsigned long flags; int retval = 0; - spin_lock_irqsave(&srmconsp_lock, flags); - - do { - if (srmconsp != NULL) { - *ps = srmconsp; - break; - } + if (srmconsp == NULL) { + spin_lock_irqsave(&srmconsp_lock, flags); srmconsp = kmalloc(sizeof(*srmconsp), GFP_KERNEL); - if (srmconsp == NULL) { + if (srmconsp == NULL) retval = -ENOMEM; - break; + else { + srmconsp->tty = NULL; + spin_lock_init(&srmconsp->lock); + init_timer(&srmconsp->timer); } - srmconsp->tty = NULL; - srmconsp->lock = SPIN_LOCK_UNLOCKED; - init_timer(&srmconsp->timer); - - *ps = srmconsp; - } while(0); - - spin_unlock_irqrestore(&srmconsp_lock, flags); + spin_unlock_irqrestore(&srmconsp_lock, flags); + } + *ps = srmconsp; return retval; }