diff options
| author | David Woodhouse <David.Woodhouse@intel.com> | 2008-07-11 14:36:25 +0100 | 
|---|---|---|
| committer | David Woodhouse <David.Woodhouse@intel.com> | 2008-07-11 14:36:25 +0100 | 
| commit | a8931ef380c92d121ae74ecfb03b2d63f72eea6f (patch) | |
| tree | 980fb6b019e11e6cb1ece55b7faff184721a8053 /drivers/base/core.c | |
| parent | 90574d0a4d4b73308ae54a2a57a4f3f1fa98e984 (diff) | |
| parent | e5a5816f7875207cb0a0a7032e39a4686c5e10a4 (diff) | |
| download | olio-linux-3.10-a8931ef380c92d121ae74ecfb03b2d63f72eea6f.tar.xz olio-linux-3.10-a8931ef380c92d121ae74ecfb03b2d63f72eea6f.zip  | |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers/base/core.c')
| -rw-r--r-- | drivers/base/core.c | 109 | 
1 files changed, 98 insertions, 11 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index be288b5e418..ee0a51a3a41 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -760,6 +760,22 @@ static void device_remove_class_symlinks(struct device *dev)  }  /** + * dev_set_name - set a device name + * @dev: device + * @fmt: format string for the device's name + */ +int dev_set_name(struct device *dev, const char *fmt, ...) +{ +	va_list vargs; + +	va_start(vargs, fmt); +	vsnprintf(dev->bus_id, sizeof(dev->bus_id), fmt, vargs); +	va_end(vargs); +	return 0; +} +EXPORT_SYMBOL_GPL(dev_set_name); + +/**   * device_add - add device to device hierarchy.   * @dev: device.   * @@ -1084,11 +1100,13 @@ static void device_create_release(struct device *dev)  }  /** - * device_create - creates a device and registers it with sysfs + * device_create_vargs - creates a device and registers it with sysfs   * @class: pointer to the struct class that this device should be registered to   * @parent: pointer to the parent struct device of this new device, if any   * @devt: the dev_t for the char device to be added + * @drvdata: the data to be added to the device for callbacks   * @fmt: string for the device's name + * @args: va_list for the device's name   *   * This function can be used by char device classes.  A struct device   * will be created in sysfs, registered to the specified class. @@ -1104,10 +1122,10 @@ static void device_create_release(struct device *dev)   * Note: the struct class passed to this function must have previously   * been created with a call to class_create().   */ -struct device *device_create(struct class *class, struct device *parent, -			     dev_t devt, const char *fmt, ...) +struct device *device_create_vargs(struct class *class, struct device *parent, +				   dev_t devt, void *drvdata, const char *fmt, +				   va_list args)  { -	va_list args;  	struct device *dev = NULL;  	int retval = -ENODEV; @@ -1124,10 +1142,9 @@ struct device *device_create(struct class *class, struct device *parent,  	dev->class = class;  	dev->parent = parent;  	dev->release = device_create_release; +	dev_set_drvdata(dev, drvdata); -	va_start(args, fmt);  	vsnprintf(dev->bus_id, BUS_ID_SIZE, fmt, args); -	va_end(args);  	retval = device_register(dev);  	if (retval)  		goto error; @@ -1138,6 +1155,78 @@ error:  	kfree(dev);  	return ERR_PTR(retval);  } +EXPORT_SYMBOL_GPL(device_create_vargs); + +/** + * device_create_drvdata - creates a device and registers it with sysfs + * @class: pointer to the struct class that this device should be registered to + * @parent: pointer to the parent struct device of this new device, if any + * @devt: the dev_t for the char device to be added + * @drvdata: the data to be added to the device for callbacks + * @fmt: string for the device's name + * + * This function can be used by char device classes.  A struct device + * will be created in sysfs, registered to the specified class. + * + * A "dev" file will be created, showing the dev_t for the device, if + * the dev_t is not 0,0. + * If a pointer to a parent struct device is passed in, the newly created + * struct device will be a child of that device in sysfs. + * The pointer to the struct device will be returned from the call. + * Any further sysfs files that might be required can be created using this + * pointer. + * + * Note: the struct class passed to this function must have previously + * been created with a call to class_create(). + */ +struct device *device_create_drvdata(struct class *class, +				     struct device *parent, +				     dev_t devt, +				     void *drvdata, +				     const char *fmt, ...) +{ +	va_list vargs; +	struct device *dev; + +	va_start(vargs, fmt); +	dev = device_create_vargs(class, parent, devt, drvdata, fmt, vargs); +	va_end(vargs); +	return dev; +} +EXPORT_SYMBOL_GPL(device_create_drvdata); + +/** + * device_create - creates a device and registers it with sysfs + * @class: pointer to the struct class that this device should be registered to + * @parent: pointer to the parent struct device of this new device, if any + * @devt: the dev_t for the char device to be added + * @fmt: string for the device's name + * + * This function can be used by char device classes.  A struct device + * will be created in sysfs, registered to the specified class. + * + * A "dev" file will be created, showing the dev_t for the device, if + * the dev_t is not 0,0. + * If a pointer to a parent struct device is passed in, the newly created + * struct device will be a child of that device in sysfs. + * The pointer to the struct device will be returned from the call. + * Any further sysfs files that might be required can be created using this + * pointer. + * + * Note: the struct class passed to this function must have previously + * been created with a call to class_create(). + */ +struct device *device_create(struct class *class, struct device *parent, +			     dev_t devt, const char *fmt, ...) +{ +	va_list vargs; +	struct device *dev; + +	va_start(vargs, fmt); +	dev = device_create_vargs(class, parent, devt, NULL, fmt, vargs); +	va_end(vargs); +	return dev; +}  EXPORT_SYMBOL_GPL(device_create);  static int __match_devt(struct device *dev, void *data) @@ -1218,13 +1307,11 @@ int device_rename(struct device *dev, char *new_name)  	}  #else  	if (dev->class) { -		sysfs_remove_link(&dev->class->subsys.kobj, old_device_name);  		error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,  					  dev->bus_id); -		if (error) { -			dev_err(dev, "%s: sysfs_create_symlink failed (%d)\n", -				__func__, error); -		} +		if (error) +			goto out; +		sysfs_remove_link(&dev->class->subsys.kobj, old_device_name);  	}  #endif  |