ia64/xen-unstable

changeset 5888:b52196300306

Fix locking: probe can be called from several places, so ensure
we lock for it.
Signed-off-by: Rusty Russel <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Jul 26 17:22:38 2005 +0000 (2005-07-26)
parents c1c2a023dbc4
children a9a956748997
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Jul 26 17:19:38 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Jul 26 17:22:38 2005 +0000
     1.3 @@ -47,10 +47,13 @@ match_device(const struct xenbus_device_
     1.4  		if (!streq(arr->devicetype, dev->devicetype))
     1.5  			continue;
     1.6  
     1.7 -		if (streq(arr->subtype, "") ||
     1.8 -		    streq(arr->subtype, dev->subtype)) {
     1.9 +		/* If they don't care what subtype, it's a match. */
    1.10 +		if (streq(arr->subtype, ""))
    1.11  			return arr;
    1.12 -		}
    1.13 +
    1.14 +		/* If they care, device must have (same) subtype. */
    1.15 +		if (dev->subtype && streq(arr->subtype, dev->subtype))
    1.16 +			return arr;
    1.17  	}
    1.18  	return NULL;
    1.19  }
    1.20 @@ -99,18 +102,25 @@ static int xenbus_dev_remove(struct devi
    1.21  
    1.22  int xenbus_register_driver(struct xenbus_driver *drv)
    1.23  {
    1.24 +	int err;
    1.25 +
    1.26  	drv->driver.name = drv->name;
    1.27  	drv->driver.bus = &xenbus_type;
    1.28  	drv->driver.owner = drv->owner;
    1.29  	drv->driver.probe = xenbus_dev_probe;
    1.30  	drv->driver.remove = xenbus_dev_remove;
    1.31  
    1.32 -	return driver_register(&drv->driver);
    1.33 +	down(&xenbus_lock);
    1.34 +	err = driver_register(&drv->driver);
    1.35 +	up(&xenbus_lock);
    1.36 +	return err;
    1.37  }
    1.38  
    1.39  void xenbus_unregister_driver(struct xenbus_driver *drv)
    1.40  {
    1.41 +	down(&xenbus_lock);
    1.42  	driver_unregister(&drv->driver);
    1.43 +	up(&xenbus_lock);
    1.44  }
    1.45  
    1.46  struct xb_find_info
    1.47 @@ -203,20 +213,16 @@ static int xenbus_probe_devices(const ch
    1.48  	char **dir;
    1.49  	unsigned int i, dir_n;
    1.50  
    1.51 -	down(&xenbus_lock);
    1.52  	dir = xenbus_directory(path, "", &dir_n);
    1.53 -	if (IS_ERR(dir)) {
    1.54 -		err = PTR_ERR(dir);
    1.55 -		goto unlock;
    1.56 -	}
    1.57 +	if (IS_ERR(dir))
    1.58 +		return PTR_ERR(dir);
    1.59 +
    1.60  	for (i = 0; i < dir_n; i++) {
    1.61  		err = xenbus_probe_device_type(path, dir[i]);
    1.62  		if (err)
    1.63  			break;
    1.64  	}
    1.65  	kfree(dir);
    1.66 -unlock:
    1.67 -	up(&xenbus_lock);
    1.68  	return err;
    1.69  }
    1.70  
    1.71 @@ -292,10 +298,10 @@ int do_xenbus_probe(void *unused)
    1.72  		return err;
    1.73  	}
    1.74  
    1.75 +	down(&xenbus_lock);
    1.76  	/* Enumerate devices in xenstore. */
    1.77  	xenbus_probe_devices("device");
    1.78 -
    1.79 -	down(&xenbus_lock);
    1.80 +	/* Watch for changes. */
    1.81  	register_xenbus_watch(&dev_watch);
    1.82  	up(&xenbus_lock);
    1.83  	return 0;