* Serialised against concurrent create and destroy using the
* gb_connection_mutex.
*
- * Return: A pointer to the new connection if successful, or NULL otherwise.
+ * Return: A pointer to the new connection if successful, or an ERR_PTR
+ * otherwise.
*/
static struct gb_connection *
_gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
struct gb_connection *connection;
struct ida *id_map = &hd->cport_id_map;
int ida_start, ida_end;
+ int ret;
if (hd_cport_id < 0) {
ida_start = 0;
ida_end = hd_cport_id + 1;
} else {
dev_err(&hd->dev, "cport %d not available\n", hd_cport_id);
- return NULL;
+ return ERR_PTR(-EINVAL);
}
mutex_lock(&gb_connection_mutex);
if (intf && gb_connection_intf_find(intf, cport_id)) {
dev_err(&intf->dev, "cport %u already in use\n", cport_id);
+ ret = -EBUSY;
goto err_unlock;
}
- hd_cport_id = ida_simple_get(id_map, ida_start, ida_end, GFP_KERNEL);
- if (hd_cport_id < 0)
+ ret = ida_simple_get(id_map, ida_start, ida_end, GFP_KERNEL);
+ if (ret < 0)
goto err_unlock;
+ hd_cport_id = ret;
connection = kzalloc(sizeof(*connection), GFP_KERNEL);
- if (!connection)
+ if (!connection) {
+ ret = -ENOMEM;
goto err_remove_ida;
+ }
connection->hd_cport_id = hd_cport_id;
connection->intf_cport_id = cport_id;
connection->wq = alloc_workqueue("%s:%d", WQ_UNBOUND, 1,
dev_name(&hd->dev), hd_cport_id);
- if (!connection->wq)
+ if (!connection->wq) {
+ ret = -ENOMEM;
goto err_free_connection;
+ }
kref_init(&connection->kref);
err_unlock:
mutex_unlock(&gb_connection_mutex);
- return NULL;
+ return ERR_PTR(ret);
}
struct gb_connection *
return NULL;
control->connection = gb_connection_create_control(intf);
- if (!control->connection) {
- dev_err(&intf->dev, "failed to create control connection\n");
+ if (IS_ERR(control->connection)) {
+ dev_err(&intf->dev,
+ "failed to create control connection: %ld\n",
+ PTR_ERR(control->connection));
kfree(control);
return NULL;
}
struct legacy_data *data;
struct gb_connection *connection;
int i;
- int ret = -ENOMEM;
+ int ret;
dev_dbg(&bundle->dev,
"%s - bundle class = 0x%02x, num_cports = %zu\n",
data->connections = kcalloc(data->num_cports,
sizeof(*data->connections),
GFP_KERNEL);
- if (!data->connections)
+ if (!data->connections) {
+ ret = -ENOMEM;
goto err_free_data;
+ }
for (i = 0; i < data->num_cports; ++i) {
cport_desc = &bundle->cport_desc[i];
connection = gb_connection_create(bundle,
le16_to_cpu(cport_desc->id));
- if (!connection)
+ if (IS_ERR(connection)) {
+ ret = PTR_ERR(connection);
goto err_connections_destroy;
+ }
connection->protocol_id = cport_desc->protocol_id;
}
svc->connection = gb_connection_create_static(hd, GB_SVC_CPORT_ID);
- if (!svc->connection) {
- dev_err(&svc->dev, "failed to create connection\n");
+ if (IS_ERR(svc->connection)) {
+ dev_err(&svc->dev, "failed to create connection: %ld\n",
+ PTR_ERR(svc->connection));
goto err_free_input;
}