trimming task_work: kill ->data
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 26 Jun 2012 18:10:04 +0000 (22:10 +0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 22 Jul 2012 19:57:54 +0000 (23:57 +0400)
get rid of the only user of ->data; this is _not_ the final variant - in the
end we'll have task_work and rcu_head identical and just use cred->rcu,
at which point the separate allocation will be gone completely.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
include/linux/task_work.h
kernel/irq/manage.c
security/keys/internal.h
security/keys/keyctl.c
security/keys/process_keys.c

index 294d5d5e90b1fe410da2330f0bd0dfce132a021d..627421c0e10816cb3d4a91eaafacb40a7044cc9d 100644 (file)
@@ -10,14 +10,12 @@ typedef void (*task_work_func_t)(struct task_work *);
 struct task_work {
        struct hlist_node hlist;
        task_work_func_t func;
-       void *data;
 };
 
 static inline void
-init_task_work(struct task_work *twork, task_work_func_t func, void *data)
+init_task_work(struct task_work *twork, task_work_func_t func)
 {
        twork->func = func;
-       twork->data = data;
 }
 
 int task_work_add(struct task_struct *task, struct task_work *twork, bool);
index 8c548232ba39daf0f7320d64f19d85775000201a..d1dd54734ce780742a089600946da6c35c7f09ed 100644 (file)
@@ -830,7 +830,7 @@ static int irq_thread(void *data)
 
        sched_setscheduler(current, SCHED_FIFO, &param);
 
-       init_task_work(&on_exit_work, irq_thread_dtor, NULL);
+       init_task_work(&on_exit_work, irq_thread_dtor);
        task_work_add(current, &on_exit_work, false);
 
        while (!irq_wait_for_interrupt(action)) {
index 3dcbf86b0d31b9c7c9c889c80dacf34f9b33adc6..b510a316874a68a52c275ce8f07502f6d1cc701e 100644 (file)
@@ -148,6 +148,10 @@ extern key_ref_t lookup_user_key(key_serial_t id, unsigned long flags,
 #define KEY_LOOKUP_PARTIAL     0x02
 #define KEY_LOOKUP_FOR_UNLINK  0x04
 
+struct kludge {        /* this will die off very soon */
+       struct task_work twork;
+       struct cred *cred;
+};
 extern long join_session_keyring(const char *name);
 extern void key_change_session_keyring(struct task_work *twork);
 
index 0f5b3f0272995dc7057f1306c346468174d3e464..26723caaad05bf55adc07f8dce00e53d46ac70a4 100644 (file)
@@ -1456,7 +1456,8 @@ long keyctl_session_to_parent(void)
 {
        struct task_struct *me, *parent;
        const struct cred *mycred, *pcred;
-       struct task_work *newwork, *oldwork;
+       struct kludge *newwork;
+       struct task_work *oldwork;
        key_ref_t keyring_r;
        struct cred *cred;
        int ret;
@@ -1466,7 +1467,7 @@ long keyctl_session_to_parent(void)
                return PTR_ERR(keyring_r);
 
        ret = -ENOMEM;
-       newwork = kmalloc(sizeof(struct task_work), GFP_KERNEL);
+       newwork = kmalloc(sizeof(struct kludge), GFP_KERNEL);
        if (!newwork)
                goto error_keyring;
 
@@ -1478,7 +1479,8 @@ long keyctl_session_to_parent(void)
                goto error_newwork;
 
        cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r);
-       init_task_work(newwork, key_change_session_keyring, cred);
+       init_task_work(&newwork->twork, key_change_session_keyring);
+       newwork->cred = cred;
 
        me = current;
        rcu_read_lock();
@@ -1527,18 +1529,18 @@ long keyctl_session_to_parent(void)
 
        /* the replacement session keyring is applied just prior to userspace
         * restarting */
-       ret = task_work_add(parent, newwork, true);
+       ret = task_work_add(parent, &newwork->twork, true);
        if (!ret)
                newwork = NULL;
 unlock:
        write_unlock_irq(&tasklist_lock);
        rcu_read_unlock();
        if (oldwork) {
-               put_cred(oldwork->data);
+               put_cred(container_of(oldwork, struct kludge, twork)->cred);
                kfree(oldwork);
        }
        if (newwork) {
-               put_cred(newwork->data);
+               put_cred(newwork->cred);
                kfree(newwork);
        }
        return ret;
index 4ad54eea1ea45554d5d931497671fdb32a33660b..c9b07c97d7f2b31f9181429deb967a127442c6da 100644 (file)
@@ -837,9 +837,10 @@ error:
 void key_change_session_keyring(struct task_work *twork)
 {
        const struct cred *old = current_cred();
-       struct cred *new = twork->data;
+       struct kludge *p = container_of(twork, struct kludge, twork);
+       struct cred *new = p->cred;
 
-       kfree(twork);
+       kfree(p);
        if (unlikely(current->flags & PF_EXITING)) {
                put_cred(new);
                return;