sched/core: Convert get_task_struct() to return the task
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 4 Jul 2019 22:13:23 +0000 (15:13 -0700)
committerIngo Molnar <mingo@kernel.org>
Thu, 25 Jul 2019 13:51:54 +0000 (15:51 +0200)
Returning the pointer that was passed in allows us to write
slightly more idiomatic code.  Convert a few users.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190704221323.24290-1-willy@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
include/linux/sched/task.h
kernel/events/core.c
kernel/irq/manage.c
kernel/locking/rtmutex.c
kernel/trace/trace_sched_wakeup.c

index 0497091e40c12326078554c5dda0155193075a9b..3d90ed8f75f0992e98d9169f087c74b8fd5a4d74 100644 (file)
@@ -105,7 +105,11 @@ extern void sched_exec(void);
 #define sched_exec()   {}
 #endif
 
-#define get_task_struct(tsk) do { refcount_inc(&(tsk)->usage); } while(0)
+static inline struct task_struct *get_task_struct(struct task_struct *t)
+{
+       refcount_inc(&t->usage);
+       return t;
+}
 
 extern void __put_task_struct(struct task_struct *t);
 
index 026a14541a38223669a021585f0539e9d45f7628..ea5e8139fe6282a6623b0a590d4f0e02df6d936f 100644 (file)
@@ -4089,10 +4089,8 @@ alloc_perf_context(struct pmu *pmu, struct task_struct *task)
                return NULL;
 
        __perf_event_init_context(ctx);
-       if (task) {
-               ctx->task = task;
-               get_task_struct(task);
-       }
+       if (task)
+               ctx->task = get_task_struct(task);
        ctx->pmu = pmu;
 
        return ctx;
@@ -10355,8 +10353,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
                 * and we cannot use the ctx information because we need the
                 * pmu before we get a ctx.
                 */
-               get_task_struct(task);
-               event->hw.target = task;
+               event->hw.target = get_task_struct(task);
        }
 
        event->clock = &local_clock;
index e8f7f179bf77e6a721deaaf349462edbc14ef8f3..9d50fbe5531a35a433d415bee40d391373890100 100644 (file)
@@ -1255,8 +1255,7 @@ setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary)
         * the thread dies to avoid that the interrupt code
         * references an already freed task_struct.
         */
-       get_task_struct(t);
-       new->thread = t;
+       new->thread = get_task_struct(t);
        /*
         * Tell the thread to set its affinity. This is
         * important for shared interrupt handlers as we do
index fa83d36e30c661e8d9200d236dab9f8fc3501929..2874bf55616201d74ba1d4c36279d9df621113ff 100644 (file)
@@ -628,8 +628,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
                }
 
                /* [10] Grab the next task, i.e. owner of @lock */
-               task = rt_mutex_owner(lock);
-               get_task_struct(task);
+               task = get_task_struct(rt_mutex_owner(lock));
                raw_spin_lock(&task->pi_lock);
 
                /*
@@ -709,8 +708,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
        }
 
        /* [10] Grab the next task, i.e. the owner of @lock */
-       task = rt_mutex_owner(lock);
-       get_task_struct(task);
+       task = get_task_struct(rt_mutex_owner(lock));
        raw_spin_lock(&task->pi_lock);
 
        /* [11] requeue the pi waiters if necessary */
index 743b2b520d34235135f2b85201b8a05622eb1c46..5e43b9664ecabb366dc8e81faa4d09d962084baa 100644 (file)
@@ -579,8 +579,7 @@ probe_wakeup(void *ignore, struct task_struct *p)
        else
                tracing_dl = 0;
 
-       wakeup_task = p;
-       get_task_struct(wakeup_task);
+       wakeup_task = get_task_struct(p);
 
        local_save_flags(flags);