ia64/xen-unstable

changeset 11884:9943e06e966e

[LINUX] Eliminate microcode driver's dependency on sys_m{,un}lock as
well as the needless use of static variables.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kfraser@localhost.localdomain
date Wed Oct 18 17:41:36 2006 +0100 (2006-10-18)
parents 7f861cd3d0c3
children 4d1b44450bdb
files linux-2.6-xen-sparse/arch/i386/kernel/microcode-xen.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/microcode-xen.c	Wed Oct 18 17:39:52 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/microcode-xen.c	Wed Oct 18 17:41:36 2006 +0100
     1.3 @@ -50,9 +50,6 @@ MODULE_LICENSE("GPL");
     1.4  
     1.5  /* no concurrent ->write()s are allowed on /dev/cpu/microcode */
     1.6  static DECLARE_MUTEX(microcode_sem);
     1.7 -
     1.8 -static void __user *user_buffer;	/* user area microcode data buffer */
     1.9 -static unsigned int user_buffer_size;	/* it's size */
    1.10  				
    1.11  static int microcode_open (struct inode *unused1, struct file *unused2)
    1.12  {
    1.13 @@ -60,21 +57,26 @@ static int microcode_open (struct inode 
    1.14  }
    1.15  
    1.16  
    1.17 -static int do_microcode_update (void)
    1.18 +static int do_microcode_update (const void __user *ubuf, size_t len)
    1.19  {
    1.20  	int err;
    1.21 -	dom0_op_t op;
    1.22 +	void *kbuf;
    1.23  
    1.24 -	err = sys_mlock((unsigned long)user_buffer, user_buffer_size);
    1.25 -	if (err != 0)
    1.26 -		return err;
    1.27 +	kbuf = vmalloc(len);
    1.28 +	if (!kbuf)
    1.29 +		return -ENOMEM;
    1.30 +
    1.31 +	if (copy_from_user(kbuf, ubuf, len) == 0) {
    1.32 +		dom0_op_t op;
    1.33  
    1.34 -	op.cmd = DOM0_MICROCODE;
    1.35 -	set_xen_guest_handle(op.u.microcode.data, user_buffer);
    1.36 -	op.u.microcode.length = user_buffer_size;
    1.37 -	err = HYPERVISOR_dom0_op(&op);
    1.38 +		op.cmd = DOM0_MICROCODE;
    1.39 +		set_xen_guest_handle(op.u.microcode.data, kbuf);
    1.40 +		op.u.microcode.length = len;
    1.41 +		err = HYPERVISOR_dom0_op(&op);
    1.42 +	} else
    1.43 +		err = -EFAULT;
    1.44  
    1.45 -	(void)sys_munlock((unsigned long)user_buffer, user_buffer_size);
    1.46 +	vfree(kbuf);
    1.47  
    1.48  	return err;
    1.49  }
    1.50 @@ -88,17 +90,9 @@ static ssize_t microcode_write (struct f
    1.51  		return -EINVAL;
    1.52  	}
    1.53  
    1.54 -	if ((len >> PAGE_SHIFT) > num_physpages) {
    1.55 -		printk(KERN_ERR "microcode: too much data (max %ld pages)\n", num_physpages);
    1.56 -		return -EINVAL;
    1.57 -	}
    1.58 -
    1.59  	down(&microcode_sem);
    1.60  
    1.61 -	user_buffer = (void __user *) buf;
    1.62 -	user_buffer_size = (int) len;
    1.63 -
    1.64 -	ret = do_microcode_update();
    1.65 +	ret = do_microcode_update(buf, len);
    1.66  	if (!ret)
    1.67  		ret = (ssize_t)len;
    1.68