Commit 6de3d58d authored by Linus Torvalds's avatar Linus Torvalds

Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6:
  klist: fix coding style errors in klist.h and klist.c
  driver core: remove no longer used "struct class_device"
  pcmcia: remove pccard_sysfs_interface warnings
  devres: support addresses greater than an unsigned long via dev_ioremap
  kobject: do not copy vargs, just pass them around
  sysfs: sysfs_update_group stub for CONFIG_SYSFS=n
  DEBUGFS: Correct location of debugfs API documentation.
  driver core: warn about duplicate driver names on the same bus
  klist: implement klist_add_{after|before}()
  klist: implement KLIST_INIT() and DEFINE_KLIST()
  sysfs: Disallow truncation of files in sysfs
parents e0066c4e c3bb7fad
...@@ -64,17 +64,6 @@ extern void sysdev_shutdown(void); ...@@ -64,17 +64,6 @@ extern void sysdev_shutdown(void);
extern int sysdev_suspend(pm_message_t state); extern int sysdev_suspend(pm_message_t state);
extern int sysdev_resume(void); extern int sysdev_resume(void);
static inline struct class_device *to_class_dev(struct kobject *obj)
{
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);
}
extern char *make_class_name(const char *name, struct kobject *kobj); extern char *make_class_name(const char *name, struct kobject *kobj);
extern int devres_release_all(struct device *dev); extern int devres_release_all(struct device *dev);
......
This diff is collapsed.
...@@ -217,12 +217,22 @@ static void driver_remove_groups(struct device_driver *drv, ...@@ -217,12 +217,22 @@ static void driver_remove_groups(struct device_driver *drv,
int driver_register(struct device_driver *drv) int driver_register(struct device_driver *drv)
{ {
int ret; int ret;
struct device_driver *other;
if ((drv->bus->probe && drv->probe) || if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) || (drv->bus->remove && drv->remove) ||
(drv->bus->shutdown && drv->shutdown)) (drv->bus->shutdown && drv->shutdown))
printk(KERN_WARNING "Driver '%s' needs updating - please use " printk(KERN_WARNING "Driver '%s' needs updating - please use "
"bus_type methods\n", drv->name); "bus_type methods\n", drv->name);
other = driver_find(drv->name, drv->bus);
if (other) {
put_driver(other);
printk(KERN_ERR "Error: Driver '%s' is already registered, "
"aborting...\n", drv->name);
return -EEXIST;
}
ret = bus_add_driver(drv); ret = bus_add_driver(drv);
if (ret) if (ret)
return ret; return ret;
......
...@@ -652,6 +652,9 @@ static int pccardd(void *__skt) ...@@ -652,6 +652,9 @@ static int pccardd(void *__skt)
complete(&skt->thread_done); complete(&skt->thread_done);
return 0; return 0;
} }
ret = pccard_sysfs_add_socket(&skt->dev);
if (ret)
dev_warn(&skt->dev, "err %d adding socket attributes\n", ret);
add_wait_queue(&skt->thread_wait, &wait); add_wait_queue(&skt->thread_wait, &wait);
complete(&skt->thread_done); complete(&skt->thread_done);
...@@ -694,6 +697,7 @@ static int pccardd(void *__skt) ...@@ -694,6 +697,7 @@ static int pccardd(void *__skt)
remove_wait_queue(&skt->thread_wait, &wait); remove_wait_queue(&skt->thread_wait, &wait);
/* remove from the device core */ /* remove from the device core */
pccard_sysfs_remove_socket(&skt->dev);
device_unregister(&skt->dev); device_unregister(&skt->dev);
return 0; return 0;
...@@ -940,20 +944,13 @@ EXPORT_SYMBOL(pcmcia_socket_class); ...@@ -940,20 +944,13 @@ EXPORT_SYMBOL(pcmcia_socket_class);
static int __init init_pcmcia_cs(void) static int __init init_pcmcia_cs(void)
{ {
int ret;
init_completion(&pcmcia_unload); init_completion(&pcmcia_unload);
ret = class_register(&pcmcia_socket_class); return class_register(&pcmcia_socket_class);
if (ret)
return (ret);
return class_interface_register(&pccard_sysfs_interface);
} }
static void __exit exit_pcmcia_cs(void) static void __exit exit_pcmcia_cs(void)
{ {
class_interface_unregister(&pccard_sysfs_interface);
class_unregister(&pcmcia_socket_class); class_unregister(&pcmcia_socket_class);
wait_for_completion(&pcmcia_unload); wait_for_completion(&pcmcia_unload);
} }
......
...@@ -121,7 +121,8 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, ...@@ -121,7 +121,8 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
void release_resource_db(struct pcmcia_socket *s); void release_resource_db(struct pcmcia_socket *s);
/* In socket_sysfs.c */ /* In socket_sysfs.c */
extern struct class_interface pccard_sysfs_interface; extern int pccard_sysfs_add_socket(struct device *dev);
extern void pccard_sysfs_remove_socket(struct device *dev);
/* In cs.c */ /* In cs.c */
extern struct rw_semaphore pcmcia_socket_list_rwsem; extern struct rw_semaphore pcmcia_socket_list_rwsem;
......
...@@ -356,19 +356,23 @@ static ssize_t pccard_store_cis(struct kobject *kobj, ...@@ -356,19 +356,23 @@ static ssize_t pccard_store_cis(struct kobject *kobj,
} }
static struct device_attribute *pccard_socket_attributes[] = { static struct attribute *pccard_socket_attributes[] = {
&dev_attr_card_type, &dev_attr_card_type.attr,
&dev_attr_card_voltage, &dev_attr_card_voltage.attr,
&dev_attr_card_vpp, &dev_attr_card_vpp.attr,
&dev_attr_card_vcc, &dev_attr_card_vcc.attr,
&dev_attr_card_insert, &dev_attr_card_insert.attr,
&dev_attr_card_pm_state, &dev_attr_card_pm_state.attr,
&dev_attr_card_eject, &dev_attr_card_eject.attr,
&dev_attr_card_irq_mask, &dev_attr_card_irq_mask.attr,
&dev_attr_available_resources_setup_done, &dev_attr_available_resources_setup_done.attr,
NULL, NULL,
}; };
static const struct attribute_group socket_attrs = {
.attrs = pccard_socket_attributes,
};
static struct bin_attribute pccard_cis_attr = { static struct bin_attribute pccard_cis_attr = {
.attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR },
.size = 0x200, .size = 0x200,
...@@ -376,35 +380,21 @@ static struct bin_attribute pccard_cis_attr = { ...@@ -376,35 +380,21 @@ static struct bin_attribute pccard_cis_attr = {
.write = pccard_store_cis, .write = pccard_store_cis,
}; };
static int __devinit pccard_sysfs_add_socket(struct device *dev, int pccard_sysfs_add_socket(struct device *dev)
struct class_interface *class_intf)
{ {
struct device_attribute **attr;
int ret = 0; int ret = 0;
for (attr = pccard_socket_attributes; *attr; attr++) { ret = sysfs_create_group(&dev->kobj, &socket_attrs);
ret = device_create_file(dev, *attr); if (!ret) {
ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr);
if (ret) if (ret)
break; sysfs_remove_group(&dev->kobj, &socket_attrs);
} }
if (!ret)
ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr);
return ret; return ret;
} }
static void __devexit pccard_sysfs_remove_socket(struct device *dev, void pccard_sysfs_remove_socket(struct device *dev)
struct class_interface *class_intf)
{ {
struct device_attribute **attr;
sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr);
for (attr = pccard_socket_attributes; *attr; attr++) sysfs_remove_group(&dev->kobj, &socket_attrs);
device_remove_file(dev, *attr);
} }
struct class_interface pccard_sysfs_interface = {
.class = &pcmcia_socket_class,
.add_dev = &pccard_sysfs_add_socket,
.remove_dev = __devexit_p(&pccard_sysfs_remove_socket),
};
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* 2 as published by the Free Software Foundation. * 2 as published by the Free Software Foundation.
* *
* debugfs is for people to use instead of /proc or /sys. * debugfs is for people to use instead of /proc or /sys.
* See Documentation/DocBook/kernel-api for more details. * See Documentation/DocBook/filesystems for more details.
* *
*/ */
......
...@@ -59,6 +59,8 @@ int sysfs_setattr(struct dentry * dentry, struct iattr * iattr) ...@@ -59,6 +59,8 @@ int sysfs_setattr(struct dentry * dentry, struct iattr * iattr)
if (error) if (error)
return error; return error;
iattr->ia_valid &= ~ATTR_SIZE; /* ignore size changes */
error = inode_setattr(inode, iattr); error = inode_setattr(inode, iattr);
if (error) if (error)
return error; return error;
......
...@@ -35,7 +35,6 @@ struct device; ...@@ -35,7 +35,6 @@ struct device;
struct device_driver; struct device_driver;
struct driver_private; struct driver_private;
struct class; struct class;
struct class_device;
struct bus_type; struct bus_type;
struct bus_type_private; struct bus_type_private;
...@@ -190,13 +189,10 @@ struct class { ...@@ -190,13 +189,10 @@ struct class {
struct kset class_dirs; struct kset class_dirs;
struct semaphore sem; /* locks children, devices, interfaces */ struct semaphore sem; /* locks children, devices, interfaces */
struct class_attribute *class_attrs; struct class_attribute *class_attrs;
struct class_device_attribute *class_dev_attrs;
struct device_attribute *dev_attrs; struct device_attribute *dev_attrs;
int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
void (*release)(struct class_device *dev);
void (*class_release)(struct class *class); void (*class_release)(struct class *class);
void (*dev_release)(struct device *dev); void (*dev_release)(struct device *dev);
...@@ -210,9 +206,6 @@ extern int class_for_each_device(struct class *class, void *data, ...@@ -210,9 +206,6 @@ extern int class_for_each_device(struct class *class, void *data,
int (*fn)(struct device *dev, void *data)); int (*fn)(struct device *dev, void *data));
extern struct device *class_find_device(struct class *class, void *data, extern struct device *class_find_device(struct class *class, void *data,
int (*match)(struct device *, void *)); int (*match)(struct device *, void *));
extern struct class_device *class_find_child(struct class *class, void *data,
int (*match)(struct class_device *, void *));
struct class_attribute { struct class_attribute {
struct attribute attr; struct attribute attr;
...@@ -228,92 +221,10 @@ extern int __must_check class_create_file(struct class *class, ...@@ -228,92 +221,10 @@ extern int __must_check class_create_file(struct class *class,
extern void class_remove_file(struct class *class, extern void class_remove_file(struct class *class,
const struct class_attribute *attr); const struct class_attribute *attr);
struct class_device_attribute {
struct attribute attr;
ssize_t (*show)(struct class_device *, char *buf);
ssize_t (*store)(struct class_device *, const char *buf, size_t count);
};
#define CLASS_DEVICE_ATTR(_name, _mode, _show, _store) \
struct class_device_attribute class_device_attr_##_name = \
__ATTR(_name, _mode, _show, _store)
extern int __must_check class_device_create_file(struct class_device *,
const struct class_device_attribute *);
/**
* struct class_device - class devices
* @class: pointer to the parent class for this class device. This is required.
* @devt: for internal use by the driver core only.
* @node: for internal use by the driver core only.
* @kobj: for internal use by the driver core only.
* @groups: optional additional groups to be created
* @dev: if set, a symlink to the struct device is created in the sysfs
* directory for this struct class device.
* @class_data: pointer to whatever you want to store here for this struct
* class_device. Use class_get_devdata() and class_set_devdata() to get and
* set this pointer.
* @parent: pointer to a struct class_device that is the parent of this struct
* class_device. If NULL, this class_device will show up at the root of the
* struct class in sysfs (which is probably what you want to have happen.)
* @release: pointer to a release function for this struct class_device. If
* set, this will be called instead of the class specific release function.
* Only use this if you want to override the default release function, like
* when you are nesting class_device structures.
* @uevent: pointer to a uevent function for this struct class_device. If
* set, this will be called instead of the class specific uevent function.
* Only use this if you want to override the default uevent function, like
* when you are nesting class_device structures.
*/
struct class_device {
struct list_head node;
struct kobject kobj;
struct class *class;
dev_t devt;
struct device *dev;
void *class_data;
struct class_device *parent;
struct attribute_group **groups;
void (*release)(struct class_device *dev);
int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
char class_id[BUS_ID_SIZE];
};
static inline void *class_get_devdata(struct class_device *dev)
{
return dev->class_data;
}
static inline void class_set_devdata(struct class_device *dev, void *data)
{
dev->class_data = data;
}
extern int __must_check class_device_register(struct class_device *);
extern void class_device_unregister(struct class_device *);
extern void class_device_initialize(struct class_device *);
extern int __must_check class_device_add(struct class_device *);
extern void class_device_del(struct class_device *);
extern struct class_device *class_device_get(struct class_device *);
extern void class_device_put(struct class_device *);
extern void class_device_remove_file(struct class_device *,
const struct class_device_attribute *);
extern int __must_check class_device_create_bin_file(struct class_device *,
struct bin_attribute *);
extern void class_device_remove_bin_file(struct class_device *,
struct bin_attribute *);
struct class_interface { struct class_interface {
struct list_head node; struct list_head node;
struct class *class; struct class *class;
int (*add) (struct class_device *, struct class_interface *);
void (*remove) (struct class_device *, struct class_interface *);
int (*add_dev) (struct device *, struct class_interface *); int (*add_dev) (struct device *, struct class_interface *);
void (*remove_dev) (struct device *, struct class_interface *); void (*remove_dev) (struct device *, struct class_interface *);
}; };
...@@ -323,13 +234,6 @@ extern void class_interface_unregister(struct class_interface *); ...@@ -323,13 +234,6 @@ extern void class_interface_unregister(struct class_interface *);
extern struct class *class_create(struct module *owner, const char *name); extern struct class *class_create(struct module *owner, const char *name);
extern void class_destroy(struct class *cls); extern void class_destroy(struct class *cls);
extern struct class_device *class_device_create(struct class *cls,
struct class_device *parent,
dev_t devt,
struct device *device,
const char *fmt, ...)
__attribute__((format(printf, 5, 6)));
extern void class_device_destroy(struct class *cls, dev_t devt);
/* /*
* The type of device, "struct device" is embedded in. A class * The type of device, "struct device" is embedded in. A class
...@@ -465,7 +369,6 @@ struct device { ...@@ -465,7 +369,6 @@ struct device {
spinlock_t devres_lock; spinlock_t devres_lock;
struct list_head devres_head; struct list_head devres_head;
/* class_device migration path */
struct list_head node; struct list_head node;
struct class *class; struct class *class;
dev_t devt; /* dev_t, creates the sysfs "dev" */ dev_t devt; /* dev_t, creates the sysfs "dev" */
......
...@@ -58,9 +58,9 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr) ...@@ -58,9 +58,9 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
} }
#endif #endif
void __iomem * devm_ioremap(struct device *dev, unsigned long offset, void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
unsigned long size); unsigned long size);
void __iomem * devm_ioremap_nocache(struct device *dev, unsigned long offset, void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
unsigned long size); unsigned long size);
void devm_iounmap(struct device *dev, void __iomem *addr); void devm_iounmap(struct device *dev, void __iomem *addr);
int check_signature(const volatile void __iomem *io_addr, int check_signature(const volatile void __iomem *io_addr,
......
...@@ -25,37 +25,47 @@ struct klist { ...@@ -25,37 +25,47 @@ struct klist {
void (*put)(struct klist_node *); void (*put)(struct klist_node *);
}; };
#define KLIST_INIT(_name, _get, _put) \
{ .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \
.k_list = LIST_HEAD_INIT(_name.k_list), \
.get = _get, \
.put = _put, }
extern void klist_init(struct klist * k, void (*get)(struct klist_node *), #define DEFINE_KLIST(_name, _get, _put) \
struct klist _name = KLIST_INIT(_name, _get, _put)
extern void klist_init(struct klist *k, void (*get)(struct klist_node *),
void (*put)(struct klist_node *)); void (*put)(struct klist_node *));
struct klist_node { struct klist_node {
struct klist * n_klist; struct klist *n_klist;
struct list_head n_node; struct list_head n_node;
struct kref n_ref; struct kref n_ref;
struct completion n_removed; struct completion n_removed;
}; };
extern void klist_add_tail(struct klist_node * n, struct klist * k); extern void klist_add_tail(struct klist_node *n, struct klist *k);
extern void klist_add_head(struct klist_node * n, struct klist * k); extern void klist_add_head(struct klist_node *n, struct klist *k);
extern void klist_add_after(struct klist_node *n, struct klist_node *pos);
extern void klist_add_before(struct klist_node *n, struct klist_node *pos);
extern void klist_del(struct klist_node * n); extern void klist_del(struct klist_node *n);
extern void klist_remove(struct klist_node * n); extern void klist_remove(struct klist_node *n);
extern int klist_node_attached(struct klist_node * n); extern int klist_node_attached(struct klist_node *n);
struct klist_iter { struct klist_iter {
struct klist * i_klist; struct klist *i_klist;
struct list_head * i_head; struct list_head *i_head;
struct klist_node * i_cur; struct klist_node *i_cur;
}; };
extern void klist_iter_init(struct klist * k, struct klist_iter * i); extern void klist_iter_init(struct klist *k, struct klist_iter *i);
extern void klist_iter_init_node(struct klist * k, struct klist_iter * i, extern void klist_iter_init_node(struct klist *k, struct klist_iter *i,
struct klist_node * n); struct klist_node *n);
extern void klist_iter_exit(struct klist_iter * i); extern void klist_iter_exit(struct klist_iter *i);
extern struct klist_node * klist_next(struct klist_iter * i); extern struct klist_node *klist_next(struct klist_iter *i);
#endif #endif
...@@ -190,6 +190,12 @@ static inline int sysfs_create_group(struct kobject *kobj, ...@@ -190,6 +190,12 @@ static inline int sysfs_create_group(struct kobject *kobj,
return 0; return 0;
} }
static inline int sysfs_update_group(struct kobject *kobj,
const struct attribute_group *grp)
{
return 0;
}
static inline void sysfs_remove_group(struct kobject *kobj, static inline void sysfs_remove_group(struct kobject *kobj,
const struct attribute_group *grp) const struct attribute_group *grp)
{ {
......
...@@ -20,7 +20,7 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) ...@@ -20,7 +20,7 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data)
* *
* Managed ioremap(). Map is automatically unmapped on driver detach. * Managed ioremap(). Map is automatically unmapped on driver detach.
*/ */
void __iomem *devm_ioremap(struct device *dev, unsigned long offset, void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
unsigned long size) unsigned long size)
{ {
void __iomem **ptr, *addr; void __iomem **ptr, *addr;
...@@ -49,7 +49,7 @@ EXPORT_SYMBOL(devm_ioremap); ...@@ -49,7 +49,7 @@ EXPORT_SYMBOL(devm_ioremap);
* Managed ioremap_nocache(). Map is automatically unmapped on driver * Managed ioremap_nocache(). Map is automatically unmapped on driver
* detach. * detach.
*/ */
void __iomem *devm_ioremap_nocache(struct device *dev, unsigned long offset, void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
unsigned long size) unsigned long size)
{ {
void __iomem **ptr, *addr; void __iomem **ptr, *addr;
......
/* /*
* klist.c - Routines for manipulating klists. * klist.c - Routines for manipulating klists.
* *
* Copyright (C) 2005 Patrick Mochel
*
* This file is released under the GPL v2.
* *
* This klist interface provides a couple of structures that wrap around * This klist interface provides a couple of structures that wrap around
* struct list_head to provide explicit list "head" (struct klist) and * struct list_head to provide explicit list "head" (struct klist) and list
* list "node" (struct klist_node) objects. For struct klist, a spinlock * "node" (struct klist_node) objects. For struct klist, a spinlock is
* is included that protects access to the actual list itself. struct * included that protects access to the actual list itself. struct
* klist_node provides a pointer to the klist that owns it and a kref * klist_node provides a pointer to the klist that owns it and a kref
* reference count that indicates the number of current users of that node * reference count that indicates the number of current users of that node
* in the list. * in the list.
...@@ -18,21 +21,17 @@ ...@@ -18,21 +21,17 @@
* It works using a 3rd object type - struct klist_iter - that is declared * It works using a 3rd object type - struct klist_iter - that is declared
* and initialized before an iteration. klist_next() is used to acquire the * and initialized before an iteration. klist_next() is used to acquire the
* next element in the list. It returns NULL if there are no more items. * next element in the list. It returns NULL if there are no more items.
* Internally, that routine takes the klist's lock, decrements the reference * Internally, that routine takes the klist's lock, decrements the
* count of the previous klist_node and increments the count of the next * reference count of the previous klist_node and increments the count of
* klist_node. It then drops the lock and returns. * the next klist_node. It then drops the lock and returns.
* *
* There are primitives for adding and removing nodes to/from a klist. * There are primitives for adding and removing nodes to/from a klist.
* When deleting, klist_del() will simply decrement the reference count. * When deleting, klist_del() will simply decrement the reference count.
* Only when the count goes to 0 is the node removed from the list. * Only when the count goes to 0 is the node removed from the list.
* klist_remove() will try to delete the node from the list and block * klist_remove() will try to delete the node from the list and block until
* until it is actually removed. This is useful for objects (like devices) * it is actually removed. This is useful for objects (like devices) that
* that have been removed from the system and must be freed (but must wait * have been removed from the system and must be freed (but must wait until
* until all accessors have finished). * all accessors have finished).
*
* Copyright (C) 2005 Patrick Mochel
*
* This file is released under the GPL v2.
*/ */
#include <linux/klist.h> #include <linux/klist.h>
...@@ -51,8 +50,7 @@ ...@@ -51,8 +50,7 @@
* functions that take and release references on the embedding * functions that take and release references on the embedding
* objects. * objects.
*/ */
void klist_init(struct klist *k, void (*get)(struct klist_node *),
void klist_init(struct klist * k, void (*get)(struct klist_node *),
void (*put)(struct klist_node *)) void (*put)(struct klist_node *))
{ {
INIT_LIST_HEAD(&k->k_list); INIT_LIST_HEAD(&k->k_list);
...@@ -60,26 +58,23 @@ void klist_init(struct klist * k, void (*get)(struct klist_node *), ...@@ -60,26 +58,23 @@ void klist_init(struct klist * k, void (*get)(struct klist_node *),
k->get = get; k->get = get;
k->put = put; k->put = put;
} }
EXPORT_SYMBOL_GPL(klist_init); EXPORT_SYMBOL_GPL(klist_init);
static void add_head(struct klist *k, struct klist_node *n)
static void add_head(struct klist * k, struct klist_node * n)
{ {
spin_lock(&k->k_lock); spin_lock(&k->k_lock);
list_add(&n->n_node, &k->k_list); list_add(&n->n_node, &k->k_list);
spin_unlock(&k->k_lock); spin_unlock(&k->k_lock);
} }
static void add_tail(struct klist * k, struct klist_node * n) static void add_tail(struct klist *k, struct klist_node *n)
{ {
spin_lock(&k->k_lock); spin_lock(&k->k_lock);
list_add_tail(&n->n_node, &k->k_list); list_add_tail(&n->n_node, &k->k_list);
spin_unlock(&k->k_lock); spin_unlock(&k->k_lock);
} }
static void klist_node_init(struct klist *k, struct klist_node *n)
static void klist_node_init(struct klist * k, struct klist_node * n)
{ {
INIT_LIST_HEAD(&n->n_node); INIT_LIST_HEAD(&n->n_node);
init_completion(&n->n_removed); init_completion(&n->n_removed);
...@@ -89,60 +84,83 @@ static void klist_node_init(struct klist * k, struct klist_node * n) ...@@ -89,60 +84,83 @@ static void klist_node_init(struct klist * k, struct klist_node * n)
k->get(n); k->get(n);
} }
/** /**
* klist_add_head - Initialize a klist_node and add it to front. * klist_add_head - Initialize a klist_node and add it to front.
* @n: node we're adding. * @n: node we're adding.
* @k: klist it's going on. * @k: klist it's going on.
*/ */
void klist_add_head(struct klist_node *n, struct klist *k)
void klist_add_head(struct klist_node * n, struct klist * k)
{ {
klist_node_init(k, n); klist_node_init(k, n);
add_head(k, n); add_head(k, n);
} }
EXPORT_SYMBOL_GPL(klist_add_head); EXPORT_SYMBOL_GPL(klist_add_head);
/** /**
* klist_add_tail - Initialize a klist_node and add it to back. * klist_add_tail - Initialize a klist_node and add it to back.
* @n: node we're adding. * @n: node we're adding.
* @k: klist it's going on. * @k: klist it's going on.
*/ */
void klist_add_tail(struct klist_node *n, struct klist *k)
void klist_add_tail(struct klist_node * n, struct klist * k)
{ {
klist_node_init(k, n); klist_node_init(k, n);
add_tail(k, n); add_tail(k, n);
} }
EXPORT_SYMBOL_GPL(klist_add_tail); EXPORT_SYMBOL_GPL(klist_add_tail);
/**
* klist_add_after - Init a klist_node and add it after an existing node
* @n: node we're adding.
* @pos: node to put @n after
*/
void klist_add_after(struct klist_node *n, struct klist_node *pos)
{
struct klist *k = pos->n_klist;
klist_node_init(k, n);
spin_lock(&k->k_lock);
list_add(&n->n_node, &pos->n_node);
spin_unlock(&k->k_lock);
}
EXPORT_SYMBOL_GPL(klist_add_after);
/**
* klist_add_before - Init a klist_node and add it before an existing node
* @n: node we're adding.
* @pos: node to put @n after
*/
void klist_add_before(struct klist_node *n, struct klist_node *pos)
{
struct klist *k = pos->n_klist;
klist_node_init(k, n);
spin_lock(&k->k_lock);
list_add_tail(&n->n_node, &pos->n_node);
spin_unlock(&k->k_lock);
}
EXPORT_SYMBOL_GPL(klist_add_before);
static void klist_release(struct kref * kref) static void klist_release(struct kref *kref)
{ {
struct klist_node * n = container_of(kref, struct klist_node, n_ref); struct klist_node *n = container_of(kref, struct klist_node, n_ref);
list_del(&n->n_node); list_del(&n->n_node);
complete(&n->n_removed); complete(&n->n_removed);
n->n_klist = NULL; n->n_klist = NULL;
} }
static int klist_dec_and_del(struct klist_node * n) static int klist_dec_and_del(struct klist_node *n)
{ {
return kref_put(&n->n_ref, klist_release); return kref_put(&n->n_ref, klist_release);
} }
/** /**
* klist_del - Decrement the reference count of node and try to remove. * klist_del - Decrement the reference count of node and try to remove.
* @n: node we're deleting. * @n: node we're deleting.
*/ */
void klist_del(struct klist_node *n)
void klist_del(struct klist_node * n)
{ {
struct klist * k = n->n_klist; struct klist *k = n->n_klist;
void (*put)(struct klist_node *) = k->put; void (*put)(struct klist_node *) = k->put;
spin_lock(&k->k_lock); spin_lock(&k->k_lock);
...@@ -152,37 +170,29 @@ void klist_del(struct klist_node * n) ...@@ -152,37 +170,29 @@ void klist_del(struct klist_node * n)
if (put) if (put)
put(n); put(n);
} }
EXPORT_SYMBOL_GPL(klist_del); EXPORT_SYMBOL_GPL(klist_del);
/** /**
* klist_remove - Decrement the refcount of node and wait for it to go away. * klist_remove - Decrement the refcount of node and wait for it to go away.
* @n: node we're removing. * @n: node we're removing.
*/ */
void klist_remove(struct klist_node *n)
void klist_remove(struct klist_node * n)
{ {
klist_del(n); klist_del(n);
wait_for_completion(&n->n_removed); wait_for_completion(&n->n_removed);
} }
EXPORT_SYMBOL_GPL(klist_remove); EXPORT_SYMBOL_GPL(klist_remove);
/** /**
* klist_node_attached - Say whether a node is bound to a list or not. * klist_node_attached - Say whether a node is bound to a list or not.
* @n: Node that we're testing. * @n: Node that we're testing.
*/ */
int klist_node_attached(struct klist_node *n)
int klist_node_attached(struct klist_node * n)
{ {
return (n->n_klist != NULL); return (n->n_klist != NULL);
} }
EXPORT_SYMBOL_GPL(klist_node_attached); EXPORT_SYMBOL_GPL(klist_node_attached);
/** /**
* klist_iter_init_node - Initialize a klist_iter structure. * klist_iter_init_node - Initialize a klist_iter structure.
* @k: klist we're iterating. * @k: klist we're iterating.
...@@ -192,8 +202,8 @@ EXPORT_SYMBOL_GPL(klist_node_attached); ...@@ -192,8 +202,8 @@ EXPORT_SYMBOL_GPL(klist_node_attached);
* Similar to klist_iter_init(), but starts the action off with @n, * Similar to klist_iter_init(), but starts the action off with @n,
* instead of with the list head. * instead of with the list head.
*/ */
void klist_iter_init_node(struct klist *k, struct klist_iter *i,
void klist_iter_init_node(struct klist * k, struct klist_iter * i, struct klist_node * n) struct klist_node *n)
{ {
i->i_klist = k; i->i_klist = k;
i->i_head = &k->k_list; i->i_head = &k->k_list;
...@@ -201,10 +211,8 @@ void klist_iter_init_node(struct klist * k, struct klist_iter * i, struct klist_ ...@@ -201,10 +211,8 @@ void klist_iter_init_node(struct klist * k, struct klist_iter * i, struct klist_
if (n) if (n)
kref_get(&n->n_ref); kref_get(&n->n_ref);
} }
EXPORT_SYMBOL_GPL(klist_iter_init_node); EXPORT_SYMBOL_GPL(klist_iter_init_node);
/** /**
* klist_iter_init - Iniitalize a klist_iter structure. * klist_iter_init - Iniitalize a klist_iter structure.
* @k: klist we're iterating. * @k: klist we're iterating.
...@@ -212,15 +220,12 @@ EXPORT_SYMBOL_GPL(klist_iter_init_node); ...@@ -212,15 +220,12 @@ EXPORT_SYMBOL_GPL(klist_iter_init_node);
* *
* Similar to klist_iter_init_node(), but start with the list head. * Similar to klist_iter_init_node(), but start with the list head.
*/ */
void klist_iter_init(struct klist *k, struct klist_iter *i)
void klist_iter_init(struct klist * k, struct klist_iter * i)
{ {
klist_iter_init_node(k, i, NULL); klist_iter_init_node(k, i, NULL);
} }
EXPORT_SYMBOL_GPL(klist_iter_init); EXPORT_SYMBOL_GPL(klist_iter_init);
/** /**
* klist_iter_exit - Finish a list iteration. * klist_iter_exit - Finish a list iteration.
* @i: Iterator structure. * @i: Iterator structure.
...@@ -229,24 +234,20 @@ EXPORT_SYMBOL_GPL(klist_iter_init); ...@@ -229,24 +234,20 @@ EXPORT_SYMBOL_GPL(klist_iter_init);
* refcount of the current node. Necessary in case iteration exited before * refcount of the current node. Necessary in case iteration exited before
* the end of the list was reached, and always good form. * the end of the list was reached, and always good form.
*/ */
void klist_iter_exit(struct klist_iter *i)
void klist_iter_exit(struct klist_iter * i)
{ {
if (i->i_cur) { if (i->i_cur) {
klist_del(i->i_cur); klist_del(i->i_cur);
i->i_cur = NULL; i->i_cur = NULL;
} }
} }
EXPORT_SYMBOL_GPL(klist_iter_exit); EXPORT_SYMBOL_GPL(klist_iter_exit);
static struct klist_node *to_klist_node(struct list_head *n)
static struct klist_node * to_klist_node(struct list_head * n)
{ {
return container_of(n, struct klist_node, n_node); return container_of(n, struct klist_node, n_node);
} }
/** /**
* klist_next - Ante up next node in list. * klist_next - Ante up next node in list.
* @i: Iterator structure. * @i: Iterator structure.
...@@ -255,12 +256,11 @@ static struct klist_node * to_klist_node(struct list_head * n) ...@@ -255,12 +256,11 @@ static struct klist_node * to_klist_node(struct list_head * n)
* node, if there was one. Grab the next node, increment its reference * node, if there was one. Grab the next node, increment its reference
* count, drop the lock, and return that next node. * count, drop the lock, and return that next node.
*/ */
struct klist_node *klist_next(struct klist_iter *i)
struct klist_node * klist_next(struct klist_iter * i)
{ {
struct list_head * next; struct list_head *next;
struct klist_node * lnode = i->i_cur; struct klist_node *lnode = i->i_cur;
struct klist_node * knode = NULL; struct klist_node *knode = NULL;
void (*put)(struct klist_node *) = i->i_klist->put; void (*put)(struct klist_node *) = i->i_klist->put;
spin_lock(&i->i_klist->k_lock); spin_lock(&i->i_klist->k_lock);
...@@ -281,7 +281,4 @@ struct klist_node * klist_next(struct klist_iter * i) ...@@ -281,7 +281,4 @@ struct klist_node * klist_next(struct klist_iter * i)
put(lnode); put(lnode);
return knode; return knode;
} }
EXPORT_SYMBOL_GPL(klist_next); EXPORT_SYMBOL_GPL(klist_next);
...@@ -216,21 +216,12 @@ static int kobject_add_internal(struct kobject *kobj) ...@@ -216,21 +216,12 @@ static int kobject_add_internal(struct kobject *kobj)
static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
va_list vargs) va_list vargs)
{ {
va_list aq;
char *name;
va_copy(aq, vargs);
name = kvasprintf(GFP_KERNEL, fmt, vargs);
va_end(aq);
if (!name)
return -ENOMEM;
/* Free the old name, if necessary. */ /* Free the old name, if necessary. */
kfree(kobj->name); kfree(kobj->name);
/* Now, set the new name */ kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
kobj->name = name; if (!kobj->name)
return -ENOMEM;
return 0; return 0;
} }
...@@ -246,12 +237,12 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, ...@@ -246,12 +237,12 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
*/ */
int kobject_set_name(struct kobject *kobj, const char *fmt, ...) int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
{ {
va_list args; va_list vargs;
int retval; int retval;
va_start(args, fmt); va_start(vargs, fmt);
retval = kobject_set_name_vargs(kobj, fmt, args); retval = kobject_set_name_vargs(kobj, fmt, vargs);
va_end(args); va_end(vargs);
return retval; return retval;
} }
...@@ -301,12 +292,9 @@ EXPORT_SYMBOL(kobject_init); ...@@ -301,12 +292,9 @@ EXPORT_SYMBOL(kobject_init);
static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
const char *fmt, va_list vargs) const char *fmt, va_list vargs)
{ {
va_list aq;
int retval; int retval;
va_copy(aq, vargs); retval = kobject_set_name_vargs(kobj, fmt, vargs);
retval = kobject_set_name_vargs(kobj, fmt, aq);
va_end(aq);
if (retval) { if (retval) {
printk(KERN_ERR "kobject: can not set name properly!\n"); printk(KERN_ERR "kobject: can not set name properly!\n");
return retval; return retval;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment