summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2012-04-16 15:06:25 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-19 00:39:52 +0200
commita15d49fd3094cff90e5410ca454a870e0a722fe1 (patch)
treef3e458fa4ce3524f756e0faa48d5ed2400c022bf /lib
parentdrivers/base/bus.c: local variables should not be exposed globally (diff)
downloadlinux-a15d49fd3094cff90e5410ca454a870e0a722fe1.tar.xz
linux-a15d49fd3094cff90e5410ca454a870e0a722fe1.zip
driver core: check start node in klist_iter_init_node
klist_iter_init_node() takes a node as a start argument. However, this node might not be valid anymore. This patch updates the klist_iter_init_node() and dependent functions to return an error if so. All calling functions have been audited to check for a return code here. Signed-off-by: Hannes Reinecke <hare@suse.de> Cc: Greg Kroah-Hartmann <gregkh@linuxfoundation.org> Cc: Kay Sievers <kay@vrfy.org> Cc: Stable Kernel <stable@kernel.org> Cc: Linux Kernel <linux-kernel@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/klist.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/klist.c b/lib/klist.c
index 0874e41609a6..a2741a7d9784 100644
--- a/lib/klist.c
+++ b/lib/klist.c
@@ -278,13 +278,19 @@ EXPORT_SYMBOL_GPL(klist_node_attached);
* Similar to klist_iter_init(), but starts the action off with @n,
* instead of with the list head.
*/
-void klist_iter_init_node(struct klist *k, struct klist_iter *i,
- struct klist_node *n)
+int klist_iter_init_node(struct klist *k, struct klist_iter *i,
+ struct klist_node *n)
{
+ if (n) {
+ kref_get(&n->n_ref);
+ if (!n->n_klist) {
+ kref_put(&n->n_ref);
+ return -ENODEV;
+ }
+ }
i->i_klist = k;
i->i_cur = n;
- if (n)
- kref_get(&n->n_ref);
+ return 0;
}
EXPORT_SYMBOL_GPL(klist_iter_init_node);