Skip to contentSkip to conversation

Couple of sysfs patches

PATCH Applied Dmitry Torokhov 3 participants 19 messages Jun 9, 2004 – Jun 10, 2004 3 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Couple of sysfs patches

Hi,

I am trying to add sysfs support to the serio subsystem and I would like you to consider the following changes:

- when registering platform device, if device id is set to -1, do not add it as a suffix to device's name. It can be used when there is only one device. The reason for change - i find that i80420 looks ugly, just i8042 is much better ;)

- create platform_device_simple_releasse function that would just free memory occupied by platform device. Having such release routine in core allows drivers implementing simple platform devices not wait in module unload code till last reference to the device is dropped.

And of course whitespace changes ;) in the very first patch.

Please consider applying.

Signature · 1 line
Dmitry
#1 lore raw

PATCH 1/3 whitespace fixes in drivers/base

===================================================================

[email protected], 2004-06-07 19:08:11-05:00, [email protected]
Whitespace and formatting changes (a,b,c -> a, b, c) in drivers/base

 base.h           |    5 +-
 bus.c            |  125 +++++++++++++++++++++++++++----------------------------
 class.c          |   38 ++++++++--------
 class_simple.c   |   12 ++---
 core.c           |   46 ++++++++++----------
 driver.c         |   16 +++----
 firmware.c       |    6 +-
 firmware_class.c |   10 ++--
 init.c           |    4 -
 interface.c      |   18 +++----
 node.c           |   14 +++---
 platform.c       |   20 ++++----
 power/main.c     |   14 +++---
 power/power.h    |    8 +--
 power/resume.c   |   12 ++---
 power/runtime.c  |    8 +--
 power/shutdown.c |   18 +++----
 power/suspend.c  |   42 +++++++++---------
 power/sysfs.c    |   18 +++----
 sys.c            |  102 ++++++++++++++++++++++----------------------
 20 files changed, 268 insertions(+), 268 deletions(-)

===================================================================

drivers/base/base.h +3 -2
diff -Nru a/drivers/base/base.h b/drivers/base/base.h
@@ -6,12 +6,13 @@
 
 static inline struct class_device *to_class_dev(struct kobject *obj)
 {
-	return container_of(obj,struct class_device,kobj);
+	return container_of(obj, struct class_device, kobj);
 }
+
 static inline
 struct class_device_attribute *to_class_dev_attr(struct attribute *_attr)
 {
-	return container_of(_attr,struct class_device_attribute,attr);
+	return container_of(_attr, struct class_device_attribute, attr);
 }
 
 
drivers/base/bus.c +62 -63

360 lines not on this page · raw message

drivers/base/class.c +19 -19
diff -Nru a/drivers/base/class.c b/drivers/base/class.c
@@ -5,7 +5,7 @@
  * Copyright (c) 2002-3 Open Source Development Labs
  * Copyright (c) 2003-2004 Greg Kroah-Hartman
  * Copyright (c) 2003-2004 IBM Corp.
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -17,8 +17,8 @@
 #include <linux/string.h>
 #include "base.h"
 
-#define to_class_attr(_attr) container_of(_attr,struct class_attribute,attr)
-#define to_class(obj) container_of(obj,struct class,subsys.kset.kobj)
+#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
+#define to_class(obj) container_of(obj, struct class, subsys.kset.kobj)
 
 static ssize_t
 class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
@@ -28,12 +28,12 @@
 	ssize_t ret = 0;
 
 	if (class_attr->show)
-		ret = class_attr->show(dc,buf);
+		ret = class_attr->show(dc, buf);
 	return ret;
 }
 
 static ssize_t
-class_attr_store(struct kobject * kobj, struct attribute * attr, 
+class_attr_store(struct kobject * kobj, struct attribute * attr,
 		 const char * buf, size_t count)
 {
 	struct class_attribute * class_attr = to_class_attr(attr);
@@ -41,7 +41,7 @@
 	ssize_t ret = 0;
 
 	if (class_attr->store)
-		ret = class_attr->store(dc,buf,count);
+		ret = class_attr->store(dc, buf, count);
 	return ret;
 }
 
@@ -69,14 +69,14 @@
 };
 
 /* Hotplug events for classes go to the class_obj subsys */
-static decl_subsys(class,&ktype_class,NULL);
+static decl_subsys(class, &ktype_class, NULL);
 
 
 int class_create_file(struct class * cls, const struct class_attribute * attr)
 {
 	int error;
 	if (cls) {
-		error = sysfs_create_file(&cls->subsys.kset.kobj,&attr->attr);
+		error = sysfs_create_file(&cls->subsys.kset.kobj, &attr->attr);
 	} else
 		error = -EINVAL;
 	return error;
@@ -85,13 +85,13 @@
 void class_remove_file(struct class * cls, const struct class_attribute * attr)
 {
 	if (cls)
-		sysfs_remove_file(&cls->subsys.kset.kobj,&attr->attr);
+		sysfs_remove_file(&cls->subsys.kset.kobj, &attr->attr);
 }
 
 struct class * class_get(struct class * cls)
 {
 	if (cls)
-		return container_of(subsys_get(&cls->subsys),struct class,subsys);
+		return container_of(subsys_get(&cls->subsys), struct class, subsys);
 	return NULL;
 }
 
@@ -104,15 +104,15 @@
 {
 	int error;
 
-	pr_debug("device class '%s': registering\n",cls->name);
+	pr_debug("device class '%s': registering\n", cls->name);
 
 	INIT_LIST_HEAD(&cls->children);
 	INIT_LIST_HEAD(&cls->interfaces);
-	error = kobject_set_name(&cls->subsys.kset.kobj,cls->name);
+	error = kobject_set_name(&cls->subsys.kset.kobj, cls->name);
 	if (error)
 		return error;
 
-	subsys_set_kset(cls,class_subsys);
+	subsys_set_kset(cls, class_subsys);
 
 	error = subsystem_register(&cls->subsys);
 	if (error)
@@ -123,7 +123,7 @@
 
 void class_unregister(struct class * cls)
 {
-	pr_debug("device class '%s': unregistering\n",cls->name);
+	pr_debug("device class '%s': unregistering\n", cls->name);
 	subsystem_unregister(&cls->subsys);
 }
 
@@ -181,12 +181,12 @@
 	ssize_t ret = 0;
 
 	if (class_dev_attr->show)
-		ret = class_dev_attr->show(cd,buf);
+		ret = class_dev_attr->show(cd, buf);
 	return ret;
 }
 
 static ssize_t
-class_device_attr_store(struct kobject * kobj, struct attribute * attr, 
+class_device_attr_store(struct kobject * kobj, struct attribute * attr,
 			const char * buf, size_t count)
 {
 	struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
@@ -194,7 +194,7 @@
 	ssize_t ret = 0;
 
 	if (class_dev_attr->store)
-		ret = class_dev_attr->store(cd,buf,count);
+		ret = class_dev_attr->store(cd, buf, count);
 	return ret;
 }
 
@@ -208,7 +208,7 @@
 	struct class_device *cd = to_class_dev(kobj);
 	struct class * cls = cd->class;
 
-	pr_debug("device class '%s': release.\n",cd->class_id);
+	pr_debug("device class '%s': release.\n", cd->class_id);
 
 	if (cls->release)
 		cls->release(cd);
@@ -344,7 +344,7 @@
 
 	class_device_dev_unlink(class_dev);
 	class_device_driver_unlink(class_dev);
-	
+
 	kobject_del(&class_dev->kobj);
 
 	if (parent)
drivers/base/class_simple.c +6 -6
diff -Nru a/drivers/base/class_simple.c b/drivers/base/class_simple.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2003-2004 Greg Kroah-Hartman <[email protected]>
  * Copyright (c) 2003-2004 IBM Corp.
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -111,7 +111,7 @@
 
 /**
  * class_simple_device_add - adds a class device to sysfs for a character driver
- * @cs: pointer to the struct class_simple that this device should be registered to.  
+ * @cs: pointer to the struct class_simple that this device should be registered to.
  * @dev: the dev_t for the device to be added.
  * @device: a pointer to a struct device that is assiociated with this class device.
  * @fmt: string for the class device's name
@@ -146,8 +146,8 @@
 	s_dev->dev = dev;
 	s_dev->class_dev.dev = device;
 	s_dev->class_dev.class = &cs->class;
-	
-	va_start(args,fmt);
+
+	va_start(args, fmt);
 	vsnprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, fmt, args);
 	va_end(args);
 	retval = class_device_register(&s_dev->class_dev);
@@ -173,10 +173,10 @@
  * @cs: pointer to the struct class_simple to hold the pointer
  * @hotplug: function pointer to the hotplug function
  *
- * Implement and set a hotplug function to add environment variables specific to this 
+ * Implement and set a hotplug function to add environment variables specific to this
  * class on the hotplug event.
  */
-int class_simple_set_hotplug(struct class_simple *cs, 
+int class_simple_set_hotplug(struct class_simple *cs,
 	int (*hotplug)(struct class_device *dev, char **envp, int num_envp, char *buffer, int buffer_size))
 {
 	if ((cs == NULL) || (IS_ERR(cs)))
drivers/base/core.c +23 -23

150 lines not on this page · raw message

drivers/base/driver.c +8 -8
diff -Nru a/drivers/base/driver.c b/drivers/base/driver.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -15,8 +15,8 @@
 #include <linux/string.h>
 #include "base.h"
 
-#define to_dev(node) container_of(node,struct device,driver_list)
-#define to_drv(obj) container_of(obj,struct device_driver,kobj)
+#define to_dev(node) container_of(node, struct device, driver_list)
+#define to_drv(obj) container_of(obj, struct device_driver, kobj)
 
 /**
  *	driver_create_file - create sysfs file for driver.
@@ -28,7 +28,7 @@
 {
 	int error;
 	if (get_driver(drv)) {
-		error = sysfs_create_file(&drv->kobj,&attr->attr);
+		error = sysfs_create_file(&drv->kobj, &attr->attr);
 		put_driver(drv);
 	} else
 		error = -EINVAL;
@@ -45,7 +45,7 @@
 void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr)
 {
 	if (get_driver(drv)) {
-		sysfs_remove_file(&drv->kobj,&attr->attr);
+		sysfs_remove_file(&drv->kobj, &attr->attr);
 		put_driver(drv);
 	}
 }
@@ -76,7 +76,7 @@
  *	@drv:	driver to register
  *
  *	We pass off most of the work to the bus_add_driver() call,
- *	since most of the things we have to do deal with the bus 
+ *	since most of the things we have to do deal with the bus
  *	structures.
  *
  *	The one interesting aspect is that we initialize @drv->unload_sem
@@ -99,8 +99,8 @@
  *
  *	Though, once that is done, we attempt to take @drv->unload_sem.
  *	This will block until the driver refcount reaches 0, and it is
- *	released. Only modular drivers will call this function, and we 
- *	have to guarantee that it won't complete, letting the driver 
+ *	released. Only modular drivers will call this function, and we
+ *	have to guarantee that it won't complete, letting the driver
  *	unload until all references are gone.
  */
 
drivers/base/firmware.c +3 -3
diff -Nru a/drivers/base/firmware.c b/drivers/base/firmware.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -12,11 +12,11 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
-static decl_subsys(firmware,NULL,NULL);
+static decl_subsys(firmware, NULL, NULL);
 
 int firmware_register(struct subsystem * s)
 {
-	kset_set_kset_s(s,firmware_subsys);
+	kset_set_kset_s(s, firmware_subsys);
 	return subsystem_register(s);
 }
 
drivers/base/firmware_class.c +5 -5
diff -Nru a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
@@ -68,7 +68,7 @@
  *	firmware will be provided.
  *
  *	Note: zero means 'wait for ever'
- *  
+ *
  **/
 static ssize_t
 firmware_timeout_store(struct class *class, const char *buf, size_t count)
@@ -121,7 +121,7 @@
 /**
  * firmware_loading_store: - loading control file
  * Description:
- *	The relevant values are: 
+ *	The relevant values are:
  *
  *	 1: Start a load, discarding any previous partial load.
  *	 0: Conclude the load and handle the data to the driver code.
@@ -376,7 +376,7 @@
 	return retval;
 }
 
-/** 
+/**
  * request_firmware: - request firmware to hotplug and wait for it
  * Description:
  *	@firmware will be used to return a firmware image by the name
@@ -457,7 +457,7 @@
 
 /**
  * register_firmware: - provide a firmware image for later usage
- * 
+ *
  * Description:
  *	Make sure that @data will be available by requesting firmware @name.
  *
@@ -541,7 +541,7 @@
 
 	ret = kernel_thread(request_firmware_work_func, fw_work,
 			    CLONE_FS | CLONE_FILES);
-	
+
 	if (ret < 0) {
 		fw_work->cont(NULL, fw_work->context);
 		return ret;
drivers/base/init.c +2 -2
diff -Nru a/drivers/base/init.c b/drivers/base/init.c
@@ -2,7 +2,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -33,7 +33,7 @@
 	classes_init();
 	firmware_init();
 
-	/* These are also core pieces, but must come after the 
+	/* These are also core pieces, but must come after the
 	 * core core pieces.
 	 */
 	platform_bus_init();
drivers/base/interface.c +9 -9
diff -Nru a/drivers/base/interface.c b/drivers/base/interface.c
@@ -1,10 +1,10 @@
 /*
- * drivers/base/interface.c - common driverfs interface that's exported to 
+ * drivers/base/interface.c - common driverfs interface that's exported to
  * 	the world for all devices.
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -16,33 +16,33 @@
 
 /**
  *	detach_state - control the default power state for the device.
- *	
- *	This is the state the device enters when it's driver module is 
+ *
+ *	This is the state the device enters when it's driver module is
  *	unloaded. The value is an unsigned integer, in the range of 0-4.
  *	'0' indicates 'On', so no action will be taken when the driver is
  *	unloaded. This is the default behavior.
  *	'4' indicates 'Off', meaning the driver core will call the driver's
  *	shutdown method to quiesce the device.
- *	1-3 indicate a low-power state for the device to enter via the 
- *	driver's suspend method. 
+ *	1-3 indicate a low-power state for the device to enter via the
+ *	driver's suspend method.
  */
 
 static ssize_t detach_show(struct device * dev, char * buf)
 {
-	return sprintf(buf,"%u\n",dev->detach_state);
+	return sprintf(buf, "%u\n", dev->detach_state);
 }
 
 static ssize_t detach_store(struct device * dev, const char * buf, size_t n)
 {
 	u32 state;
-	state = simple_strtoul(buf,NULL,10);
+	state = simple_strtoul(buf, NULL, 10);
 	if (state > 4)
 		return -EINVAL;
 	dev->detach_state = state;
 	return n;
 }
 
-static DEVICE_ATTR(detach_state,0644,detach_show,detach_store);
+static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store);
 
 
 struct attribute * dev_default_attrs[] = {
drivers/base/node.c +7 -7
diff -Nru a/drivers/base/node.c b/drivers/base/node.c
@@ -28,7 +28,7 @@
 	return len;
 }
 
-static SYSDEV_ATTR(cpumap,S_IRUGO,node_read_cpumap,NULL);
+static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL);
 
 /* Can be overwritten by architecture specific code. */
 int __attribute__((weak)) hugetlb_report_node_meminfo(int node, char *buf)
@@ -53,17 +53,17 @@
 		       "Node %d LowFree:      %8lu kB\n",
 		       nid, K(i.totalram),
 		       nid, K(i.freeram),
-		       nid, K(i.totalram-i.freeram),
+		       nid, K(i.totalram - i.freeram),
 		       nid, K(i.totalhigh),
 		       nid, K(i.freehigh),
-		       nid, K(i.totalram-i.totalhigh),
-		       nid, K(i.freeram-i.freehigh));
+		       nid, K(i.totalram - i.totalhigh),
+		       nid, K(i.freeram - i.freehigh));
 	n += hugetlb_report_node_meminfo(nid, buf + n);
 	return n;
 }
 
-#undef K 
-static SYSDEV_ATTR(meminfo,S_IRUGO,node_read_meminfo,NULL);
+#undef K
+static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
 
 static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
 {
@@ -103,7 +103,7 @@
 		       local_node,
 		       other_node);
 }
-static SYSDEV_ATTR(numastat,S_IRUGO,node_read_numastat,NULL);
+static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
 
 /*
  * register_node - Setup a driverfs device for a node.
drivers/base/platform.c +10 -10
diff -Nru a/drivers/base/platform.c b/drivers/base/platform.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  * Please see Documentation/driver-model/platform.txt for more
@@ -32,11 +32,11 @@
 		pdev->dev.parent = &platform_bus;
 
 	pdev->dev.bus = &platform_bus_type;
-	
-	snprintf(pdev->dev.bus_id,BUS_ID_SIZE,"%s%u",pdev->name,pdev->id);
+
+	snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s%u", pdev->name, pdev->id);
 
 	pr_debug("Registering platform device '%s'. Parent at %s\n",
-		 pdev->dev.bus_id,pdev->dev.parent->bus_id);
+		 pdev->dev.bus_id, pdev->dev.parent->bus_id);
 	return device_register(&pdev->dev);
 }
 
@@ -52,13 +52,13 @@
  *	@dev:	device.
  *	@drv:	driver.
  *
- *	Platform device IDs are assumed to be encoded like this: 
- *	"<name><instance>", where <name> is a short description of the 
- *	type of device, like "pci" or "floppy", and <instance> is the 
+ *	Platform device IDs are assumed to be encoded like this:
+ *	"<name><instance>", where <name> is a short description of the
+ *	type of device, like "pci" or "floppy", and <instance> is the
  *	enumerated instance of the device, like '0' or '42'.
- *	Driver IDs are simply "<name>". 
- *	So, extract the <name> from the platform_device structure, 
- *	and compare it against the name of the driver. Return whether 
+ *	Driver IDs are simply "<name>".
+ *	So, extract the <name> from the platform_device structure,
+ *	and compare it against the name of the driver. Return whether
  *	they match or not.
  */
 
drivers/base/power/main.c +7 -7
diff -Nru a/drivers/base/power/main.c b/drivers/base/power/main.c
@@ -12,10 +12,10 @@
  * and add it to the list of power-controlled devices. sysfs entries for
  * controlling device power management will also be added.
  *
- * A different set of lists than the global subsystem list are used to 
- * keep track of power info because we use different lists to hold 
- * devices based on what stage of the power management process they 
- * are in. The power domain dependencies may also differ from the 
+ * A different set of lists than the global subsystem list are used to
+ * keep track of power info because we use different lists to hold
+ * devices based on what stage of the power management process they
+ * are in. The power domain dependencies may also differ from the
  * ancestral dependencies that the subsystem list maintains.
  */
 
@@ -74,10 +74,10 @@
 
 	pr_debug("PM: Adding info for %s:%s\n",
 		 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);
-	atomic_set(&dev->power.pm_users,0);
+	atomic_set(&dev->power.pm_users, 0);
 	down(&dpm_sem);
-	list_add_tail(&dev->power.entry,&dpm_active);
-	device_pm_set_parent(dev,dev->parent);
+	list_add_tail(&dev->power.entry, &dpm_active);
+	device_pm_set_parent(dev, dev->parent);
 	if ((error = dpm_sysfs_add(dev)))
 		list_del(&dev->power.entry);
 	up(&dpm_sem);
drivers/base/power/power.h +4 -4
diff -Nru a/drivers/base/power/power.h b/drivers/base/power/power.h
@@ -27,7 +27,7 @@
  */
 extern struct semaphore dpm_sem;
 
-/* 
+/*
  * The PM lists.
  */
 extern struct list_head dpm_active;
@@ -37,12 +37,12 @@
 
 static inline struct dev_pm_info * to_pm_info(struct list_head * entry)
 {
-	return container_of(entry,struct dev_pm_info,entry);
+	return container_of(entry, struct dev_pm_info, entry);
 }
 
 static inline struct device * to_device(struct list_head * entry)
 {
-	return container_of(to_pm_info(entry),struct device,power);
+	return container_of(to_pm_info(entry), struct device, power);
 }
 
 extern int device_pm_add(struct device *);
@@ -56,7 +56,7 @@
 extern void dpm_sysfs_remove(struct device *);
 
 /*
- * resume.c 
+ * resume.c
  */
 
 extern void dpm_resume(void);
drivers/base/power/resume.c +6 -6
diff -Nru a/drivers/base/power/resume.c b/drivers/base/power/resume.c
@@ -39,7 +39,7 @@
 		if (!dev->power.prev_state)
 			resume_device(dev);
 
-		list_add_tail(entry,&dpm_active);
+		list_add_tail(entry, &dpm_active);
 	}
 }
 
@@ -48,7 +48,7 @@
  *	device_resume - Restore state of each device in system.
  *
  *	Walk the dpm_off list, remove each entry, resume the device,
- *	then add it to the dpm_active list. 
+ *	then add it to the dpm_active list.
  */
 
 void device_resume(void)
@@ -62,14 +62,14 @@
 
 
 /**
- *	device_power_up_irq - Power on some devices. 
+ *	device_power_up_irq - Power on some devices.
  *
- *	Walk the dpm_off_irq list and power each device up. This 
+ *	Walk the dpm_off_irq list and power each device up. This
  *	is used for devices that required they be powered down with
  *	interrupts disabled. As devices are powered on, they are moved to
  *	the dpm_suspended list.
  *
- *	Interrupts must be disabled when calling this. 
+ *	Interrupts must be disabled when calling this.
  */
 
 void dpm_power_up(void)
@@ -78,7 +78,7 @@
 		struct list_head * entry = dpm_off_irq.next;
 		list_del_init(entry);
 		resume_device(to_device(entry));
-		list_add_tail(entry,&dpm_active);
+		list_add_tail(entry, &dpm_active);
 	}
 }
 
drivers/base/power/runtime.c +4 -4
diff -Nru a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
@@ -24,9 +24,9 @@
  *	dpm_runtime_resume - Power one device back on.
  *	@dev:	Device.
  *
- *	Bring one device back to the on state by first powering it 
+ *	Bring one device back to the on state by first powering it
  *	on, then restoring state. We only operate on devices that aren't
- *	already on. 
+ *	already on.
  *	FIXME: We need to handle devices that are in an unknown state.
  */
 
@@ -55,7 +55,7 @@
 	if (dev->power.power_state)
 		runtime_resume(dev);
 
-	if (!(error = suspend_device(dev,state)))
+	if (!(error = suspend_device(dev, state)))
 		dev->power.power_state = state;
  Done:
 	up(&dpm_sem);
@@ -70,7 +70,7 @@
  *
  *	This is an update mechanism for drivers to notify the core
  *	what power state a device is in. Device probing code may not
- *	always be able to tell, but we need accurate information to 
+ *	always be able to tell, but we need accurate information to
  *	work reliably.
  */
 void dpm_set_power_state(struct device * dev, u32 state)
drivers/base/power/shutdown.c +9 -9
diff -Nru a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
@@ -1,9 +1,9 @@
 /*
  * shutdown.c - power management functions for the device tree.
- * 
+ *
  * Copyright (c) 2002-3 Patrick Mochel
  *		 2002-3 Open Source Development Lab
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -14,7 +14,7 @@
 
 #include "power.h"
 
-#define to_dev(node) container_of(node,struct device,kobj.entry)
+#define to_dev(node) container_of(node, struct device, kobj.entry)
 
 extern struct subsystem devices_subsys;
 
@@ -29,7 +29,7 @@
 			dev->driver->shutdown(dev);
 		return 0;
 	}
-	return dpm_runtime_suspend(dev,dev->detach_state);
+	return dpm_runtime_suspend(dev, dev->detach_state);
 }
 
 
@@ -38,8 +38,8 @@
  * down last and resume them first. That way, we don't do anything stupid like
  * shutting down the interrupt controller before any devices..
  *
- * Note that there are not different stages for power management calls - 
- * they only get one called once when interrupts are disabled. 
+ * Note that there are not different stages for power management calls -
+ * they only get one called once when interrupts are disabled.
  */
 
 extern int sysdev_shutdown(void);
@@ -50,10 +50,10 @@
 void device_shutdown(void)
 {
 	struct device * dev;
-	
+
 	down_write(&devices_subsys.rwsem);
-	list_for_each_entry_reverse(dev,&devices_subsys.kset.list,kobj.entry) {
-		pr_debug("shutting down %s: ",dev->bus_id);
+	list_for_each_entry_reverse(dev, &devices_subsys.kset.list, kobj.entry) {
+		pr_debug("shutting down %s: ", dev->bus_id);
 		if (dev->driver && dev->driver->shutdown) {
 			pr_debug("Ok\n");
 			dev->driver->shutdown(dev);
drivers/base/power/suspend.c +21 -21

99 lines not on this page · raw message

drivers/base/power/sysfs.c +9 -9
diff -Nru a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
@@ -11,10 +11,10 @@
  *
  *	show() returns the current power state of the device. '0' indicates
  *	the device is on. Other values (1-3) indicate the device is in a low
- *	power state. 
+ *	power state.
  *
- *	store() sets the current power state, which is an integer value 
- *	between 0-3. If the device is on ('0'), and the value written is 
+ *	store() sets the current power state, which is an integer value
+ *	between 0-3. If the device is on ('0'), and the value written is
  *	greater than 0, then the device is placed directly into the low-power
  *	state (via its driver's ->suspend() method).
  *	If the device is currently in a low-power state, and the value is 0,
@@ -26,7 +26,7 @@
 
 static ssize_t state_show(struct device * dev, char * buf)
 {
-	return sprintf(buf,"%u\n",dev->power.power_state);
+	return sprintf(buf, "%u\n", dev->power.power_state);
 }
 
 static ssize_t state_store(struct device * dev, const char * buf, size_t n)
@@ -35,17 +35,17 @@
 	char * rest;
 	int error = 0;
 
-	state = simple_strtoul(buf,&rest,10);
+	state = simple_strtoul(buf, &rest, 10);
 	if (*rest)
 		return -EINVAL;
 	if (state)
-		error = dpm_runtime_suspend(dev,state);
+		error = dpm_runtime_suspend(dev, state);
 	else
 		dpm_runtime_resume(dev);
 	return error ? error : n;
 }
 
-static DEVICE_ATTR(state,0644,state_show,state_store);
+static DEVICE_ATTR(state, 0644, state_show, state_store);
 
 
 static struct attribute * power_attrs[] = {
@@ -59,10 +59,10 @@
 
 int dpm_sysfs_add(struct device * dev)
 {
-	return sysfs_create_group(&dev->kobj,&pm_attr_group);
+	return sysfs_create_group(&dev->kobj, &pm_attr_group);
 }
 
 void dpm_sysfs_remove(struct device * dev)
 {
-	sysfs_remove_group(&dev->kobj,&pm_attr_group);
+	sysfs_remove_group(&dev->kobj, &pm_attr_group);
 }
drivers/base/sys.c +51 -51

298 lines not on this page · raw message

#2 lore raw

PATCH 2/3 Suppress platform device suffixes

===================================================================

[email protected], 2004-06-08 23:46:49-05:00, [email protected]
sysfs: Do not add numeric suffix to platform device name if device
id is set to -1. This can be used when there can be only one instance of a device (like i8042).

 platform.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletion(-)

===================================================================

drivers/base/platform.c +4 -1
diff -Nru a/drivers/base/platform.c b/drivers/base/platform.c
@@ -33,7 +33,10 @@
 
 	pdev->dev.bus = &platform_bus_type;
 
-	snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s%u", pdev->name, pdev->id);
+	if (pdev->id != -1)
+		snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s%u", pdev->name, pdev->id);
+	else
+		strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE);
 
 	pr_debug("Registering platform device '%s'. Parent at %s\n",
 		 pdev->dev.bus_id, pdev->dev.parent->bus_id);
#3 lore raw

PATCH 3/3 Add platform_device_simple_release

===================================================================

[email protected], 2004-06-09 01:36:36-05:00, [email protected]
sysfs: add platform_device_simple_release that just frees memory
occupied by platform device. The function can be used by simple platform devices, when all resources except for memory can be deallocated beforehand. By having final release function in the driver core module can be unloaded without waiting for the last reference to the device to be dropped.

 drivers/base/platform.c |   21 +++++++++++++++++++++
 include/linux/device.h  |    1 +
 2 files changed, 22 insertions(+)

===================================================================

drivers/base/platform.c +21 -0
diff -Nru a/drivers/base/platform.c b/drivers/base/platform.c
@@ -43,12 +43,32 @@
 	return device_register(&pdev->dev);
 }
 
+/**
+ *	platform_device_unregister - remove a platform-level device
+ *	@dev:	platform device we're removing
+ *
+ */
 void platform_device_unregister(struct platform_device * pdev)
 {
 	if (pdev)
 		device_unregister(&pdev->dev);
 }
 
+/**
+ *	platform_device_simple_release - free a platform-level device
+ *	@dev:	platform device we're freeing
+ *
+ *	This canned release function can be used for simple platform
+ *	devices. By having the function outside of driver module it
+ *	can be unloaded without waiting for the device to be released
+ *	(provided that the device has been dynamically allocated).
+ */
+void platform_device_simple_release(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	kfree(pdev);
+}
 
 /**
  *	platform_match - bind platform device to platform driver.
@@ -117,3 +137,4 @@
 EXPORT_SYMBOL(platform_bus_type);
 EXPORT_SYMBOL(platform_device_register);
 EXPORT_SYMBOL(platform_device_unregister);
+EXPORT_SYMBOL(platform_device_simple_release);
include/linux/device.h +1 -0
diff -Nru a/include/linux/device.h b/include/linux/device.h
@@ -386,6 +386,7 @@
 
 extern int platform_device_register(struct platform_device *);
 extern void platform_device_unregister(struct platform_device *);
+extern void platform_device_simple_release(struct device *);
 
 extern struct bus_type platform_bus_type;
 extern struct device platform_bus;
#4 lore raw
In reply to Dmitry Torokhov
Quoted 9 lines · Dmitry Torokhov

Hi,

I am trying to add sysfs support to the serio subsystem and I would like you to consider the following changes:

- when registering platform device, if device id is set to -1, do not add it as a suffix to device's name. It can be used when there is only one device. The reason for change - i find that i80420 looks ugly, just i8042 is much better ;)

That sounds sane.

Quoted 4 lines

- create platform_device_simple_releasse function that would just free memory occupied by platform device. Having such release routine in core allows drivers implementing simple platform devices not wait in module unload code till last reference to the device is dropped.

I'm _very_ leary of applying this. It could be abused very badly (by putting the platform_device as the first object in the structure and relying on this function to kfree the whole thing.) So sorry, but no.

Unless you show me a real need for it..

And as for the whitespace cleanup, why? The lack of spaces seem to be something that the original author liked doing. There's nothing in the kernel coding style guidelines that really mention it that I can see.

So, care to just send me the name change patch against the latest tree?

thanks,

greg k-h

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 9 lines · Dmitry Torokhov

Actually, I myself want someting else -

int platform_device_register_simple(struct platform_device **ppdev,
const char *name, int id)

It will allocate platform device, set name and id and release function to platform_device_simple_release which in turn will be hidden from outside world. Since the function does allocation for user is should prevent the abuse you were concerned about.

Ok, that sounds good. I'll take patches for that kind of interface.

But have the function return the pointer, like the class_simple functions work. Not the ** like you just specified.

Quoted 10 lines
Quoted 6 lines

Unless you show me a real need for it..

And as for the whitespace cleanup, why? The lack of spaces seem to be something that the original author liked doing. There's nothing in the kernel coding style guidelines that really mention it that I can see.

If you check the files in question there were already both styles present (with and without spaces). And trailing whitespace looks bloody red in my vi ;) Will you accept just trailing whitespace cleanup?

Hm, ok, you are correct about the duplicate styles, ok, I'll take the whole cleanup. But things have changed in these files lately, and your patch doesn't apply :( Care to resend this against the latest -mm release which has all of the changes in it?

thanks,

greg k-h

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 12 lines · Dmitry Torokhov
Quoted 11 lines · Greg KH
Quoted 9 lines · Dmitry Torokhov

Actually, I myself want someting else -

int platform_device_register_simple(struct platform_device **ppdev,
const char *name, int id)

It will allocate platform device, set name and id and release function to platform_device_simple_release which in turn will be hidden from outside world. Since the function does allocation for user is should prevent the abuse you were concerned about.

Quoted 7 lines
Quoted 4 lines

Ok, that sounds good. I'll take patches for that kind of interface.

But have the function return the pointer, like the class_simple functions work. Not the ** like you just specified.

I want to do both allocation + registration in one shot and I knowing the error code may be important to users.

That's fine to do. Again, look at how the class_simple_create() function works. If an error happens, convert it to ERR_PTR() and return that. The caller can check it with IS_ERR() and friends.

Quoted 1 line

Why do you oppose having double pointers in interface?

It's messy, and with the ERR_PTR() macros, not needed :)

thanks,

greg k-h

#9 lore raw
Quoted 18 lines · Greg KH
Quoted 17 lines · Dmitry Torokhov
Quoted 15 lines · Greg KH
Quoted 9 lines · Dmitry Torokhov

Actually, I myself want someting else -

int platform_device_register_simple(struct platform_device **ppdev,
const char *name, int id)

It will allocate platform device, set name and id and release function to platform_device_simple_release which in turn will be hidden from outside world. Since the function does allocation for user is should prevent the abuse you were concerned about.

Ok, that sounds good. I'll take patches for that kind of interface.

But have the function return the pointer, like the class_simple functions work. Not the ** like you just specified.

Quoted 6 lines
Quoted 2 lines

I want to do both allocation + registration in one shot and I knowing the error code may be important to users.

That's fine to do. Again, look at how the class_simple_create() function works. If an error happens, convert it to ERR_PTR() and return that. The caller can check it with IS_ERR() and friends.

I apologize, I wrote above hastily, without looking at class_simple_create implementation.

Please take a look at the new version of patces. I changed the order so whitespace changes are on 3rd place to ease merging. The patches are against tonight's bk pull from Linus' tree.

There is also 4th patch that allows a device driver to register/unregister a new device on the same bus from driver's probe/remove routine. I need this functionality for implementing pass-through ports, I tried to work around sysfs limitation but it was too ugly for words.

Please let me know what you think.

Signature · 1 line
Dmitry
#10 lore raw

PATCH 1/3 Suppress platform device suffixes - take 2

===================================================================

[email protected], 2004-06-09 23:55:59-05:00, [email protected]
sysfs: Do not add numeric suffix to platform device name if device
id is set to -1. This can be used when there can be only one instance of a device (like i8042).

 platform.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletion(-)

===================================================================

drivers/base/platform.c +4 -1
diff -Nru a/drivers/base/platform.c b/drivers/base/platform.c
@@ -33,7 +33,10 @@
 
 	pdev->dev.bus = &platform_bus_type;
 	
-	snprintf(pdev->dev.bus_id,BUS_ID_SIZE,"%s%u",pdev->name,pdev->id);
+	if (pdev->id != -1)
+		snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s%u", pdev->name, pdev->id);
+	else
+		strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE);
 
 	pr_debug("Registering platform device '%s'. Parent at %s\n",
 		 pdev->dev.bus_id,pdev->dev.parent->bus_id);
#11 lore raw

PATCH 2/3 Add platform_device_register_simple

===================================================================

[email protected], 2004-06-09 23:58:52-05:00, [email protected]
sysfs: add platform_device_register_simple() that creates a simple
platform device that does not manage any resources. Modules using such platform devices can be unloaded without waiting for the device to me released (but any additional resources allocated by module should be freed beforehand).

 drivers/base/platform.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/device.h  |    1 
 2 files changed, 52 insertions(+)

===================================================================

drivers/base/platform.c +51 -0
diff -Nru a/drivers/base/platform.c b/drivers/base/platform.c
@@ -13,6 +13,7 @@
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/err.h>
 
 struct device platform_bus = {
 	.bus_id		= "platform",
@@ -43,10 +44,60 @@
 	return device_register(&pdev->dev);
 }
 
+
+/**
+ *	platform_device_unregister - remove a platform-level device
+ *	@dev:	platform device we're removing
+ *
+ */
 void platform_device_unregister(struct platform_device * pdev)
 {
 	if (pdev)
 		device_unregister(&pdev->dev);
+}
+
+
+static void platform_device_release_simple(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	kfree(pdev);
+}
+
+/**
+ *	platform_device_register_simple
+ *	@name:	base name of the device we're adding
+ *	@id:	instance id
+ *
+ *	This function creates a simple platform device that does not
+ *	manage any resources. By having release function in the driver
+ *	core modules that are using such devices can be unloaded without
+ *	waiting for the last reference to the device to be dropped.
+ */
+struct platform_device *platform_device_register_simple(char *name, unsigned int id)
+{
+	struct platform_device *pdev;
+	int retval;
+
+	pdev = kmalloc(sizeof(*pdev), GFP_KERNEL);
+	if (!pdev) {
+		retval = -ENOMEM;
+		goto error;
+	}
+
+	memset(pdev, 0, sizeof(*pdev));
+	pdev->name = name;
+	pdev->id = id;
+	pdev->dev.release = platform_device_release_simple;
+
+	retval = platform_device_register(pdev);
+	if (retval)
+		goto error;
+
+	return pdev;
+
+error:
+	kfree(pdev);
+	return ERR_PTR(retval);
 }
 
 
include/linux/device.h +1 -0
diff -Nru a/include/linux/device.h b/include/linux/device.h
@@ -386,6 +386,7 @@
 
 extern int platform_device_register(struct platform_device *);
 extern void platform_device_unregister(struct platform_device *);
+extern struct platform_device *platform_device_register_simple(char *, unsigned int);
 
 extern struct bus_type platform_bus_type;
 extern struct device platform_bus;
#12 lore raw

PATCH 3/3 Whitespace fixes

===================================================================

[email protected], 2004-06-10 00:07:32-05:00, [email protected]
Whitespace and formatting changes (a,b,c -> a, b, c) in drivers/base

 base.h           |    5 +-
 bus.c            |  125 +++++++++++++++++++++++++++----------------------------
 class.c          |   38 ++++++++--------
 class_simple.c   |   12 ++---
 core.c           |   46 ++++++++++----------
 driver.c         |   16 +++----
 firmware.c       |    6 +-
 firmware_class.c |   10 ++--
 init.c           |    4 -
 interface.c      |   18 +++----
 node.c           |   14 +++---
 platform.c       |   18 +++----
 power/main.c     |   14 +++---
 power/power.h    |    8 +--
 power/resume.c   |   12 ++---
 power/runtime.c  |    8 +--
 power/shutdown.c |   18 +++----
 power/suspend.c  |   42 +++++++++---------
 power/sysfs.c    |   18 +++----
 sys.c            |  102 ++++++++++++++++++++++----------------------
 20 files changed, 267 insertions(+), 267 deletions(-)

===================================================================

drivers/base/base.h +3 -2
diff -Nru a/drivers/base/base.h b/drivers/base/base.h
@@ -6,12 +6,13 @@
 
 static inline struct class_device *to_class_dev(struct kobject *obj)
 {
-	return container_of(obj,struct class_device,kobj);
+	return container_of(obj, struct class_device, kobj);
 }
+
 static inline
 struct class_device_attribute *to_class_dev_attr(struct attribute *_attr)
 {
-	return container_of(_attr,struct class_device_attribute,attr);
+	return container_of(_attr, struct class_device_attribute, attr);
 }
 
 
drivers/base/bus.c +62 -63

360 lines not on this page · raw message

drivers/base/class.c +19 -19
diff -Nru a/drivers/base/class.c b/drivers/base/class.c
@@ -5,7 +5,7 @@
  * Copyright (c) 2002-3 Open Source Development Labs
  * Copyright (c) 2003-2004 Greg Kroah-Hartman
  * Copyright (c) 2003-2004 IBM Corp.
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -17,8 +17,8 @@
 #include <linux/string.h>
 #include "base.h"
 
-#define to_class_attr(_attr) container_of(_attr,struct class_attribute,attr)
-#define to_class(obj) container_of(obj,struct class,subsys.kset.kobj)
+#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
+#define to_class(obj) container_of(obj, struct class, subsys.kset.kobj)
 
 static ssize_t
 class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
@@ -28,12 +28,12 @@
 	ssize_t ret = 0;
 
 	if (class_attr->show)
-		ret = class_attr->show(dc,buf);
+		ret = class_attr->show(dc, buf);
 	return ret;
 }
 
 static ssize_t
-class_attr_store(struct kobject * kobj, struct attribute * attr, 
+class_attr_store(struct kobject * kobj, struct attribute * attr,
 		 const char * buf, size_t count)
 {
 	struct class_attribute * class_attr = to_class_attr(attr);
@@ -41,7 +41,7 @@
 	ssize_t ret = 0;
 
 	if (class_attr->store)
-		ret = class_attr->store(dc,buf,count);
+		ret = class_attr->store(dc, buf, count);
 	return ret;
 }
 
@@ -69,14 +69,14 @@
 };
 
 /* Hotplug events for classes go to the class_obj subsys */
-static decl_subsys(class,&ktype_class,NULL);
+static decl_subsys(class, &ktype_class, NULL);
 
 
 int class_create_file(struct class * cls, const struct class_attribute * attr)
 {
 	int error;
 	if (cls) {
-		error = sysfs_create_file(&cls->subsys.kset.kobj,&attr->attr);
+		error = sysfs_create_file(&cls->subsys.kset.kobj, &attr->attr);
 	} else
 		error = -EINVAL;
 	return error;
@@ -85,13 +85,13 @@
 void class_remove_file(struct class * cls, const struct class_attribute * attr)
 {
 	if (cls)
-		sysfs_remove_file(&cls->subsys.kset.kobj,&attr->attr);
+		sysfs_remove_file(&cls->subsys.kset.kobj, &attr->attr);
 }
 
 struct class * class_get(struct class * cls)
 {
 	if (cls)
-		return container_of(subsys_get(&cls->subsys),struct class,subsys);
+		return container_of(subsys_get(&cls->subsys), struct class, subsys);
 	return NULL;
 }
 
@@ -104,15 +104,15 @@
 {
 	int error;
 
-	pr_debug("device class '%s': registering\n",cls->name);
+	pr_debug("device class '%s': registering\n", cls->name);
 
 	INIT_LIST_HEAD(&cls->children);
 	INIT_LIST_HEAD(&cls->interfaces);
-	error = kobject_set_name(&cls->subsys.kset.kobj,cls->name);
+	error = kobject_set_name(&cls->subsys.kset.kobj, cls->name);
 	if (error)
 		return error;
 
-	subsys_set_kset(cls,class_subsys);
+	subsys_set_kset(cls, class_subsys);
 
 	error = subsystem_register(&cls->subsys);
 	if (error)
@@ -123,7 +123,7 @@
 
 void class_unregister(struct class * cls)
 {
-	pr_debug("device class '%s': unregistering\n",cls->name);
+	pr_debug("device class '%s': unregistering\n", cls->name);
 	subsystem_unregister(&cls->subsys);
 }
 
@@ -181,12 +181,12 @@
 	ssize_t ret = 0;
 
 	if (class_dev_attr->show)
-		ret = class_dev_attr->show(cd,buf);
+		ret = class_dev_attr->show(cd, buf);
 	return ret;
 }
 
 static ssize_t
-class_device_attr_store(struct kobject * kobj, struct attribute * attr, 
+class_device_attr_store(struct kobject * kobj, struct attribute * attr,
 			const char * buf, size_t count)
 {
 	struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
@@ -194,7 +194,7 @@
 	ssize_t ret = 0;
 
 	if (class_dev_attr->store)
-		ret = class_dev_attr->store(cd,buf,count);
+		ret = class_dev_attr->store(cd, buf, count);
 	return ret;
 }
 
@@ -208,7 +208,7 @@
 	struct class_device *cd = to_class_dev(kobj);
 	struct class * cls = cd->class;
 
-	pr_debug("device class '%s': release.\n",cd->class_id);
+	pr_debug("device class '%s': release.\n", cd->class_id);
 
 	if (cls->release)
 		cls->release(cd);
@@ -344,7 +344,7 @@
 
 	class_device_dev_unlink(class_dev);
 	class_device_driver_unlink(class_dev);
-	
+
 	kobject_del(&class_dev->kobj);
 
 	if (parent)
drivers/base/class_simple.c +6 -6
diff -Nru a/drivers/base/class_simple.c b/drivers/base/class_simple.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2003-2004 Greg Kroah-Hartman <[email protected]>
  * Copyright (c) 2003-2004 IBM Corp.
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -111,7 +111,7 @@
 
 /**
  * class_simple_device_add - adds a class device to sysfs for a character driver
- * @cs: pointer to the struct class_simple that this device should be registered to.  
+ * @cs: pointer to the struct class_simple that this device should be registered to.
  * @dev: the dev_t for the device to be added.
  * @device: a pointer to a struct device that is assiociated with this class device.
  * @fmt: string for the class device's name
@@ -146,8 +146,8 @@
 	s_dev->dev = dev;
 	s_dev->class_dev.dev = device;
 	s_dev->class_dev.class = &cs->class;
-	
-	va_start(args,fmt);
+
+	va_start(args, fmt);
 	vsnprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, fmt, args);
 	va_end(args);
 	retval = class_device_register(&s_dev->class_dev);
@@ -173,10 +173,10 @@
  * @cs: pointer to the struct class_simple to hold the pointer
  * @hotplug: function pointer to the hotplug function
  *
- * Implement and set a hotplug function to add environment variables specific to this 
+ * Implement and set a hotplug function to add environment variables specific to this
  * class on the hotplug event.
  */
-int class_simple_set_hotplug(struct class_simple *cs, 
+int class_simple_set_hotplug(struct class_simple *cs,
 	int (*hotplug)(struct class_device *dev, char **envp, int num_envp, char *buffer, int buffer_size))
 {
 	if ((cs == NULL) || (IS_ERR(cs)))
drivers/base/core.c +23 -23

150 lines not on this page · raw message

drivers/base/driver.c +8 -8
diff -Nru a/drivers/base/driver.c b/drivers/base/driver.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -15,8 +15,8 @@
 #include <linux/string.h>
 #include "base.h"
 
-#define to_dev(node) container_of(node,struct device,driver_list)
-#define to_drv(obj) container_of(obj,struct device_driver,kobj)
+#define to_dev(node) container_of(node, struct device, driver_list)
+#define to_drv(obj) container_of(obj, struct device_driver, kobj)
 
 /**
  *	driver_create_file - create sysfs file for driver.
@@ -28,7 +28,7 @@
 {
 	int error;
 	if (get_driver(drv)) {
-		error = sysfs_create_file(&drv->kobj,&attr->attr);
+		error = sysfs_create_file(&drv->kobj, &attr->attr);
 		put_driver(drv);
 	} else
 		error = -EINVAL;
@@ -45,7 +45,7 @@
 void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr)
 {
 	if (get_driver(drv)) {
-		sysfs_remove_file(&drv->kobj,&attr->attr);
+		sysfs_remove_file(&drv->kobj, &attr->attr);
 		put_driver(drv);
 	}
 }
@@ -76,7 +76,7 @@
  *	@drv:	driver to register
  *
  *	We pass off most of the work to the bus_add_driver() call,
- *	since most of the things we have to do deal with the bus 
+ *	since most of the things we have to do deal with the bus
  *	structures.
  *
  *	The one interesting aspect is that we initialize @drv->unload_sem
@@ -99,8 +99,8 @@
  *
  *	Though, once that is done, we attempt to take @drv->unload_sem.
  *	This will block until the driver refcount reaches 0, and it is
- *	released. Only modular drivers will call this function, and we 
- *	have to guarantee that it won't complete, letting the driver 
+ *	released. Only modular drivers will call this function, and we
+ *	have to guarantee that it won't complete, letting the driver
  *	unload until all references are gone.
  */
 
drivers/base/firmware.c +3 -3
diff -Nru a/drivers/base/firmware.c b/drivers/base/firmware.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -12,11 +12,11 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
-static decl_subsys(firmware,NULL,NULL);
+static decl_subsys(firmware, NULL, NULL);
 
 int firmware_register(struct subsystem * s)
 {
-	kset_set_kset_s(s,firmware_subsys);
+	kset_set_kset_s(s, firmware_subsys);
 	return subsystem_register(s);
 }
 
drivers/base/firmware_class.c +5 -5
diff -Nru a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
@@ -68,7 +68,7 @@
  *	firmware will be provided.
  *
  *	Note: zero means 'wait for ever'
- *  
+ *
  **/
 static ssize_t
 firmware_timeout_store(struct class *class, const char *buf, size_t count)
@@ -121,7 +121,7 @@
 /**
  * firmware_loading_store: - loading control file
  * Description:
- *	The relevant values are: 
+ *	The relevant values are:
  *
  *	 1: Start a load, discarding any previous partial load.
  *	 0: Conclude the load and handle the data to the driver code.
@@ -376,7 +376,7 @@
 	return retval;
 }
 
-/** 
+/**
  * request_firmware: - request firmware to hotplug and wait for it
  * Description:
  *	@firmware will be used to return a firmware image by the name
@@ -457,7 +457,7 @@
 
 /**
  * register_firmware: - provide a firmware image for later usage
- * 
+ *
  * Description:
  *	Make sure that @data will be available by requesting firmware @name.
  *
@@ -541,7 +541,7 @@
 
 	ret = kernel_thread(request_firmware_work_func, fw_work,
 			    CLONE_FS | CLONE_FILES);
-	
+
 	if (ret < 0) {
 		fw_work->cont(NULL, fw_work->context);
 		return ret;
drivers/base/init.c +2 -2
diff -Nru a/drivers/base/init.c b/drivers/base/init.c
@@ -2,7 +2,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -33,7 +33,7 @@
 	classes_init();
 	firmware_init();
 
-	/* These are also core pieces, but must come after the 
+	/* These are also core pieces, but must come after the
 	 * core core pieces.
 	 */
 	platform_bus_init();
drivers/base/interface.c +9 -9
diff -Nru a/drivers/base/interface.c b/drivers/base/interface.c
@@ -1,10 +1,10 @@
 /*
- * drivers/base/interface.c - common driverfs interface that's exported to 
+ * drivers/base/interface.c - common driverfs interface that's exported to
  * 	the world for all devices.
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -16,33 +16,33 @@
 
 /**
  *	detach_state - control the default power state for the device.
- *	
- *	This is the state the device enters when it's driver module is 
+ *
+ *	This is the state the device enters when it's driver module is
  *	unloaded. The value is an unsigned integer, in the range of 0-4.
  *	'0' indicates 'On', so no action will be taken when the driver is
  *	unloaded. This is the default behavior.
  *	'4' indicates 'Off', meaning the driver core will call the driver's
  *	shutdown method to quiesce the device.
- *	1-3 indicate a low-power state for the device to enter via the 
- *	driver's suspend method. 
+ *	1-3 indicate a low-power state for the device to enter via the
+ *	driver's suspend method.
  */
 
 static ssize_t detach_show(struct device * dev, char * buf)
 {
-	return sprintf(buf,"%u\n",dev->detach_state);
+	return sprintf(buf, "%u\n", dev->detach_state);
 }
 
 static ssize_t detach_store(struct device * dev, const char * buf, size_t n)
 {
 	u32 state;
-	state = simple_strtoul(buf,NULL,10);
+	state = simple_strtoul(buf, NULL, 10);
 	if (state > 4)
 		return -EINVAL;
 	dev->detach_state = state;
 	return n;
 }
 
-static DEVICE_ATTR(detach_state,0644,detach_show,detach_store);
+static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store);
 
 
 struct attribute * dev_default_attrs[] = {
drivers/base/node.c +7 -7
diff -Nru a/drivers/base/node.c b/drivers/base/node.c
@@ -29,7 +29,7 @@
 	return len;
 }
 
-static SYSDEV_ATTR(cpumap,S_IRUGO,node_read_cpumap,NULL);
+static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumap, NULL);
 
 /* Can be overwritten by architecture specific code. */
 int __attribute__((weak)) hugetlb_report_node_meminfo(int node, char *buf)
@@ -54,17 +54,17 @@
 		       "Node %d LowFree:      %8lu kB\n",
 		       nid, K(i.totalram),
 		       nid, K(i.freeram),
-		       nid, K(i.totalram-i.freeram),
+		       nid, K(i.totalram - i.freeram),
 		       nid, K(i.totalhigh),
 		       nid, K(i.freehigh),
-		       nid, K(i.totalram-i.totalhigh),
-		       nid, K(i.freeram-i.freehigh));
+		       nid, K(i.totalram - i.totalhigh),
+		       nid, K(i.freeram - i.freehigh));
 	n += hugetlb_report_node_meminfo(nid, buf + n);
 	return n;
 }
 
-#undef K 
-static SYSDEV_ATTR(meminfo,S_IRUGO,node_read_meminfo,NULL);
+#undef K
+static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
 
 static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
 {
@@ -104,7 +104,7 @@
 		       local_node,
 		       other_node);
 }
-static SYSDEV_ATTR(numastat,S_IRUGO,node_read_numastat,NULL);
+static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
 
 /*
  * register_node - Setup a driverfs device for a node.
drivers/base/platform.c +9 -9
diff -Nru a/drivers/base/platform.c b/drivers/base/platform.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2002-3 Patrick Mochel
  * Copyright (c) 2002-3 Open Source Development Labs
- * 
+ *
  * This file is released under the GPLv2
  *
  * Please see Documentation/driver-model/platform.txt for more
@@ -33,14 +33,14 @@
 		pdev->dev.parent = &platform_bus;
 
 	pdev->dev.bus = &platform_bus_type;
-	
+
 	if (pdev->id != -1)
 		snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s%u", pdev->name, pdev->id);
 	else
 		strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE);
 
 	pr_debug("Registering platform device '%s'. Parent at %s\n",
-		 pdev->dev.bus_id,pdev->dev.parent->bus_id);
+		 pdev->dev.bus_id, pdev->dev.parent->bus_id);
 	return device_register(&pdev->dev);
 }
 
@@ -106,13 +106,13 @@
  *	@dev:	device.
  *	@drv:	driver.
  *
- *	Platform device IDs are assumed to be encoded like this: 
- *	"<name><instance>", where <name> is a short description of the 
- *	type of device, like "pci" or "floppy", and <instance> is the 
+ *	Platform device IDs are assumed to be encoded like this:
+ *	"<name><instance>", where <name> is a short description of the
+ *	type of device, like "pci" or "floppy", and <instance> is the
  *	enumerated instance of the device, like '0' or '42'.
- *	Driver IDs are simply "<name>". 
- *	So, extract the <name> from the platform_device structure, 
- *	and compare it against the name of the driver. Return whether 
+ *	Driver IDs are simply "<name>".
+ *	So, extract the <name> from the platform_device structure,
+ *	and compare it against the name of the driver. Return whether
  *	they match or not.
  */
 
drivers/base/power/main.c +7 -7
diff -Nru a/drivers/base/power/main.c b/drivers/base/power/main.c
@@ -12,10 +12,10 @@
  * and add it to the list of power-controlled devices. sysfs entries for
  * controlling device power management will also be added.
  *
- * A different set of lists than the global subsystem list are used to 
- * keep track of power info because we use different lists to hold 
- * devices based on what stage of the power management process they 
- * are in. The power domain dependencies may also differ from the 
+ * A different set of lists than the global subsystem list are used to
+ * keep track of power info because we use different lists to hold
+ * devices based on what stage of the power management process they
+ * are in. The power domain dependencies may also differ from the
  * ancestral dependencies that the subsystem list maintains.
  */
 
@@ -74,10 +74,10 @@
 
 	pr_debug("PM: Adding info for %s:%s\n",
 		 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);
-	atomic_set(&dev->power.pm_users,0);
+	atomic_set(&dev->power.pm_users, 0);
 	down(&dpm_sem);
-	list_add_tail(&dev->power.entry,&dpm_active);
-	device_pm_set_parent(dev,dev->parent);
+	list_add_tail(&dev->power.entry, &dpm_active);
+	device_pm_set_parent(dev, dev->parent);
 	if ((error = dpm_sysfs_add(dev)))
 		list_del(&dev->power.entry);
 	up(&dpm_sem);
drivers/base/power/power.h +4 -4
diff -Nru a/drivers/base/power/power.h b/drivers/base/power/power.h
@@ -27,7 +27,7 @@
  */
 extern struct semaphore dpm_sem;
 
-/* 
+/*
  * The PM lists.
  */
 extern struct list_head dpm_active;
@@ -37,12 +37,12 @@
 
 static inline struct dev_pm_info * to_pm_info(struct list_head * entry)
 {
-	return container_of(entry,struct dev_pm_info,entry);
+	return container_of(entry, struct dev_pm_info, entry);
 }
 
 static inline struct device * to_device(struct list_head * entry)
 {
-	return container_of(to_pm_info(entry),struct device,power);
+	return container_of(to_pm_info(entry), struct device, power);
 }
 
 extern int device_pm_add(struct device *);
@@ -56,7 +56,7 @@
 extern void dpm_sysfs_remove(struct device *);
 
 /*
- * resume.c 
+ * resume.c
  */
 
 extern void dpm_resume(void);
drivers/base/power/resume.c +6 -6
diff -Nru a/drivers/base/power/resume.c b/drivers/base/power/resume.c
@@ -39,7 +39,7 @@
 		if (!dev->power.prev_state)
 			resume_device(dev);
 
-		list_add_tail(entry,&dpm_active);
+		list_add_tail(entry, &dpm_active);
 	}
 }
 
@@ -48,7 +48,7 @@
  *	device_resume - Restore state of each device in system.
  *
  *	Walk the dpm_off list, remove each entry, resume the device,
- *	then add it to the dpm_active list. 
+ *	then add it to the dpm_active list.
  */
 
 void device_resume(void)
@@ -62,14 +62,14 @@
 
 
 /**
- *	device_power_up_irq - Power on some devices. 
+ *	device_power_up_irq - Power on some devices.
  *
- *	Walk the dpm_off_irq list and power each device up. This 
+ *	Walk the dpm_off_irq list and power each device up. This
  *	is used for devices that required they be powered down with
  *	interrupts disabled. As devices are powered on, they are moved to
  *	the dpm_suspended list.
  *
- *	Interrupts must be disabled when calling this. 
+ *	Interrupts must be disabled when calling this.
  */
 
 void dpm_power_up(void)
@@ -78,7 +78,7 @@
 		struct list_head * entry = dpm_off_irq.next;
 		list_del_init(entry);
 		resume_device(to_device(entry));
-		list_add_tail(entry,&dpm_active);
+		list_add_tail(entry, &dpm_active);
 	}
 }
 
drivers/base/power/runtime.c +4 -4
diff -Nru a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
@@ -24,9 +24,9 @@
  *	dpm_runtime_resume - Power one device back on.
  *	@dev:	Device.
  *
- *	Bring one device back to the on state by first powering it 
+ *	Bring one device back to the on state by first powering it
  *	on, then restoring state. We only operate on devices that aren't
- *	already on. 
+ *	already on.
  *	FIXME: We need to handle devices that are in an unknown state.
  */
 
@@ -55,7 +55,7 @@
 	if (dev->power.power_state)
 		runtime_resume(dev);
 
-	if (!(error = suspend_device(dev,state)))
+	if (!(error = suspend_device(dev, state)))
 		dev->power.power_state = state;
  Done:
 	up(&dpm_sem);
@@ -70,7 +70,7 @@
  *
  *	This is an update mechanism for drivers to notify the core
  *	what power state a device is in. Device probing code may not
- *	always be able to tell, but we need accurate information to 
+ *	always be able to tell, but we need accurate information to
  *	work reliably.
  */
 void dpm_set_power_state(struct device * dev, u32 state)
drivers/base/power/shutdown.c +9 -9
diff -Nru a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
@@ -1,9 +1,9 @@
 /*
  * shutdown.c - power management functions for the device tree.
- * 
+ *
  * Copyright (c) 2002-3 Patrick Mochel
  *		 2002-3 Open Source Development Lab
- * 
+ *
  * This file is released under the GPLv2
  *
  */
@@ -14,7 +14,7 @@
 
 #include "power.h"
 
-#define to_dev(node) container_of(node,struct device,kobj.entry)
+#define to_dev(node) container_of(node, struct device, kobj.entry)
 
 extern struct subsystem devices_subsys;
 
@@ -29,7 +29,7 @@
 			dev->driver->shutdown(dev);
 		return 0;
 	}
-	return dpm_runtime_suspend(dev,dev->detach_state);
+	return dpm_runtime_suspend(dev, dev->detach_state);
 }
 
 
@@ -38,8 +38,8 @@
  * down last and resume them first. That way, we don't do anything stupid like
  * shutting down the interrupt controller before any devices..
  *
- * Note that there are not different stages for power management calls - 
- * they only get one called once when interrupts are disabled. 
+ * Note that there are not different stages for power management calls -
+ * they only get one called once when interrupts are disabled.
  */
 
 extern int sysdev_shutdown(void);
@@ -50,10 +50,10 @@
 void device_shutdown(void)
 {
 	struct device * dev;
-	
+
 	down_write(&devices_subsys.rwsem);
-	list_for_each_entry_reverse(dev,&devices_subsys.kset.list,kobj.entry) {
-		pr_debug("shutting down %s: ",dev->bus_id);
+	list_for_each_entry_reverse(dev, &devices_subsys.kset.list, kobj.entry) {
+		pr_debug("shutting down %s: ", dev->bus_id);
 		if (dev->driver && dev->driver->shutdown) {
 			pr_debug("Ok\n");
 			dev->driver->shutdown(dev);
drivers/base/power/suspend.c +21 -21

99 lines not on this page · raw message

drivers/base/power/sysfs.c +9 -9
diff -Nru a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
@@ -11,10 +11,10 @@
  *
  *	show() returns the current power state of the device. '0' indicates
  *	the device is on. Other values (1-3) indicate the device is in a low
- *	power state. 
+ *	power state.
  *
- *	store() sets the current power state, which is an integer value 
- *	between 0-3. If the device is on ('0'), and the value written is 
+ *	store() sets the current power state, which is an integer value
+ *	between 0-3. If the device is on ('0'), and the value written is
  *	greater than 0, then the device is placed directly into the low-power
  *	state (via its driver's ->suspend() method).
  *	If the device is currently in a low-power state, and the value is 0,
@@ -26,7 +26,7 @@
 
 static ssize_t state_show(struct device * dev, char * buf)
 {
-	return sprintf(buf,"%u\n",dev->power.power_state);
+	return sprintf(buf, "%u\n", dev->power.power_state);
 }
 
 static ssize_t state_store(struct device * dev, const char * buf, size_t n)
@@ -35,17 +35,17 @@
 	char * rest;
 	int error = 0;
 
-	state = simple_strtoul(buf,&rest,10);
+	state = simple_strtoul(buf, &rest, 10);
 	if (*rest)
 		return -EINVAL;
 	if (state)
-		error = dpm_runtime_suspend(dev,state);
+		error = dpm_runtime_suspend(dev, state);
 	else
 		dpm_runtime_resume(dev);
 	return error ? error : n;
 }
 
-static DEVICE_ATTR(state,0644,state_show,state_store);
+static DEVICE_ATTR(state, 0644, state_show, state_store);
 
 
 static struct attribute * power_attrs[] = {
@@ -59,10 +59,10 @@
 
 int dpm_sysfs_add(struct device * dev)
 {
-	return sysfs_create_group(&dev->kobj,&pm_attr_group);
+	return sysfs_create_group(&dev->kobj, &pm_attr_group);
 }
 
 void dpm_sysfs_remove(struct device * dev)
 {
-	sysfs_remove_group(&dev->kobj,&pm_attr_group);
+	sysfs_remove_group(&dev->kobj, &pm_attr_group);
 }
drivers/base/sys.c +51 -51

298 lines not on this page · raw message

#13 lore raw

[PATCH 4/3] Allow registering device without taking bus lock

===================================================================

[email protected], 2004-06-10 00:10:02-05:00, [email protected]
sysfs: provide means for adding and removing devices to a bus without
taking bus' semaphore so devices can be added/removed from driver's probe() and remove() methods.

 drivers/base/base.h    |    4 ++--
 drivers/base/bus.c     |   48 +++++++++++++++++++++++++++++++++++++++++-------
 drivers/base/core.c    |   46 ++++++++++++++++++++++++++++++++--------------
 include/linux/device.h |   31 ++++++++++++++++++++++++++-----
 4 files changed, 101 insertions(+), 28 deletions(-)

===================================================================

drivers/base/base.h +2 -2
diff -Nru a/drivers/base/base.h b/drivers/base/base.h
@@ -1,5 +1,5 @@
-extern int bus_add_device(struct device * dev);
-extern void bus_remove_device(struct device * dev);
+extern int bus_add_device(struct device * dev, int lock);
+extern void bus_remove_device(struct device * dev, int lock);
 
 extern int bus_add_driver(struct device_driver *);
 extern void bus_remove_driver(struct device_driver *);
drivers/base/bus.c +41 -7

84 lines not on this page · raw message

drivers/base/core.c +32 -14

124 lines not on this page · raw message

include/linux/device.h +26 -5
diff -Nru a/include/linux/device.h b/include/linux/device.h
@@ -316,16 +316,37 @@
 /*
  * High level routines for use by the bus drivers
  */
-extern int device_register(struct device * dev);
-extern void device_unregister(struct device * dev);
+extern int __device_register(struct device * dev, int lock);
+static inline int device_register(struct device * dev)
+{
+	return __device_register(dev, 1);
+}
+
+extern void __device_unregister(struct device * dev, int lock);
+static inline void device_unregister(struct device * dev)
+{
+	__device_unregister(dev, 1);
+}
+
 extern void device_initialize(struct device * dev);
-extern int device_add(struct device * dev);
-extern void device_del(struct device * dev);
+
+extern int __device_add(struct device * dev, int lock);
+static inline int device_add(struct device * dev)
+{
+	return __device_add(dev, 1);
+}
+
+extern void __device_del(struct device * dev, int lock);
+static inline void device_del(struct device * dev)
+{
+	__device_del(dev, 1);
+}
+
 extern int device_for_each_child(struct device *, void *,
 		     int (*fn)(struct device *, void *));
 
 /*
- * Manual binding of a device to driver. See drivers/base/bus.c 
+ * Manual binding of a device to driver. See drivers/base/bus.c
  * for information on use.
  */
 extern void device_bind_driver(struct device * dev);
#14 lore raw

Re: [PATCH 4/3] Allow registering device without taking bus lock

Quoted 4 lines · Dmitry Torokhov

[email protected], 2004-06-10 00:10:02-05:00, [email protected]
sysfs: provide means for adding and removing devices to a bus without
taking bus' semaphore so devices can be added/removed from driver's probe() and remove() methods.

Eww. Why can't you do the same as PCMCIA and register/remove in a separate thread?

Really though, lets not introduce this hacky solution, but come up with a way to do it cleanly so PCMCIA doesn't have this problem either.

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#15 lore raw

Re: [PATCH 4/3] Allow registering device without taking bus lock

In reply to Dmitry Torokhov
Quoted 4 lines · Dmitry Torokhov

[email protected], 2004-06-10 00:10:02-05:00, [email protected]
sysfs: provide means for adding and removing devices to a bus without
taking bus' semaphore so devices can be added/removed from driver's probe() and remove() methods.

Ick, no, sorry, I will not take this.

For now (2.6), do what others do and add the devices from another thread, or somthing else.

We will revisit this in 2.7 to make it a sane solution.

Sorry,

greg k-h

#16 lore raw

Re: [PATCH 3/3] Whitespace fixes

In reply to Dmitry Torokhov
Quoted 8 lines · Dmitry Torokhov

===================================================================

[email protected], 2004-06-10 00:07:32-05:00, [email protected]
Whitespace and formatting changes (a,b,c -> a, b, c) in drivers/base

Ok, I've applied the majority of this patch. But the bus.c and class.c files are different in my tree than in Linus's right now, so I'll apply those sections by hand and fix up the rejects in a separate changeset.

thanks again.

greg k-h

#17 lore raw

Re: [PATCH 2/3] Add platform_device_register_simple

In reply to Dmitry Torokhov
Quoted 6 lines · Dmitry Torokhov

[email protected], 2004-06-09 23:58:52-05:00, [email protected]
sysfs: add platform_device_register_simple() that creates a simple
platform device that does not manage any resources. Modules using such platform devices can be unloaded without waiting for the device to me released (but any additional resources allocated by module should be freed beforehand).

What about platform devices which have resources associated with them?

Quoted 15 lines
drivers/base/platform.c +15 -0
+struct platform_device *platform_device_register_simple(char *name, unsigned int id)
+{
+	struct platform_device *pdev;
+	int retval;
+
+	pdev = kmalloc(sizeof(*pdev), GFP_KERNEL);
+	if (!pdev) {
+		retval = -ENOMEM;
+		goto error;
+	}
+
+	memset(pdev, 0, sizeof(*pdev));
+	pdev->name = name;
+	pdev->id = id;
+	pdev->dev.release = platform_device_release_simple;

drivers/base/platform.c line 100

Quoted 10 lines
drivers/base/platform.c +10 -0
+
+	retval = platform_device_register(pdev);
+	if (retval)
+		goto error;
+
+	return pdev;
+
+error:
+	kfree(pdev);
+	return ERR_PTR(retval);

As this currently stands, you have no chance to add resources to the platform device before it's made available to the driver. It's likely that any attached resources will have the same lifetime as the device itself, so it makes sense to allocate them together with the platform device.

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw

Re: [PATCH 2/3] Add platform_device_register_simple

Quoted 9 lines · Dmitry Torokhov
Quoted 7 lines · Russell King

As this currently stands, you have no chance to add resources to the platform device before it's made available to the driver. It's likely that any attached resources will have the same lifetime as the device itself, so it makes sense to allocate them together with the platform device.

Quoted 3 lines

Are you suggesting adding pointer to resources as a 3rd argument and automotically release it for the user? It probably could be done but users will be tempted to use static module data and bad things would happen.

Please read my second sentence again. It implies a copy of the resources is kept with the platform device, so both have the same lifetime.

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#20 lore raw

Re: [PATCH 2/3] Add platform_device_register_simple

In reply to Dmitry Torokhov
Quoted 10 lines · Dmitry Torokhov

===================================================================

[email protected], 2004-06-09 23:58:52-05:00, [email protected]
sysfs: add platform_device_register_simple() that creates a simple
platform device that does not manage any resources. Modules using such platform devices can be unloaded without waiting for the device to me released (but any additional resources allocated by module should be freed beforehand).

I have the same objections to this that Russell does. Also, care to show me a patch that uses this new interface, so that I can understand what you are trying to accomplish here?

thanks,

greg k-h

Applied
#21 lore raw

Re: [PATCH 1/3] Suppress platform device suffixes - take 2

In reply to Dmitry Torokhov
Quoted 10 lines · Dmitry Torokhov

===================================================================

[email protected], 2004-06-09 23:55:59-05:00, [email protected]
sysfs: Do not add numeric suffix to platform device name if device
id is set to -1. This can be used when there can be only one instance of a device (like i8042).

Applied, thanks.

greg k-h