@@ -47,6 +47,22 @@ struct padata_mt_job_state {
47
47
static void padata_free_pd (struct parallel_data * pd );
48
48
static void __init padata_mt_helper (struct work_struct * work );
49
49
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
+
50
66
static int padata_index_to_cpu (struct parallel_data * pd , int cpu_index )
51
67
{
52
68
int cpu , target_cpu ;
@@ -206,7 +222,7 @@ int padata_do_parallel(struct padata_shell *ps,
206
222
if ((pinst -> flags & PADATA_RESET ))
207
223
goto out ;
208
224
209
- refcount_inc ( & pd -> refcnt );
225
+ padata_get_pd ( pd );
210
226
padata -> pd = pd ;
211
227
padata -> cb_cpu = * cb_cpu ;
212
228
@@ -380,8 +396,7 @@ static void padata_serial_worker(struct work_struct *serial_work)
380
396
}
381
397
local_bh_enable ();
382
398
383
- if (refcount_sub_and_test (cnt , & pd -> refcnt ))
384
- padata_free_pd (pd );
399
+ padata_put_pd_cnt (pd , cnt );
385
400
}
386
401
387
402
/**
@@ -688,8 +703,7 @@ static int padata_replace(struct padata_instance *pinst)
688
703
synchronize_rcu ();
689
704
690
705
list_for_each_entry_continue_reverse (ps , & pinst -> pslist , list )
691
- if (refcount_dec_and_test (& ps -> opd -> refcnt ))
692
- padata_free_pd (ps -> opd );
706
+ padata_put_pd (ps -> opd );
693
707
694
708
pinst -> flags &= ~PADATA_RESET ;
695
709
@@ -1137,8 +1151,7 @@ void padata_free_shell(struct padata_shell *ps)
1137
1151
mutex_lock (& ps -> pinst -> lock );
1138
1152
list_del (& ps -> list );
1139
1153
pd = rcu_dereference_protected (ps -> pd , 1 );
1140
- if (refcount_dec_and_test (& pd -> refcnt ))
1141
- padata_free_pd (pd );
1154
+ padata_put_pd (pd );
1142
1155
mutex_unlock (& ps -> pinst -> lock );
1143
1156
1144
1157
kfree (ps );
0 commit comments