Skip to content

Commit

Permalink
workqueue: Replace deprecated ida_simple_*() with ida_alloc()/ida_free()
Browse files Browse the repository at this point in the history
Replace ida_simple_get() with ida_alloc() and ida_simple_remove() with
ida_free(), the latter is more concise and intuitive.

In addition, if ida_alloc() fails, NULL is returned directly. This
eliminates unnecessary initialization of two local variables and an 'if'
judgment.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Zhen Lei authored and Tejun Heo committed Aug 9, 2021
1 parent 67dc832 commit e441b56
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1912,14 +1912,14 @@ static void worker_detach_from_pool(struct worker *worker)
*/
static struct worker *create_worker(struct worker_pool *pool)
{
struct worker *worker = NULL;
int id = -1;
struct worker *worker;
int id;
char id_buf[16];

/* ID is needed to determine kthread name */
id = ida_simple_get(&pool->worker_ida, 0, 0, GFP_KERNEL);
id = ida_alloc(&pool->worker_ida, GFP_KERNEL);
if (id < 0)
goto fail;
return NULL;

worker = alloc_worker(pool->node);
if (!worker)
Expand Down Expand Up @@ -1954,8 +1954,7 @@ static struct worker *create_worker(struct worker_pool *pool)
return worker;

fail:
if (id >= 0)
ida_simple_remove(&pool->worker_ida, id);
ida_free(&pool->worker_ida, id);
kfree(worker);
return NULL;
}
Expand Down Expand Up @@ -2378,7 +2377,7 @@ static int worker_thread(void *__worker)
set_pf_worker(false);

set_task_comm(worker->task, "kworker/dying");
ida_simple_remove(&pool->worker_ida, worker->id);
ida_free(&pool->worker_ida, worker->id);
worker_detach_from_pool(worker);
kfree(worker);
return 0;
Expand Down

0 comments on commit e441b56

Please sign in to comment.