aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/driver.c
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2012-04-16 09:06:25 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-18 18:39:52 -0400
commita15d49fd3094cff90e5410ca454a870e0a722fe1 (patch)
treef3e458fa4ce3524f756e0faa48d5ed2400c022bf /drivers/base/driver.c
parent97ec448aeadff55234368a89c4a07a7ef290a084 (diff)
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 'drivers/base/driver.c')
-rw-r--r--drivers/base/driver.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 3ec3896c83a6..16f6dd2c4403 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -49,11 +49,13 @@ int driver_for_each_device(struct device_driver *drv, struct device *start,
49 if (!drv) 49 if (!drv)
50 return -EINVAL; 50 return -EINVAL;
51 51
52 klist_iter_init_node(&drv->p->klist_devices, &i, 52 error = klist_iter_init_node(&drv->p->klist_devices, &i,
53 start ? &start->p->knode_driver : NULL); 53 start ? &start->p->knode_driver : NULL);
54 while ((dev = next_device(&i)) && !error) 54 if (!error) {
55 error = fn(dev, data); 55 while ((dev = next_device(&i)) && !error)
56 klist_iter_exit(&i); 56 error = fn(dev, data);
57 klist_iter_exit(&i);
58 }
57 return error; 59 return error;
58} 60}
59EXPORT_SYMBOL_GPL(driver_for_each_device); 61EXPORT_SYMBOL_GPL(driver_for_each_device);
@@ -83,8 +85,10 @@ struct device *driver_find_device(struct device_driver *drv,
83 if (!drv) 85 if (!drv)
84 return NULL; 86 return NULL;
85 87
86 klist_iter_init_node(&drv->p->klist_devices, &i, 88 if (klist_iter_init_node(&drv->p->klist_devices, &i,
87 (start ? &start->p->knode_driver : NULL)); 89 (start ? &start->p->knode_driver : NULL)) < 0)
90 return NULL;
91
88 while ((dev = next_device(&i))) 92 while ((dev = next_device(&i)))
89 if (match(dev, data) && get_device(dev)) 93 if (match(dev, data) && get_device(dev))
90 break; 94 break;