handle: do not put "ep" and "conn" in a union
authorKay Sievers <kay@vrfy.org>
Tue, 24 Dec 2013 17:57:17 +0000 (18:57 +0100)
committerKay Sievers <kay@vrfy.org>
Tue, 24 Dec 2013 18:01:36 +0000 (19:01 +0100)
TODO
bus.c
connection.c
handle.c
message.c
metadata.c
namespace.c
notify.c
policy.c
pool.c

diff --git a/TODO b/TODO
index d6d19f19f2654341c77f33db95c59eac9cf18c19..8ce2233ec54514a97e23f6ade7a7970a934fbce3 100644 (file)
--- 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 2b0f43b7b381cc671acbb7b25303804dfad040b2..c8fba7179f7009f4c7a121c45b0f653d347d263e 100644 (file)
--- 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));
index 4c007ba85b8a343d3aa8ba2ba7ef005e104d07d5..d22ff59155cf65701d68ecc63e4038cdb8f531c4 100644 (file)
@@ -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;
index 5942ac9a3bf45a8bd4bdabe309d77e3ccfb403b2..d80af93224253ccdf083087328c2809e82be488b 100644 (file)
--- 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;
index c3f8e25c60488e1d8af6bbdd356510f3b78ffc34..2a17d286c4ff07feed674eb2191d8e4e9ac25a02 100644 (file)
--- 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;
 
index d89b11d4a20ed19ca630633cc001f95378fa4087..7c1992117e7ba4eb86bbf1c723e06877dd5d6a14 100644 (file)
@@ -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;
index 584d6d86e13e4922506a16c8f49d9af73f2d0ffe..d95532455639b0807cf02659e57e3a17bb7fe1a6 100644 (file)
@@ -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;
 
index 7fb0afe26a8b6d83175a86b175c78098d6c2100f..1d6c79f1eafea33ba33579b34f6e1ecc303209a6 100644 (file)
--- 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);
index 31f1a163be38aabb0c271ce9509f83f2cb805fde..cf7ed7954167528cfacb6856a93e6bf08fdb7da4 100644 (file)
--- 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 01d4cbb018f80b8aa32f6460df876f311c22e827..6750831f720c160709f0049cdf93abac0772516b 100644 (file)
--- 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;