Skip to content

Commit ae15420

Browse files
Chen Ridongherbertx
authored andcommitted
padata: add pd get/put refcnt helper
Add helpers for pd to get/put refcnt to make code consice. Signed-off-by: Chen Ridong <chenridong@huawei.com> Acked-by: Daniel Jordan <daniel.m.jordan@oracle.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 878d87f commit ae15420

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

kernel/padata.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ struct padata_mt_job_state {
4747
static void padata_free_pd(struct parallel_data *pd);
4848
static void __init padata_mt_helper(struct work_struct *work);
4949

50+
static inline void padata_get_pd(struct parallel_data *pd)
51+
{
52+
refcount_inc(&pd->refcnt);
53+
}
54+
55+
static inline void padata_put_pd_cnt(struct parallel_data *pd, int cnt)
56+
{
57+
if (refcount_sub_and_test(cnt, &pd->refcnt))
58+
padata_free_pd(pd);
59+
}
60+
61+
static inline void padata_put_pd(struct parallel_data *pd)
62+
{
63+
padata_put_pd_cnt(pd, 1);
64+
}
65+
5066
static int padata_index_to_cpu(struct parallel_data *pd, int cpu_index)
5167
{
5268
int cpu, target_cpu;
@@ -206,7 +222,7 @@ int padata_do_parallel(struct padata_shell *ps,
206222
if ((pinst->flags & PADATA_RESET))
207223
goto out;
208224

209-
refcount_inc(&pd->refcnt);
225+
padata_get_pd(pd);
210226
padata->pd = pd;
211227
padata->cb_cpu = *cb_cpu;
212228

@@ -380,8 +396,7 @@ static void padata_serial_worker(struct work_struct *serial_work)
380396
}
381397
local_bh_enable();
382398

383-
if (refcount_sub_and_test(cnt, &pd->refcnt))
384-
padata_free_pd(pd);
399+
padata_put_pd_cnt(pd, cnt);
385400
}
386401

387402
/**
@@ -681,8 +696,7 @@ static int padata_replace(struct padata_instance *pinst)
681696
synchronize_rcu();
682697

683698
list_for_each_entry_continue_reverse(ps, &pinst->pslist, list)
684-
if (refcount_dec_and_test(&ps->opd->refcnt))
685-
padata_free_pd(ps->opd);
699+
padata_put_pd(ps->opd);
686700

687701
pinst->flags &= ~PADATA_RESET;
688702

@@ -1124,8 +1138,7 @@ void padata_free_shell(struct padata_shell *ps)
11241138
mutex_lock(&ps->pinst->lock);
11251139
list_del(&ps->list);
11261140
pd = rcu_dereference_protected(ps->pd, 1);
1127-
if (refcount_dec_and_test(&pd->refcnt))
1128-
padata_free_pd(pd);
1141+
padata_put_pd(pd);
11291142
mutex_unlock(&ps->pinst->lock);
11301143

11311144
kfree(ps);

0 commit comments

Comments
 (0)