mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-25 16:11:45 +00:00
serdev: fix controller-allocation error handling
Reorder controller initialisation so that in the unlikely event that id allocation fails, we don't end up releasing id 0 in the destructor. Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
08fcee289f
commit
978d6fac5d
1 changed files with 14 additions and 9 deletions
|
@ -358,6 +358,15 @@ struct serdev_controller *serdev_controller_alloc(struct device *parent,
|
||||||
if (!ctrl)
|
if (!ctrl)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
id = ida_simple_get(&ctrl_ida, 0, 0, GFP_KERNEL);
|
||||||
|
if (id < 0) {
|
||||||
|
dev_err(parent,
|
||||||
|
"unable to allocate serdev controller identifier.\n");
|
||||||
|
goto err_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrl->nr = id;
|
||||||
|
|
||||||
device_initialize(&ctrl->dev);
|
device_initialize(&ctrl->dev);
|
||||||
ctrl->dev.type = &serdev_ctrl_type;
|
ctrl->dev.type = &serdev_ctrl_type;
|
||||||
ctrl->dev.bus = &serdev_bus_type;
|
ctrl->dev.bus = &serdev_bus_type;
|
||||||
|
@ -365,19 +374,15 @@ struct serdev_controller *serdev_controller_alloc(struct device *parent,
|
||||||
ctrl->dev.of_node = parent->of_node;
|
ctrl->dev.of_node = parent->of_node;
|
||||||
serdev_controller_set_drvdata(ctrl, &ctrl[1]);
|
serdev_controller_set_drvdata(ctrl, &ctrl[1]);
|
||||||
|
|
||||||
id = ida_simple_get(&ctrl_ida, 0, 0, GFP_KERNEL);
|
|
||||||
if (id < 0) {
|
|
||||||
dev_err(parent,
|
|
||||||
"unable to allocate serdev controller identifier.\n");
|
|
||||||
serdev_controller_put(ctrl);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrl->nr = id;
|
|
||||||
dev_set_name(&ctrl->dev, "serial%d", id);
|
dev_set_name(&ctrl->dev, "serial%d", id);
|
||||||
|
|
||||||
dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id);
|
dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id);
|
||||||
return ctrl;
|
return ctrl;
|
||||||
|
|
||||||
|
err_free:
|
||||||
|
kfree(ctrl);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(serdev_controller_alloc);
|
EXPORT_SYMBOL_GPL(serdev_controller_alloc);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue