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.
Showing the changes to kernel/workqueue.c (1 of 1 file). Show all
Unified · Split
| @@ -1912,14 +1912,14 @@ static void worker_detach_from_pool(struct worker *worker) · 1911 unmodified lines | ||
| 1912 | 1912 | */ |
| 1913 | 1913 | static struct worker *create_worker(struct worker_pool *pool) |
| 1914 | 1914 | { |
| 1915 | − struct worker *worker = NULL; | |
| 1916 | − int id = -1; | |
| 1915 | + struct worker *worker; | |
| 1916 | + int id; | |
| 1917 | 1917 | char id_buf[16]; |
| 1918 | 1918 | |
| 1919 | 1919 | /* ID is needed to determine kthread name */ |
| 1920 | − id = ida_simple_get(&pool->worker_ida, 0, 0, GFP_KERNEL); | |
| 1920 | + id = ida_alloc(&pool->worker_ida, GFP_KERNEL); | |
| 1921 | 1921 | if (id < 0) |
| 1922 | − goto fail; | |
| 1922 | + return NULL; | |
| 1923 | 1923 | |
| 1924 | 1924 | worker = alloc_worker(pool->node); |
| 1925 | 1925 | if (!worker) |
| @@ -1954,8 +1954,7 @@ static struct worker *create_worker(struct worker_pool *pool) · 28 unmodified lines | ||
| 1954 | 1954 | return worker; |
| 1955 | 1955 | |
| 1956 | 1956 | fail: |
| 1957 | − if (id >= 0) | |
| 1958 | − ida_simple_remove(&pool->worker_ida, id); | |
| 1957 | + ida_free(&pool->worker_ida, id); | |
| 1959 | 1958 | kfree(worker); |
| 1960 | 1959 | return NULL; |
| 1961 | 1960 | } |
| @@ -2378,7 +2377,7 @@ woke_up: · 416 unmodified lines | ||
| 2378 | 2377 | set_pf_worker(false); |
| 2379 | 2378 | |
| 2380 | 2379 | set_task_comm(worker->task, "kworker/dying"); |
| 2381 | − ida_simple_remove(&pool->worker_ida, worker->id); | |
| 2380 | + ida_free(&pool->worker_ida, worker->id); | |
| 2382 | 2381 | worker_detach_from_pool(worker); |
| 2383 | 2382 | kfree(worker); |
| 2384 | 2383 | return 0; |