* @mode: The access mode for the device node
* @uid: The uid of the device node
* @gid: The gid of the device node
- * @bus: Pointer to a reference where the new bus is stored
*
* This function will allocate a new kdbus_bus and link it to the given
* domain.
*
- * Return: 0 on success, negative errno on failure.
+ * Return: a new kdbus_bus object on success, ERR_PTR value on failure.
*/
-int kdbus_bus_new(struct kdbus_domain *domain,
- const struct kdbus_cmd_make *make,
- const char *name,
- const struct kdbus_bloom_parameter *bloom,
- umode_t mode, kuid_t uid, kgid_t gid,
- struct kdbus_bus **bus)
+struct kdbus_bus *kdbus_bus_new(struct kdbus_domain *domain,
+ const struct kdbus_cmd_make *make,
+ const char *name,
+ const struct kdbus_bloom_parameter *bloom,
+ umode_t mode, kuid_t uid, kgid_t gid)
{
struct kdbus_bus *b;
char prefix[16];
int ret;
- BUG_ON(*bus);
-
/* enforce "$UID-" prefix */
snprintf(prefix, sizeof(prefix), "%u-",
from_kuid(current_user_ns(), uid));
if (strncmp(name, prefix, strlen(prefix) != 0))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
b = kdbus_bus_find(domain, name);
if (b) {
kdbus_bus_unref(b);
- return -EEXIST;
+ return ERR_PTR(-EEXIST);
}
b = kzalloc(sizeof(*b), GFP_KERNEL);
if (!b)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
kref_init(&b->kref);
b->uid_owner = uid;
generate_random_uuid(b->id128);
/* cache the metadata/credentials of the creator */
- ret = kdbus_meta_new(&b->meta);
- if (ret < 0)
- return ret;
+ b->meta = kdbus_meta_new();
+ if (IS_ERR(b->meta))
+ return ERR_PTR(PTR_ERR(b->meta));
ret = kdbus_meta_append(b->meta, NULL, 0,
KDBUS_ATTACH_CREDS |
goto exit_free;
}
- ret = kdbus_name_registry_new(&b->name_registry);
- if (ret < 0)
+ b->name_registry = kdbus_name_registry_new();
+ if (IS_ERR(b->name_registry)) {
+ ret = PTR_ERR(b->name_registry);
goto exit_free_name;
+ }
- ret = kdbus_ep_new(b, "bus", mode, uid, gid, false, &b->ep);
- if (ret < 0)
+ b->ep = kdbus_ep_new(b, "bus", mode, uid, gid, false);
+ if (IS_ERR(b->ep) < 0) {
+ ret = PTR_ERR(b->ep);
goto exit_free_reg;
+ }
/* link into domain */
mutex_lock(&domain->lock);
list_add_tail(&b->domain_entry, &domain->bus_list);
mutex_unlock(&domain->lock);
- *bus = b;
- return 0;
+ return b;
exit_unref_user_unlock:
mutex_unlock(&domain->lock);
kdbus_policy_db_clear(&b->policy_db);
kdbus_domain_unref(b->domain);
kfree(b);
- return ret;
+
+ return ERR_PTR(ret);
}
/**
int kdbus_bus_make_user(const struct kdbus_cmd_make *make,
char **name, struct kdbus_bloom_parameter *bloom);
-int kdbus_bus_new(struct kdbus_domain *domain,
- const struct kdbus_cmd_make *make,
- const char *name,
- const struct kdbus_bloom_parameter *bloom,
- umode_t mode, kuid_t uid, kgid_t gid,
- struct kdbus_bus **bus);
+struct kdbus_bus *kdbus_bus_new(struct kdbus_domain *domain,
+ const struct kdbus_cmd_make *make,
+ const char *name,
+ const struct kdbus_bloom_parameter *bloom,
+ umode_t mode, kuid_t uid, kgid_t gid);
int kdbus_cmd_bus_creator_info(struct kdbus_conn *conn,
struct kdbus_cmd_info *cmd_info);
struct kdbus_bus *kdbus_bus_ref(struct kdbus_bus *bus);
int err;
};
-static int kdbus_conn_reply_new(struct kdbus_conn_reply **reply_wait,
- struct kdbus_conn *reply_dst,
- const struct kdbus_msg *msg,
- struct kdbus_name_entry *name_entry)
+static struct kdbus_conn_reply *
+kdbus_conn_reply_new(struct kdbus_conn *reply_dst,
+ const struct kdbus_msg *msg,
+ struct kdbus_name_entry *name_entry)
{
bool sync = msg->flags & KDBUS_MSG_FLAGS_SYNC_REPLY;
struct kdbus_conn_reply *r;
r->waiting = true;
}
- *reply_wait = r;
-
exit_dec_reply_count:
- if (ret < 0)
+ if (ret < 0) {
atomic_dec(&reply_dst->reply_count);
+ return ERR_PTR(ret);
+ }
- return ret;
+ return r;
}
static void __kdbus_conn_reply_free(struct kref *kref)
* and take care not to augment it by attaching any new items.
*/
if (conn_src->owner_meta)
- ret = kdbus_meta_dup(conn_src->owner_meta, &kmsg->meta);
+ kmsg->meta = kdbus_meta_dup(conn_src->owner_meta);
else
- ret = kdbus_meta_new(&kmsg->meta);
+ kmsg->meta = kdbus_meta_new();
- if (ret < 0)
- return ret;
+ if (IS_ERR(kmsg->meta))
+ return PTR_ERR(kmsg->meta);
}
if (msg->dst_id == KDBUS_DST_ID_BROADCAST) {
if (ret < 0)
goto exit_unref;
- ret = kdbus_conn_reply_new(&reply_wait, conn_src, msg,
- name_entry);
- if (ret < 0)
+ reply_wait = kdbus_conn_reply_new(conn_src, msg,
+ name_entry);
+ if (IS_ERR(reply_wait)) {
+ ret = PTR_ERR(reply_wait);
goto exit_unref;
+ }
} else {
ret = kdbus_conn_check_access(ep, msg, conn_src,
conn_dst, &reply_wake);
*/
flags = cmd_info->flags & (KDBUS_ATTACH_NAMES | KDBUS_ATTACH_CONN_NAME);
if (flags) {
- ret = kdbus_meta_new(&meta);
- if (ret < 0)
+ meta = kdbus_meta_new();
+ if (IS_ERR(meta)) {
+ ret = PTR_ERR(meta);
goto exit;
+ }
ret = kdbus_meta_append(meta, owner_conn, 0, flags);
if (ret < 0)
* @ep: The endpoint the connection is connected to
* @hello: The kdbus_cmd_hello as passed in by the user
* @meta: The metadata gathered at open() time of the handle
- * @c: Returned connection
*
- * Return: 0 on success, negative errno on failure
+ * Return: a new kdbus_conn on success, ERR_PTR on failure
*/
-int kdbus_conn_new(struct kdbus_ep *ep,
- struct kdbus_cmd_hello *hello,
- struct kdbus_meta *meta,
- struct kdbus_conn **c)
+struct kdbus_conn *kdbus_conn_new(struct kdbus_ep *ep,
+ struct kdbus_cmd_hello *hello,
+ struct kdbus_meta *meta)
{
#ifdef CONFIG_DEBUG_LOCK_ALLOC
static struct lock_class_key __key;
bool is_monitor;
int ret;
- BUG_ON(*c);
-
is_monitor = hello->flags & KDBUS_HELLO_MONITOR;
is_activator = hello->flags & KDBUS_HELLO_ACTIVATOR;
is_policy_holder = hello->flags & KDBUS_HELLO_POLICY_HOLDER;
/* can't be activator or policy holder and monitor at the same time */
if (is_monitor && (is_activator || is_policy_holder))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
/* can't be policy holder and activator at the same time */
if (is_activator && is_policy_holder)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
/* only privileged connections can activate and monitor */
if (!kdbus_bus_uid_is_privileged(bus) &&
(is_activator || is_policy_holder || is_monitor))
- return -EPERM;
+ return ERR_PTR(-EPERM);
KDBUS_ITEMS_FOREACH(item, hello->items,
KDBUS_ITEMS_SIZE(hello, items)) {
switch (item->type) {
case KDBUS_ITEM_NAME:
if (!is_activator && !is_policy_holder)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
if (name)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
if (!kdbus_name_is_valid(item->str, true))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
name = item->str;
break;
case KDBUS_ITEM_CREDS:
/* privileged processes can impersonate somebody else */
if (!kdbus_bus_uid_is_privileged(bus))
- return -EPERM;
+ return ERR_PTR(-EPERM);
if (item->size != KDBUS_ITEM_SIZE(sizeof(*creds)))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
creds = &item->creds;
break;
case KDBUS_ITEM_SECLABEL:
/* privileged processes can impersonate somebody else */
if (!kdbus_bus_uid_is_privileged(bus))
- return -EPERM;
+ return ERR_PTR(-EPERM);
seclabel = item->str;
seclabel_len = item->size - KDBUS_ITEM_HEADER_SIZE;
case KDBUS_ITEM_CONN_NAME:
/* human-readable connection name (debugging) */
if (conn_name)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
conn_name = item->str;
break;
}
if ((is_activator || is_policy_holder) && !name)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
conn = kzalloc(sizeof(*conn), GFP_KERNEL);
if (!conn)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
if (is_activator || is_policy_holder) {
/*
/* init entry, so we can unconditionally remove it */
INIT_LIST_HEAD(&conn->monitor_entry);
- ret = kdbus_pool_new(conn->name, &conn->pool, hello->pool_size);
- if (ret < 0)
+ conn->pool = kdbus_pool_new(conn->name, hello->pool_size);
+ if (IS_ERR(conn->pool)) {
+ ret = PTR_ERR(conn->pool);
goto exit_unref_cred;
+ }
- ret = kdbus_match_db_new(&conn->match_db);
- if (ret < 0)
+ conn->match_db = kdbus_match_db_new();
+ if (IS_ERR(conn->match_db)) {
+ ret = PTR_ERR(conn->match_db);
goto exit_free_pool;
+ }
conn->bus = kdbus_bus_ref(ep->bus);
conn->ep = kdbus_ep_ref(ep);
/* privileged processes can impersonate somebody else */
if (creds || seclabel) {
- ret = kdbus_meta_new(&conn->owner_meta);
- if (ret < 0)
+ conn->owner_meta = kdbus_meta_new();
+ if (IS_ERR(conn->owner_meta)) {
+ ret = PTR_ERR(conn->owner_meta);
goto exit_release_names;
+ }
if (creds) {
ret = kdbus_meta_append_data(conn->owner_meta,
kdbus_notify_flush(conn->bus);
- *c = conn;
- return 0;
+ return conn;
exit_unref_user_unlock:
up_write(&bus->conn_rwlock);
kfree(conn->name);
kfree(conn);
- return ret;
+ return ERR_PTR(ret);
}
/**
struct kdbus_kmsg;
struct kdbus_name_registry;
-int kdbus_conn_new(struct kdbus_ep *ep,
- struct kdbus_cmd_hello *hello,
- struct kdbus_meta *meta,
- struct kdbus_conn **conn);
+struct kdbus_conn *kdbus_conn_new(struct kdbus_ep *ep,
+ struct kdbus_cmd_hello *hello,
+ struct kdbus_meta *meta);
struct kdbus_conn *kdbus_conn_ref(struct kdbus_conn *conn);
struct kdbus_conn *kdbus_conn_unref(struct kdbus_conn *conn);
int kdbus_conn_acquire(struct kdbus_conn *conn);
* @parent: Parent domain, NULL for initial one
* @name: Name of the domain, NULL for the initial one
* @mode: The access mode for the "control" device node
- * @domain: The returned domain
*
- * Return: 0 on success, negative errno on failure
+ * Return: a new kdbus_domain on success, ERR_PTR on failure
*/
-int kdbus_domain_new(struct kdbus_domain *parent, const char *name,
- umode_t mode, struct kdbus_domain **domain)
+struct kdbus_domain *kdbus_domain_new(struct kdbus_domain *parent,
+ const char *name, umode_t mode)
{
struct kdbus_domain *d;
int ret;
- BUG_ON(*domain);
-
if ((parent && !name) || (!parent && name))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
d = kzalloc(sizeof(*d), GFP_KERNEL);
if (!d)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
d->disconnected = true;
INIT_LIST_HEAD(&d->bus_list);
if (ret < 0) {
kdbus_domain_disconnect(d);
kdbus_domain_unref(d);
- return ret;
+ return ERR_PTR(ret);
}
- *domain = d;
- return 0;
+ return d;
exit_put:
put_device(&d->dev);
- return ret;
+ return ERR_PTR(ret);
}
/**
struct kdbus_domain *kdbus_domain_ref(struct kdbus_domain *domain);
struct kdbus_domain *kdbus_domain_unref(struct kdbus_domain *domain);
void kdbus_domain_disconnect(struct kdbus_domain *domain);
-int kdbus_domain_new(struct kdbus_domain *parent, const char *name,
- umode_t mode, struct kdbus_domain **domain);
+struct kdbus_domain *kdbus_domain_new(struct kdbus_domain *parent,
+ const char *name, umode_t mode);
int kdbus_domain_get_user_unlocked(struct kdbus_domain *domain,
kuid_t uid,
* @uid: The uid of the device node
* @gid: The gid of the device node
* @policy: Whether or not the endpoint should have a policy db
- * @ep: Pointer to a reference where the new endpoint is stored
*
* This function will create a new enpoint with the given
* name and properties for a given bus.
*
- * Return: 0 on success, negative errno on failure.
+ * Return: a new kdbus_ep on success, ERR_PTR on failure.
*/
-int kdbus_ep_new(struct kdbus_bus *bus, const char *name,
- umode_t mode, kuid_t uid, kgid_t gid,
- bool policy, struct kdbus_ep **ep)
+struct kdbus_ep *kdbus_ep_new(struct kdbus_bus *bus, const char *name,
+ umode_t mode, kuid_t uid, kgid_t gid,
+ bool policy)
{
struct kdbus_ep *e;
int ret;
e = kzalloc(sizeof(*e), GFP_KERNEL);
if (!e)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
e->disconnected = true;
mutex_init(&e->lock);
if (ret < 0) {
kdbus_ep_disconnect(e);
kdbus_ep_unref(e);
- return ret;
+ return ERR_PTR(ret);
}
- if (ep)
- *ep = e;
- return 0;
+ return e;
exit_put:
put_device(&e->dev);
- return ret;
+ return ERR_PTR(ret);
}
/**
bool has_policy : 1;
};
-int kdbus_ep_new(struct kdbus_bus *bus, const char *name,
- umode_t mode, kuid_t uid, kgid_t gid,
- bool policy, struct kdbus_ep **ep);
+struct kdbus_ep *kdbus_ep_new(struct kdbus_bus *bus, const char *name,
+ umode_t mode, kuid_t uid, kgid_t gid,
+ bool policy);
struct kdbus_ep *kdbus_ep_ref(struct kdbus_ep *ep);
struct kdbus_ep *kdbus_ep_unref(struct kdbus_ep *ep);
void kdbus_ep_disconnect(struct kdbus_ep *ep);
handle->domain = kdbus_domain_ref(handle->ep->bus->domain);
/* cache the metadata/credentials of the creator */
- ret = kdbus_meta_new(&handle->meta);
- if (ret < 0)
+ handle->meta = kdbus_meta_new();
+ if (IS_ERR(handle->meta)) {
+ ret = PTR_ERR(handle->meta);
goto exit_free;
+ }
ret = kdbus_meta_append(handle->meta, NULL, 0,
KDBUS_ATTACH_CREDS |
gid = current_fsgid();
}
- ret = kdbus_bus_new(handle->domain, make, name, &bloom,
- mode, current_fsuid(), gid, &bus);
- if (ret < 0)
+ bus = kdbus_bus_new(handle->domain, make, name, &bloom,
+ mode, current_fsuid(), gid);
+ if (IS_ERR(bus)) {
+ ret = PTR_ERR(bus);
break;
+ }
/* turn the control fd into a new bus owner device */
ret = kdbus_handle_transform(handle, KDBUS_HANDLE_CONTROL,
if (make->flags & KDBUS_MAKE_ACCESS_WORLD)
mode = 0666;
- ret = kdbus_domain_new(handle->domain, name, mode, &domain);
- if (ret < 0)
+ domain = kdbus_domain_new(handle->domain, name, mode);
+ if (IS_ERR(domain)) {
+ ret = PTR_ERR(domain);
break;
+ }
/* turn the control fd into a new domain owner device */
ret = kdbus_handle_transform(handle, KDBUS_HANDLE_CONTROL,
}
/* custom endpoints always have a policy db */
- ret = kdbus_ep_new(handle->ep->bus, name, mode,
- current_fsuid(), gid, true, &ep);
- if (ret < 0)
+ ep = kdbus_ep_new(handle->ep->bus, name, mode,
+ current_fsuid(), gid, true);
+ if (IS_ERR(ep)) {
+ ret = PTR_ERR(ep);
break;
+ }
ret = kdbus_ep_policy_set(ep, make->items,
KDBUS_ITEMS_SIZE(make, items));
break;
}
- ret = kdbus_conn_new(handle->ep, hello, handle->meta, &conn);
- if (ret < 0)
+ conn = kdbus_conn_new(handle->ep, hello, handle->meta);
+ if (IS_ERR(conn)) {
+ ret = PTR_ERR(conn);
break;
+ }
/* turn the ep fd into a new connection */
ret = kdbus_handle_transform(handle, KDBUS_HANDLE_EP,
break;
}
- ret = kdbus_kmsg_new_from_user(conn, buf, &kmsg);
- if (ret < 0)
+ kmsg = kdbus_kmsg_new_from_user(conn, buf);
+ if (IS_ERR(kmsg)) {
+ ret = PTR_ERR(kmsg);
break;
+ }
ret = kdbus_conn_kmsg_send(conn->ep, conn, kmsg);
if (ret < 0) {
* Create the initial domain; it is world-accessible and
* provides the /dev/kdbus/control device node.
*/
- ret = kdbus_domain_new(NULL, NULL, 0666, &kdbus_domain_init);
- if (ret < 0) {
+ kdbus_domain_init = kdbus_domain_new(NULL, NULL, 0666);
+ if (IS_ERR(kdbus_domain_init) < 0) {
+ ret = PTR_ERR(kdbus_domain_init);
pr_err("failed to initialize, error=%i\n", ret);
goto exit_minor;
}
/**
* kdbus_match_db_new() - create a new match database
- * @db: Pointer location for the returned database
*
- * Return: 0 on success, negative errno on failure.
+ * Return: a new kdbus_match_db on success, ERR_PTR on failure.
*/
-int kdbus_match_db_new(struct kdbus_match_db **db)
+struct kdbus_match_db *kdbus_match_db_new(void)
{
struct kdbus_match_db *d;
d = kzalloc(sizeof(*d), GFP_KERNEL);
if (!d)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
mutex_init(&d->entries_lock);
INIT_LIST_HEAD(&d->entries_list);
- *db = d;
- return 0;
+ return d;
}
static bool kdbus_match_bloom(const struct kdbus_bloom_filter *filter,
struct kdbus_kmsg;
struct kdbus_match_db;
-int kdbus_match_db_new(struct kdbus_match_db **db);
+struct kdbus_match_db *kdbus_match_db_new(void);
void kdbus_match_db_free(struct kdbus_match_db *db);
int kdbus_match_db_add(struct kdbus_conn *conn,
struct kdbus_cmd_match *cmd);
/**
* kdbus_kmsg_new() - allocate message
* @extra_size: additional size to reserve for data
- * @kmsg: Returned Message
*
- * Return: 0 on success, negative errno on failure.
+ * Return: new kdbus_kmsg on success, ERR_PTR on failure.
*/
-int kdbus_kmsg_new(size_t extra_size, struct kdbus_kmsg **kmsg)
+struct kdbus_kmsg *kdbus_kmsg_new(size_t extra_size)
{
struct kdbus_kmsg *m;
size_t size;
- BUG_ON(*kmsg);
-
size = sizeof(struct kdbus_kmsg) + KDBUS_ITEM_SIZE(extra_size);
m = kzalloc(size, GFP_KERNEL);
if (!m)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
m->msg.size = size - KDBUS_KMSG_HEADER_SIZE;
m->msg.items[0].size = KDBUS_ITEM_SIZE(extra_size);
- *kmsg = m;
- return 0;
+ return m;
}
static int kdbus_handle_check_file(struct file *file)
* kdbus_kmsg_new_from_user() - copy message from user memory
* @conn: Connection
* @msg: User-provided message
- * @kmsg: Copy of message
*
- * Return: 0 on success, negative errno on failure.
+ * Return: a new kdbus_kmsg on success, ERR_PTR on failure.
*/
-int kdbus_kmsg_new_from_user(struct kdbus_conn *conn,
- struct kdbus_msg __user *msg,
- struct kdbus_kmsg **kmsg)
+struct kdbus_kmsg *kdbus_kmsg_new_from_user(struct kdbus_conn *conn,
+ struct kdbus_msg __user *msg)
{
struct kdbus_kmsg *m;
u64 size, alloc_size;
int ret;
- BUG_ON(*kmsg);
-
if (!KDBUS_IS_ALIGNED8((unsigned long)msg))
- return -EFAULT;
+ return ERR_PTR(-EFAULT);
if (kdbus_size_get_user(&size, msg, struct kdbus_msg))
- return -EFAULT;
+ return ERR_PTR(-EFAULT);
if (size < sizeof(struct kdbus_msg) || size > KDBUS_MSG_MAX_SIZE)
- return -EMSGSIZE;
+ return ERR_PTR(-EMSGSIZE);
alloc_size = size + KDBUS_KMSG_HEADER_SIZE;
m = kmalloc(alloc_size, GFP_KERNEL);
if (!m)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
memset(m, 0, KDBUS_KMSG_HEADER_SIZE);
if (copy_from_user(&m->msg, msg, size)) {
}
m->msg.src_id = conn->id;
- *kmsg = m;
- return 0;
+ return m;
exit_free:
kdbus_kmsg_free(m);
- return ret;
+ return ERR_PTR(ret);
}
struct kdbus_ep;
struct kdbus_conn;
-int kdbus_kmsg_new(size_t extra_size, struct kdbus_kmsg **kmsg);
-int kdbus_kmsg_new_from_user(struct kdbus_conn *conn,
- struct kdbus_msg __user *msg,
- struct kdbus_kmsg **kmsg);
+struct kdbus_kmsg *kdbus_kmsg_new(size_t extra_size);
+struct kdbus_kmsg *kdbus_kmsg_new_from_user(struct kdbus_conn *conn,
+ struct kdbus_msg __user *msg);
void kdbus_kmsg_free(struct kdbus_kmsg *kmsg);
#endif
/**
* kdbus_meta_new() - create new metadata object
- * @meta: New metadata object
*
- * Return: 0 on success, negative errno on failure.
+ * Return: a new kdbus_meta object on success, ERR_PTR on failure.
*/
-int kdbus_meta_new(struct kdbus_meta **meta)
+struct kdbus_meta *kdbus_meta_new(void)
{
struct kdbus_meta *m;
- BUG_ON(*meta);
-
m = kzalloc(sizeof(*m), GFP_KERNEL);
if (!m)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
/*
* Remember the PID and user namespaces our credentials belong to;
m->pid_namespace = get_pid_ns(task_active_pid_ns(current));
m->user_namespace = get_user_ns(current_user_ns());
- *meta = m;
- return 0;
+ return m;
}
/**
* kdbus_meta_dup() - Duplicate a meta object
*
* @orig: The meta object to duplicate
- * @copy: Return pointer for the duplicated object
*
- * Return: 0 on success, -ENOMEM on memory allocation failures.
+ * Return: a new kdbus_meta object on success, ERR_PTR on failure.
*/
-int kdbus_meta_dup(const struct kdbus_meta *orig,
- struct kdbus_meta **copy)
+struct kdbus_meta *kdbus_meta_dup(const struct kdbus_meta *orig)
{
struct kdbus_meta *m;
- BUG_ON(!orig || !copy);
+ BUG_ON(!orig);
m = kmalloc(sizeof(*m), GFP_KERNEL);
if (!m)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
m->data = kmemdup(orig->data, orig->allocated_size, GFP_KERNEL);
if (!m->data) {
kfree(m);
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
}
m->pid_namespace = get_pid_ns(orig->pid_namespace);
m->allocated_size = orig->allocated_size;
m->size = orig->size;
- *copy = m;
- return 0;
+ return m;
}
/**
struct kdbus_conn;
-int kdbus_meta_new(struct kdbus_meta **meta);
-int kdbus_meta_dup(const struct kdbus_meta *orig,
- struct kdbus_meta **copy);
+struct kdbus_meta *kdbus_meta_new(void);
+struct kdbus_meta *kdbus_meta_dup(const struct kdbus_meta *orig);
int kdbus_meta_append_data(struct kdbus_meta *meta, u64 type,
const void *buf, size_t len);
int kdbus_meta_append(struct kdbus_meta *meta,
/**
* kdbus_name_registry_new() - create a new name registry
- * @reg: The returned name registry
*
- * Return: 0 on success, negative errno on failure.
+ * Return: a new kdbus_name_registry on success, ERR_PTR on failure.
*/
-int kdbus_name_registry_new(struct kdbus_name_registry **reg)
+struct kdbus_name_registry *kdbus_name_registry_new(void)
{
struct kdbus_name_registry *r;
r = kzalloc(sizeof(*r), GFP_KERNEL);
if (!r)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
hash_init(r->entries_hash);
init_rwsem(&r->rwlock);
- *reg = r;
- return 0;
+ return r;
}
static struct kdbus_name_entry *
struct kdbus_conn *activator;
};
-int kdbus_name_registry_new(struct kdbus_name_registry **reg);
+struct kdbus_name_registry *kdbus_name_registry_new(void);
void kdbus_name_registry_free(struct kdbus_name_registry *reg);
int kdbus_name_acquire(struct kdbus_name_registry *reg,
u64 cookie, u64 msg_type)
{
struct kdbus_kmsg *kmsg = NULL;
- int ret;
BUG_ON(id == 0);
- ret = kdbus_kmsg_new(0, &kmsg);
- if (ret < 0)
- return ret;
+ kmsg = kdbus_kmsg_new(0);
+ if (IS_ERR(kmsg))
+ return PTR_ERR(kmsg);
/*
* a kernel-generated notification can only contain one
spin_lock(&bus->notify_lock);
list_add_tail(&kmsg->queue_entry, &bus->notify_list);
spin_unlock(&bus->notify_lock);
- return ret;
+ return 0;
}
/**
{
struct kdbus_kmsg *kmsg = NULL;
size_t name_len, extra_size;
- int ret;
name_len = strlen(name) + 1;
extra_size = sizeof(struct kdbus_notify_name_change) + name_len;
- ret = kdbus_kmsg_new(extra_size, &kmsg);
- if (ret < 0)
- return ret;
+ kmsg = kdbus_kmsg_new(extra_size);
+ if (IS_ERR(kmsg))
+ return PTR_ERR(kmsg);
kmsg->msg.dst_id = KDBUS_DST_ID_BROADCAST;
kmsg->msg.src_id = KDBUS_SRC_ID_KERNEL;
spin_lock(&bus->notify_lock);
list_add_tail(&kmsg->queue_entry, &bus->notify_list);
spin_unlock(&bus->notify_lock);
- return ret;
+ return 0;
}
/**
int kdbus_notify_id_change(struct kdbus_bus *bus, u64 type, u64 id, u64 flags)
{
struct kdbus_kmsg *kmsg = NULL;
- int ret;
- ret = kdbus_kmsg_new(sizeof(struct kdbus_notify_id_change), &kmsg);
- if (ret < 0)
- return ret;
+ kmsg = kdbus_kmsg_new(sizeof(struct kdbus_notify_id_change));
+ if (IS_ERR(kmsg))
+ return PTR_ERR(kmsg);
kmsg->msg.dst_id = KDBUS_DST_ID_BROADCAST;
kmsg->msg.src_id = KDBUS_SRC_ID_KERNEL;
spin_lock(&bus->notify_lock);
list_add_tail(&kmsg->queue_entry, &bus->notify_list);
spin_unlock(&bus->notify_lock);
- return ret;
+ return 0;
}
/**
* kdbus_pool_new() - create a new pool
* @name: Name of the (deleted) file which shows up in
* /proc, used for debugging
- * @pool: Newly allocated pool
* @size: Maximum size of the pool
*
- * Return: 0 on success, negative errno on failure.
+ * Return: a new kdbus_pool on success, ERR_PTR on failure.
*/
-int kdbus_pool_new(const char *name, struct kdbus_pool **pool, size_t size)
+struct kdbus_pool *kdbus_pool_new(const char *name, size_t size)
{
struct kdbus_pool_slice *s;
struct kdbus_pool *p;
char *n = NULL;
int ret;
- BUG_ON(*pool);
-
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
if (name) {
n = kasprintf(GFP_KERNEL, KBUILD_MODNAME "-conn:%s", name);
list_add(&s->entry, &p->slices);
kdbus_pool_add_free_slice(p, s);
- *pool = p;
- return 0;
+ return p;
exit_put_write:
put_write_access(file_inode(f));
fput(f);
exit_free:
kfree(p);
- return ret;
+ return ERR_PTR(ret);
}
/**
struct kdbus_pool;
struct kdbus_pool_slice;
-int kdbus_pool_new(const char *name, struct kdbus_pool **pool, size_t size);
+struct kdbus_pool *kdbus_pool_new(const char *name, size_t size);
void kdbus_pool_free(struct kdbus_pool *pool);
size_t kdbus_pool_remain(struct kdbus_pool *pool);
int kdbus_pool_mmap(const struct kdbus_pool *pool, struct vm_area_struct *vma);