From: Kay Sievers Date: Tue, 24 Dec 2013 17:57:17 +0000 (+0100) Subject: handle: do not put "ep" and "conn" in a union X-Git-Tag: upstream/0.20140120.123719~98 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e09cfdc8283be8e95edcc8c52a5d7110fd91785;p=platform%2Fcore%2Fsystem%2Fkdbus-bus.git handle: do not put "ep" and "conn" in a union --- diff --git a/TODO b/TODO index d6d19f1..8ce2233 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,7 @@ Features: - allow to update the metadata subscription bit mask - support the creation of anonymous buses + - implement EP_MAKE External API: - actually return compatible/incompatible flags to users diff --git a/bus.c b/bus.c index 2b0f43b..c8fba71 100644 --- a/bus.c +++ b/bus.c @@ -182,6 +182,8 @@ int kdbus_bus_new(struct kdbus_ns *ns, struct kdbus_bus *b; int ret; + BUG_ON(*bus); + /* enforce "$UID-" prefix */ snprintf(prefix, sizeof(prefix), "%u-", from_kuid(current_user_ns(), uid)); diff --git a/connection.c b/connection.c index 4c007ba..d22ff59 100644 --- a/connection.c +++ b/connection.c @@ -386,7 +386,8 @@ static int kdbus_conn_queue_insert(struct kdbus_conn *conn, } /* space for metadata/credential items */ - if (kmsg->meta->size > 0 && kmsg->meta->ns == conn->meta->ns) { + if (kmsg->meta && kmsg->meta->size > 0 && + kmsg->meta->ns == conn->meta->ns) { meta = msg_size; msg_size += kmsg->meta->size; } @@ -672,6 +673,13 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep, u64 deadline_ns = 0; int ret; + /* non-kernel senders append credentials/metadata */ + if (conn_src) { + ret = kdbus_meta_new(&kmsg->meta); + if (ret < 0) + return ret; + } + /* broadcast message */ if (msg->dst_id == KDBUS_DST_ID_BROADCAST) { unsigned int i; @@ -1468,6 +1476,8 @@ int kdbus_conn_new(struct kdbus_ep *ep, LIST_HEAD(notify_list); int ret; + BUG_ON(*c); + if (hello->conn_flags & KDBUS_HELLO_ACTIVATOR && hello->conn_flags & KDBUS_HELLO_MONITOR) return -EINVAL; diff --git a/handle.c b/handle.c index 5942ac9..d80af93 100644 --- a/handle.c +++ b/handle.c @@ -63,25 +63,28 @@ enum kdbus_handle_type { * @type: Type of this handle (KDBUS_HANDLE_*) * @ns: Namespace for this handle * @meta: Cached connection creator's metadata/credentials + * @ep The endpoint this handle owns, in case @type + * is KDBUS_HANDLE_EP * @ns_owner: The namespace this handle owns, in case @type * is KDBUS_HANDLE_CONTROL_NS_OWNER * @bus_owner: The bus this handle owns, in case @type * is KDBUS_HANDLE_CONTROL_BUS_OWNER + * @ep_owner The endpoint this handle owns, in case @type + * is KDBUS_HANDLE_EP_OWNER * @conn The connection this handle owns, in case @type * is KDBUS_HANDLE_EP, after HELLO it is * KDBUS_HANDLE_EP_CONNECTED - * @ep The endpoint this handle owns, in case @type - * is KDBUS_HANDLE_EP or KDBUS_HANDLE_EP_OWNER */ struct kdbus_handle { enum kdbus_handle_type type; struct kdbus_ns *ns; struct kdbus_meta *meta; + struct kdbus_ep *ep; union { struct kdbus_ns *ns_owner; struct kdbus_bus *bus_owner; + struct kdbus_ep *ep_owner; struct kdbus_conn *conn; - struct kdbus_ep *ep; }; }; @@ -166,8 +169,8 @@ static int kdbus_handle_release(struct inode *inode, struct file *file) break; case KDBUS_HANDLE_EP_OWNER: - kdbus_ep_disconnect(handle->ep); - kdbus_ep_unref(handle->ep); + kdbus_ep_disconnect(handle->ep_owner); + kdbus_ep_unref(handle->ep_owner); break; case KDBUS_HANDLE_EP: @@ -341,6 +344,7 @@ static long kdbus_handle_ioctl_ep(struct file *file, unsigned int cmd, gid = current_fsgid(); } + //FIXME: what to do with the holder connection now? ret = kdbus_ep_new(handle->ep->bus, handle->ep->bus->ns, n, mode, current_fsuid(), gid, make->flags & KDBUS_MAKE_POLICY_OPEN); @@ -509,7 +513,7 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd, case KDBUS_CMD_MSG_SEND: { /* submit a message which will be queued in the receiver */ - struct kdbus_kmsg *kmsg; + struct kdbus_kmsg *kmsg = NULL; if (!KDBUS_IS_ALIGNED8((uintptr_t)buf)) { ret = -EFAULT; diff --git a/message.c b/message.c index c3f8e25..2a17d28 100644 --- a/message.c +++ b/message.c @@ -54,17 +54,14 @@ int kdbus_kmsg_new(size_t extra_size, struct kdbus_kmsg **kmsg) { struct kdbus_kmsg *m; size_t size; - int ret; + + BUG_ON(*kmsg); size = sizeof(struct kdbus_kmsg) + KDBUS_ITEM_SIZE(extra_size); m = kzalloc(size, GFP_KERNEL); if (!m) return -ENOMEM; - ret = kdbus_meta_new(&m->meta); - if (ret < 0) - return ret; - m->msg.size = size - KDBUS_KMSG_HEADER_SIZE; m->msg.items[0].size = KDBUS_ITEM_SIZE(extra_size); @@ -249,6 +246,8 @@ int kdbus_kmsg_new_from_user(struct kdbus_conn *conn, u64 size, alloc_size; int ret; + BUG_ON(*kmsg); + if (!KDBUS_IS_ALIGNED8((unsigned long)msg)) return -EFAULT; @@ -281,10 +280,6 @@ int kdbus_kmsg_new_from_user(struct kdbus_conn *conn, if (ret < 0) goto exit_free; - ret = kdbus_meta_new(&m->meta); - if (ret < 0) - goto exit_free; - /* patch-in the source of this message */ m->msg.src_id = conn->id; diff --git a/metadata.c b/metadata.c index d89b11d..7c19921 100644 --- a/metadata.c +++ b/metadata.c @@ -38,6 +38,8 @@ int kdbus_meta_new(struct kdbus_meta **meta) { struct kdbus_meta *m; + BUG_ON(*meta); + m = kzalloc(sizeof(struct kdbus_meta), GFP_KERNEL); if (!m) return -ENOMEM; diff --git a/namespace.c b/namespace.c index 584d6d8..d955324 100644 --- a/namespace.c +++ b/namespace.c @@ -198,6 +198,8 @@ int kdbus_ns_new(struct kdbus_ns *parent, const char *name, umode_t mode, struct struct kdbus_ns *n; int ret; + BUG_ON(*ns); + if ((parent && !name) || (!parent && name)) return -EINVAL; diff --git a/notify.c b/notify.c index 7fb0afe..1d6c79f 100644 --- a/notify.c +++ b/notify.c @@ -24,7 +24,7 @@ static int kdbus_notify_reply(u64 id, u64 cookie, u64 msg_type, struct list_head *queue_list) { - struct kdbus_kmsg *kmsg; + struct kdbus_kmsg *kmsg = NULL; int ret; BUG_ON(id == 0); @@ -111,8 +111,8 @@ int kdbus_notify_name_change(u64 type, const char *name, struct list_head *queue_list) { + struct kdbus_kmsg *kmsg = NULL; size_t name_len; - struct kdbus_kmsg *kmsg; size_t extra_size; int ret; @@ -158,7 +158,7 @@ int kdbus_notify_name_change(u64 type, int kdbus_notify_id_change(u64 type, u64 id, u64 flags, struct list_head *queue_list) { - struct kdbus_kmsg *kmsg; + struct kdbus_kmsg *kmsg = NULL; int ret; ret = kdbus_kmsg_new(sizeof(struct kdbus_notify_id_change), &kmsg); diff --git a/policy.c b/policy.c index 31f1a16..cf7ed79 100644 --- a/policy.c +++ b/policy.c @@ -131,6 +131,8 @@ int kdbus_policy_db_new(struct kdbus_policy_db **db) { struct kdbus_policy_db *d; + BUG_ON(*db); + d = kzalloc(sizeof(*d), GFP_KERNEL); if (!d) return -ENOMEM; diff --git a/pool.c b/pool.c index 01d4cbb..6750831 100644 --- a/pool.c +++ b/pool.c @@ -294,6 +294,8 @@ int kdbus_pool_new(struct kdbus_pool **pool, size_t size) struct kdbus_slice *s; int ret; + BUG_ON(*pool); + p = kzalloc(sizeof(struct kdbus_pool), GFP_KERNEL); if (!p) return -ENOMEM;