Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/pai_ext: replace atomic_t with refcount_t

The s390 PMU of PAI extension 1 NNPA counters uses atomic_t for
reference counting. Replace this with the proper data type
refcount_t.

No functional change.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>

authored by

Thomas Richter and committed by
Alexander Gordeev
1f2597cd ecc758ce

+13 -10
+13 -10
arch/s390/kernel/perf_pai_ext.c
··· 50 50 struct pai_userdata *save; /* Area to store non-zero counters */ 51 51 enum paievt_mode mode; /* Type of event */ 52 52 unsigned int active_events; /* # of PAI Extension users */ 53 - unsigned int refcnt; 53 + refcount_t refcnt; 54 54 struct perf_event *event; /* Perf event for sampling */ 55 55 struct paiext_cb *paiext_cb; /* PAI extension control block area */ 56 56 }; ··· 60 60 }; 61 61 62 62 static struct paiext_root { /* Anchor to per CPU data */ 63 - int refcnt; /* Overall active events */ 63 + refcount_t refcnt; /* Overall active events */ 64 64 struct paiext_mapptr __percpu *mapptr; 65 65 } paiext_root; 66 66 67 67 /* Free per CPU data when the last event is removed. */ 68 68 static void paiext_root_free(void) 69 69 { 70 - if (!--paiext_root.refcnt) { 70 + if (refcount_dec_and_test(&paiext_root.refcnt)) { 71 71 free_percpu(paiext_root.mapptr); 72 72 paiext_root.mapptr = NULL; 73 73 } ··· 80 80 */ 81 81 static int paiext_root_alloc(void) 82 82 { 83 - if (++paiext_root.refcnt == 1) { 83 + if (!refcount_inc_not_zero(&paiext_root.refcnt)) { 84 84 /* The memory is already zeroed. */ 85 85 paiext_root.mapptr = alloc_percpu(struct paiext_mapptr); 86 86 if (!paiext_root.mapptr) { ··· 91 91 */ 92 92 return -ENOMEM; 93 93 } 94 + refcount_set(&paiext_root.refcnt, 1); 94 95 } 95 96 return 0; 96 97 } ··· 123 122 124 123 mutex_lock(&paiext_reserve_mutex); 125 124 cpump->event = NULL; 126 - if (!--cpump->refcnt) /* Last reference gone */ 125 + if (refcount_dec_and_test(&cpump->refcnt)) /* Last reference gone */ 127 126 paiext_free(mp); 128 127 paiext_root_free(); 129 128 mutex_unlock(&paiext_reserve_mutex); ··· 164 163 rc = -ENOMEM; 165 164 cpump = kzalloc(sizeof(*cpump), GFP_KERNEL); 166 165 if (!cpump) 167 - goto unlock; 166 + goto undo; 168 167 169 168 /* Allocate memory for counter area and counter extraction. 170 169 * These are ··· 184 183 GFP_KERNEL); 185 184 if (!cpump->save || !cpump->area || !cpump->paiext_cb) { 186 185 paiext_free(mp); 187 - goto unlock; 186 + goto undo; 188 187 } 188 + refcount_set(&cpump->refcnt, 1); 189 189 cpump->mode = a->sample_period ? PAI_MODE_SAMPLING 190 190 : PAI_MODE_COUNTING; 191 191 } else { ··· 197 195 if (cpump->mode == PAI_MODE_SAMPLING || 198 196 (cpump->mode == PAI_MODE_COUNTING && a->sample_period)) { 199 197 rc = -EBUSY; 200 - goto unlock; 198 + goto undo; 201 199 } 200 + refcount_inc(&cpump->refcnt); 202 201 } 203 202 204 203 rc = 0; 205 204 cpump->event = event; 206 - ++cpump->refcnt; 207 205 208 - unlock: 206 + undo: 209 207 if (rc) { 210 208 /* Error in allocation of event, decrement anchor. Since 211 209 * the event in not created, its destroy() function is never ··· 213 211 */ 214 212 paiext_root_free(); 215 213 } 214 + unlock: 216 215 mutex_unlock(&paiext_reserve_mutex); 217 216 /* If rc is non-zero, no increment of counter/sampler was done. */ 218 217 return rc;