ia64/xen-unstable

changeset 14625:32f532e6c054

xenbus: check function return values of functions declared with
__must_check post-2.6.18.

This implies completely suppressing frontend/backend operations if the
respective bus or device registration failed.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kfraser@localhost.localdomain
date Wed Mar 28 13:56:22 2007 +0100 (2007-03-28)
parents 64ab7d443549
children 50965ae270c9
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.h linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe_backend.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Mar 28 13:55:01 2007 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Mar 28 13:56:22 2007 +0100
     1.3 @@ -335,6 +335,9 @@ int xenbus_register_driver_common(struct
     1.4  {
     1.5  	int ret;
     1.6  
     1.7 +	if (bus->error)
     1.8 +		return bus->error;
     1.9 +
    1.10  	drv->driver.name = drv->name;
    1.11  	drv->driver.bus = &bus->bus;
    1.12  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
    1.13 @@ -476,6 +479,9 @@ int xenbus_probe_node(struct xen_bus_typ
    1.14  
    1.15  	enum xenbus_state state = xenbus_read_driver_state(nodename);
    1.16  
    1.17 +	if (bus->error)
    1.18 +		return bus->error;
    1.19 +
    1.20  	if (state != XenbusStateInitialising) {
    1.21  		/* Device is not new, so ignore it.  This can happen if a
    1.22  		   device is going away after switching to Closed.  */
    1.23 @@ -513,10 +519,18 @@ int xenbus_probe_node(struct xen_bus_typ
    1.24  	if (err)
    1.25  		goto fail;
    1.26  
    1.27 -	device_create_file(&xendev->dev, &dev_attr_nodename);
    1.28 -	device_create_file(&xendev->dev, &dev_attr_devtype);
    1.29 +	err = device_create_file(&xendev->dev, &dev_attr_nodename);
    1.30 +	if (err)
    1.31 +		goto unregister;
    1.32 +	err = device_create_file(&xendev->dev, &dev_attr_devtype);
    1.33 +	if (err)
    1.34 +		goto unregister;
    1.35  
    1.36  	return 0;
    1.37 +unregister:
    1.38 +	device_remove_file(&xendev->dev, &dev_attr_nodename);
    1.39 +	device_remove_file(&xendev->dev, &dev_attr_devtype);
    1.40 +	device_unregister(&xendev->dev);
    1.41  fail:
    1.42  	kfree(xendev);
    1.43  	return err;
    1.44 @@ -565,6 +579,9 @@ int xenbus_probe_devices(struct xen_bus_
    1.45  	char **dir;
    1.46  	unsigned int i, dir_n;
    1.47  
    1.48 +	if (bus->error)
    1.49 +		return bus->error;
    1.50 +
    1.51  	dir = xenbus_directory(XBT_NIL, bus->root, "", &dir_n);
    1.52  	if (IS_ERR(dir))
    1.53  		return PTR_ERR(dir);
    1.54 @@ -608,7 +625,7 @@ void dev_changed(const char *node, struc
    1.55  	char type[BUS_ID_SIZE];
    1.56  	const char *p, *root;
    1.57  
    1.58 -	if (char_count(node, '/') < 2)
    1.59 +	if (bus->error || char_count(node, '/') < 2)
    1.60   		return;
    1.61  
    1.62  	exists = xenbus_exists(XBT_NIL, node, "");
    1.63 @@ -742,7 +759,8 @@ void xenbus_suspend(void)
    1.64  {
    1.65  	DPRINTK("");
    1.66  
    1.67 -	bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, suspend_dev);
    1.68 +	if (!xenbus_frontend.error)
    1.69 +		bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, suspend_dev);
    1.70  	xenbus_backend_suspend(suspend_dev);
    1.71  	xs_suspend();
    1.72  }
    1.73 @@ -752,7 +770,8 @@ void xenbus_resume(void)
    1.74  {
    1.75  	xb_init_comms();
    1.76  	xs_resume();
    1.77 -	bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, resume_dev);
    1.78 +	if (!xenbus_frontend.error)
    1.79 +		bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, resume_dev);
    1.80  	xenbus_backend_resume(resume_dev);
    1.81  }
    1.82  EXPORT_SYMBOL_GPL(xenbus_resume);
    1.83 @@ -760,7 +779,8 @@ EXPORT_SYMBOL_GPL(xenbus_resume);
    1.84  void xenbus_suspend_cancel(void)
    1.85  {
    1.86  	xs_suspend_cancel();
    1.87 -	bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, suspend_cancel_dev);
    1.88 +	if (!xenbus_frontend.error)
    1.89 +		bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, suspend_cancel_dev);
    1.90  	xenbus_backend_resume(suspend_cancel_dev);
    1.91  }
    1.92  EXPORT_SYMBOL_GPL(xenbus_suspend_cancel);
    1.93 @@ -854,7 +874,11 @@ static int __init xenbus_probe_init(void
    1.94  		return -ENODEV;
    1.95  
    1.96  	/* Register ourselves with the kernel bus subsystem */
    1.97 -	bus_register(&xenbus_frontend.bus);
    1.98 +	xenbus_frontend.error = bus_register(&xenbus_frontend.bus);
    1.99 +	if (xenbus_frontend.error)
   1.100 +		printk(KERN_WARNING
   1.101 +		       "XENBUS: Error registering frontend bus: %i\n",
   1.102 +		       xenbus_frontend.error);
   1.103  	xenbus_backend_bus_register();
   1.104  
   1.105  	/*
   1.106 @@ -925,7 +949,15 @@ static int __init xenbus_probe_init(void
   1.107  	}
   1.108  
   1.109  	/* Register ourselves with the kernel device subsystem */
   1.110 -	device_register(&xenbus_frontend.dev);
   1.111 +	if (!xenbus_frontend.error) {
   1.112 +		xenbus_frontend.error = device_register(&xenbus_frontend.dev);
   1.113 +		if (xenbus_frontend.error) {
   1.114 +			bus_unregister(&xenbus_frontend.bus);
   1.115 +			printk(KERN_WARNING
   1.116 +			       "XENBUS: Error registering frontend device: %i\n",
   1.117 +			       xenbus_frontend.error);
   1.118 +		}
   1.119 +	}
   1.120  	xenbus_backend_device_register();
   1.121  
   1.122  	if (!is_initial_xendomain())
   1.123 @@ -972,6 +1004,8 @@ static int is_disconnected_device(struct
   1.124  
   1.125  static int exists_disconnected_device(struct device_driver *drv)
   1.126  {
   1.127 +	if (xenbus_frontend.error)
   1.128 +		return xenbus_frontend.error;
   1.129  	return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
   1.130  				is_disconnected_device);
   1.131  }
   1.132 @@ -1036,8 +1070,10 @@ static void wait_for_devices(struct xenb
   1.133  #ifndef MODULE
   1.134  static int __init boot_wait_for_devices(void)
   1.135  {
   1.136 -	ready_to_wait_for_devices = 1;
   1.137 -	wait_for_devices(NULL);
   1.138 +	if (!xenbus_frontend.error) {
   1.139 +		ready_to_wait_for_devices = 1;
   1.140 +		wait_for_devices(NULL);
   1.141 +	}
   1.142  	return 0;
   1.143  }
   1.144  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.h	Wed Mar 28 13:55:01 2007 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.h	Wed Mar 28 13:56:22 2007 +0100
     2.3 @@ -51,6 +51,7 @@ static inline void xenbus_backend_device
     2.4  struct xen_bus_type
     2.5  {
     2.6  	char *root;
     2.7 +	int error;
     2.8  	unsigned int levels;
     2.9  	int (*get_bus_id)(char bus_id[BUS_ID_SIZE], const char *nodename);
    2.10  	int (*probe)(const char *type, const char *dir);
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe_backend.c	Wed Mar 28 13:55:01 2007 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe_backend.c	Wed Mar 28 13:56:22 2007 +0100
     3.3 @@ -245,13 +245,15 @@ static struct xenbus_watch be_watch = {
     3.4  void xenbus_backend_suspend(int (*fn)(struct device *, void *))
     3.5  {
     3.6  	DPRINTK("");
     3.7 -	bus_for_each_dev(&xenbus_backend.bus, NULL, NULL, fn);
     3.8 +	if (!xenbus_backend.error)
     3.9 +		bus_for_each_dev(&xenbus_backend.bus, NULL, NULL, fn);
    3.10  }
    3.11  
    3.12  void xenbus_backend_resume(int (*fn)(struct device *, void *))
    3.13  {
    3.14  	DPRINTK("");
    3.15 -	bus_for_each_dev(&xenbus_backend.bus, NULL, NULL, fn);
    3.16 +	if (!xenbus_backend.error)
    3.17 +		bus_for_each_dev(&xenbus_backend.bus, NULL, NULL, fn);
    3.18  }
    3.19  
    3.20  void xenbus_backend_probe_and_watch(void)
    3.21 @@ -262,10 +264,23 @@ void xenbus_backend_probe_and_watch(void
    3.22  
    3.23  void xenbus_backend_bus_register(void)
    3.24  {
    3.25 -	bus_register(&xenbus_backend.bus);
    3.26 +	xenbus_backend.error = bus_register(&xenbus_backend.bus);
    3.27 +	if (xenbus_backend.error)
    3.28 +		printk(KERN_WARNING
    3.29 +		       "XENBUS: Error registering backend bus: %i\n",
    3.30 +		       xenbus_backend.error);
    3.31  }
    3.32  
    3.33  void xenbus_backend_device_register(void)
    3.34  {
    3.35 -	device_register(&xenbus_backend.dev);
    3.36 +	if (xenbus_backend.error)
    3.37 +		return;
    3.38 +
    3.39 +	xenbus_backend.error = device_register(&xenbus_backend.dev);
    3.40 +	if (xenbus_backend.error) {
    3.41 +		bus_unregister(&xenbus_backend.bus);
    3.42 +		printk(KERN_WARNING
    3.43 +		       "XENBUS: Error registering backend device: %i\n",
    3.44 +		       xenbus_backend.error);
    3.45 +	}
    3.46  }