Commit ab40c5c6b6861ee71fd97f2611027b01e9ec4da0

Authored by Masami Hiramatsu
Committed by Linus Torvalds
1 parent 46bae1a9a7

[PATCH] kprobes: replace magic numbers with enum

Replace the magic numbers with an enum, and gets rid of a warning on the
specific architectures (ex.  powerpc) on which the compiler considers
'char' as 'unsigned char'.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Prasanna S Panchamukhi <prasanna@in.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 13 additions and 7 deletions Side-by-side Diff

... ... @@ -87,6 +87,12 @@
87 87 int ngarbage;
88 88 };
89 89  
  90 +enum kprobe_slot_state {
  91 + SLOT_CLEAN = 0,
  92 + SLOT_DIRTY = 1,
  93 + SLOT_USED = 2,
  94 +};
  95 +
90 96 static struct hlist_head kprobe_insn_pages;
91 97 static int kprobe_garbage_slots;
92 98 static int collect_garbage_slots(void);
... ... @@ -130,8 +136,8 @@
130 136 if (kip->nused < INSNS_PER_PAGE) {
131 137 int i;
132 138 for (i = 0; i < INSNS_PER_PAGE; i++) {
133   - if (!kip->slot_used[i]) {
134   - kip->slot_used[i] = 1;
  139 + if (kip->slot_used[i] == SLOT_CLEAN) {
  140 + kip->slot_used[i] = SLOT_USED;
135 141 kip->nused++;
136 142 return kip->insns + (i * MAX_INSN_SIZE);
137 143 }
... ... @@ -163,8 +169,8 @@
163 169 }
164 170 INIT_HLIST_NODE(&kip->hlist);
165 171 hlist_add_head(&kip->hlist, &kprobe_insn_pages);
166   - memset(kip->slot_used, 0, INSNS_PER_PAGE);
167   - kip->slot_used[0] = 1;
  172 + memset(kip->slot_used, SLOT_CLEAN, INSNS_PER_PAGE);
  173 + kip->slot_used[0] = SLOT_USED;
168 174 kip->nused = 1;
169 175 kip->ngarbage = 0;
170 176 return kip->insns;
... ... @@ -173,7 +179,7 @@
173 179 /* Return 1 if all garbages are collected, otherwise 0. */
174 180 static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
175 181 {
176   - kip->slot_used[idx] = 0;
  182 + kip->slot_used[idx] = SLOT_CLEAN;
177 183 kip->nused--;
178 184 if (kip->nused == 0) {
179 185 /*
... ... @@ -212,7 +218,7 @@
212 218 continue;
213 219 kip->ngarbage = 0; /* we will collect all garbages */
214 220 for (i = 0; i < INSNS_PER_PAGE; i++) {
215   - if (kip->slot_used[i] == -1 &&
  221 + if (kip->slot_used[i] == SLOT_DIRTY &&
216 222 collect_one_slot(kip, i))
217 223 break;
218 224 }
... ... @@ -232,7 +238,7 @@
232 238 slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) {
233 239 int i = (slot - kip->insns) / MAX_INSN_SIZE;
234 240 if (dirty) {
235   - kip->slot_used[i] = -1;
  241 + kip->slot_used[i] = SLOT_DIRTY;
236 242 kip->ngarbage++;
237 243 } else {
238 244 collect_one_slot(kip, i);