ia64/xen-unstable

changeset 14223:36b923615369

linux: Fix xenbus device write function.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Mar 02 16:26:56 2007 +0000 (2007-03-02)
parents bc265a79dd32
children 4d447158e1dd
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Fri Mar 02 16:15:28 2007 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Fri Mar 02 16:26:56 2007 +0000
     1.3 @@ -173,7 +173,7 @@ static ssize_t xenbus_dev_write(struct f
     1.4  	void *reply;
     1.5  	char *path, *token;
     1.6  	struct watch_adapter *watch, *tmp_watch;
     1.7 -	int err;
     1.8 +	int err, rc = len;
     1.9  
    1.10  	if ((len + u->len) > sizeof(u->u.buffer))
    1.11  		return -EINVAL;
    1.12 @@ -182,8 +182,9 @@ static ssize_t xenbus_dev_write(struct f
    1.13  		return -EFAULT;
    1.14  
    1.15  	u->len += len;
    1.16 -	if (u->len < (sizeof(u->u.msg) + u->u.msg.len))
    1.17 -		return len;
    1.18 +	if ((u->len < sizeof(u->u.msg)) ||
    1.19 +	    (u->len < (sizeof(u->u.msg) + u->u.msg.len)))
    1.20 +		return rc;
    1.21  
    1.22  	msg_type = u->u.msg.type;
    1.23  
    1.24 @@ -201,14 +202,17 @@ static ssize_t xenbus_dev_write(struct f
    1.25  	case XS_SET_PERMS:
    1.26  		if (msg_type == XS_TRANSACTION_START) {
    1.27  			trans = kmalloc(sizeof(*trans), GFP_KERNEL);
    1.28 -			if (!trans)
    1.29 -				return -ENOMEM;
    1.30 +			if (!trans) {
    1.31 +				rc = -ENOMEM;
    1.32 +				goto out;
    1.33 +			}
    1.34  		}
    1.35  
    1.36  		reply = xenbus_dev_request_and_reply(&u->u.msg);
    1.37  		if (IS_ERR(reply)) {
    1.38  			kfree(trans);
    1.39 -			return PTR_ERR(reply);
    1.40 +			rc = PTR_ERR(reply);
    1.41 +			goto out;
    1.42  		}
    1.43  
    1.44  		if (msg_type == XS_TRANSACTION_START) {
    1.45 @@ -231,8 +235,10 @@ static ssize_t xenbus_dev_write(struct f
    1.46  	case XS_UNWATCH:
    1.47  		path = u->u.buffer + sizeof(u->u.msg);
    1.48  		token = memchr(path, 0, u->u.msg.len);
    1.49 -		if (token == NULL)
    1.50 -			return -EILSEQ;
    1.51 +		if (token == NULL) {
    1.52 +			rc = -EILSEQ;
    1.53 +			goto out;
    1.54 +		}
    1.55  		token++;
    1.56  
    1.57  		if (msg_type == XS_WATCH) {
    1.58 @@ -251,7 +257,8 @@ static ssize_t xenbus_dev_write(struct f
    1.59  			err = register_xenbus_watch(&watch->watch);
    1.60  			if (err) {
    1.61  				free_watch_adapter(watch);
    1.62 -				return err;
    1.63 +				rc = err;
    1.64 +				goto out;
    1.65  			}
    1.66  			
    1.67  			list_add(&watch->list, &u->watches);
    1.68 @@ -265,7 +272,6 @@ static ssize_t xenbus_dev_write(struct f
    1.69                                                   &u->watches, list) {
    1.70  				if (!strcmp(watch->token, token) &&
    1.71  				    !strcmp(watch->watch.node, path))
    1.72 -					break;
    1.73  				{
    1.74  					unregister_xenbus_watch(&watch->watch);
    1.75  					list_del(&watch->list);
    1.76 @@ -278,11 +284,13 @@ static ssize_t xenbus_dev_write(struct f
    1.77  		break;
    1.78  
    1.79  	default:
    1.80 -		return -EINVAL;
    1.81 +		rc = -EINVAL;
    1.82 +		break;
    1.83  	}
    1.84  
    1.85 + out:
    1.86  	u->len = 0;
    1.87 -	return len;
    1.88 +	return rc;
    1.89  }
    1.90  
    1.91  static int xenbus_dev_open(struct inode *inode, struct file *filp)