提交 07634464 编写于 作者: C Cornelia Huck 提交者: Greg Kroah-Hartman

Driver core: Fix error handling in bus_add_driver().

- If the allocation of ->priv fails, the reference on the bus
  must be dropped.
- If adding the kobject fails, kobject_put must be called to
  clean things up.
Signed-off-by: NCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 7199677d
...@@ -658,9 +658,10 @@ int bus_add_driver(struct device_driver *drv) ...@@ -658,9 +658,10 @@ int bus_add_driver(struct device_driver *drv)
pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name);
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv) {
return -ENOMEM; error = -ENOMEM;
goto out_put_bus;
}
klist_init(&priv->klist_devices, NULL, NULL); klist_init(&priv->klist_devices, NULL, NULL);
priv->driver = drv; priv->driver = drv;
drv->p = priv; drv->p = priv;
...@@ -668,7 +669,7 @@ int bus_add_driver(struct device_driver *drv) ...@@ -668,7 +669,7 @@ int bus_add_driver(struct device_driver *drv)
error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL, error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL,
"%s", drv->name); "%s", drv->name);
if (error) if (error)
goto out_put_bus; goto out_unregister;
if (drv->bus->p->drivers_autoprobe) { if (drv->bus->p->drivers_autoprobe) {
error = driver_attach(drv); error = driver_attach(drv);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册