History

ftrace/trivial: Clean up recordmcount.c to use Linux style comparisons

The Linux ftrace subsystem style for comparing is: var == 1 var > 0 and not: 1 == var 0 < var It is considered that Linux developers are smart enough not to do the if (var = 1) mistake.

Steven Rostedt committed 15 years ago

Commit dd5477f1 parent 449a66f2 files · +32 −32Browse files

Unified · Split

2 files
  1. scripts/recordmcount.c +24 −24
  2. scripts/recordmcount.h +8 −8
scripts/recordmcount.c+24−24
@@ -78,7 +78,7 @@ static off_t · 77 unmodified lines
7878 ulseek(int const fd, off_t const offset, int const whence)
7979 {
8080 off_t const w = lseek(fd, offset, whence);
81− if ((off_t)-1 == w) {
81+ if (w == (off_t)-1) {
8282 perror("lseek");
8383 fail_file();
8484 }
@@ -111,7 +111,7 @@ static void * · 26 unmodified lines
111111 umalloc(size_t size)
112112 {
113113 void *const addr = malloc(size);
114− if (0 == addr) {
114+ if (addr == 0) {
115115 fprintf(stderr, "malloc failed: %zu bytes\n", size);
116116 fail_file();
117117 }
@@ -136,7 +136,7 @@ static void *mmap_file(char const *fname) · 18 unmodified lines
136136 void *addr;
137137
138138 fd_map = open(fname, O_RDWR);
139− if (0 > fd_map || 0 > fstat(fd_map, &sb)) {
139+ if (fd_map < 0 || fstat(fd_map, &sb) < 0) {
140140 perror(fname);
141141 fail_file();
142142 }
@@ -147,7 +147,7 @@ static void *mmap_file(char const *fname) · 4 unmodified lines
147147 addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE,
148148 fd_map, 0);
149149 mmap_failed = 0;
150− if (MAP_FAILED == addr) {
150+ if (addr == MAP_FAILED) {
151151 mmap_failed = 1;
152152 addr = umalloc(sb.st_size);
153153 uread(fd_map, addr, sb.st_size);
@@ -206,12 +206,12 @@ static uint32_t (*w2)(uint16_t); · 52 unmodified lines
206206 static int
207207 is_mcounted_section_name(char const *const txtname)
208208 {
209− return 0 == strcmp(".text", txtname) ||
210− 0 == strcmp(".ref.text", txtname) ||
211− 0 == strcmp(".sched.text", txtname) ||
212− 0 == strcmp(".spinlock.text", txtname) ||
213− 0 == strcmp(".irqentry.text", txtname) ||
214− 0 == strcmp(".text.unlikely", txtname);
209+ return strcmp(".text", txtname) == 0 ||
210+ strcmp(".ref.text", txtname) == 0 ||
211+ strcmp(".sched.text", txtname) == 0 ||
212+ strcmp(".spinlock.text", txtname) == 0 ||
213+ strcmp(".irqentry.text", txtname) == 0 ||
214+ strcmp(".text.unlikely", txtname) == 0;
215215 }
216216
217217 /* 32 bit and 64 bit are very similar */
@@ -270,7 +270,7 @@ do_file(char const *const fname) · 52 unmodified lines
270270 fail_file();
271271 } break;
272272 case ELFDATA2LSB: {
273− if (1 != *(unsigned char const *)&endian) {
273+ if (*(unsigned char const *)&endian != 1) {
274274 /* main() is big endian, file.o is little endian. */
275275 w = w4rev;
276276 w2 = w2rev;
@@ -278,7 +278,7 @@ do_file(char const *const fname) · 1 unmodified line
278278 }
279279 } break;
280280 case ELFDATA2MSB: {
281− if (0 != *(unsigned char const *)&endian) {
281+ if (*(unsigned char const *)&endian != 0) {
282282 /* main() is little endian, file.o is big endian. */
283283 w = w4rev;
284284 w2 = w2rev;
@@ -286,9 +286,9 @@ do_file(char const *const fname) · 1 unmodified line
286286 }
287287 } break;
288288 } /* end switch */
289− if (0 != memcmp(ELFMAG, ehdr->e_ident, SELFMAG)
290− || ET_REL != w2(ehdr->e_type)
291− || EV_CURRENT != ehdr->e_ident[EI_VERSION]) {
289+ if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0
290+ || w2(ehdr->e_type) != ET_REL
291+ || ehdr->e_ident[EI_VERSION] != EV_CURRENT) {
292292 fprintf(stderr, "unrecognized ET_REL file %s\n", fname);
293293 fail_file();
294294 }
@@ -321,15 +321,15 @@ do_file(char const *const fname) · 26 unmodified lines
321321 fail_file();
322322 } break;
323323 case ELFCLASS32: {
324− if (sizeof(Elf32_Ehdr) != w2(ehdr->e_ehsize)
325− || sizeof(Elf32_Shdr) != w2(ehdr->e_shentsize)) {
324+ if (w2(ehdr->e_ehsize) != sizeof(Elf32_Ehdr)
325+ || w2(ehdr->e_shentsize) != sizeof(Elf32_Shdr)) {
326326 fprintf(stderr,
327327 "unrecognized ET_REL file: %s\n", fname);
328328 fail_file();
329329 }
330− if (EM_S390 == w2(ehdr->e_machine))
330+ if (w2(ehdr->e_machine) == EM_S390)
331331 reltype = R_390_32;
332− if (EM_MIPS == w2(ehdr->e_machine)) {
332+ if (w2(ehdr->e_machine) == EM_MIPS) {
333333 reltype = R_MIPS_32;
334334 is_fake_mcount32 = MIPS32_is_fake_mcount;
335335 }
@@ -337,15 +337,15 @@ do_file(char const *const fname) · 1 unmodified line
337337 } break;
338338 case ELFCLASS64: {
339339 Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr;
340− if (sizeof(Elf64_Ehdr) != w2(ghdr->e_ehsize)
341− || sizeof(Elf64_Shdr) != w2(ghdr->e_shentsize)) {
340+ if (w2(ghdr->e_ehsize) != sizeof(Elf64_Ehdr)
341+ || w2(ghdr->e_shentsize) != sizeof(Elf64_Shdr)) {
342342 fprintf(stderr,
343343 "unrecognized ET_REL file: %s\n", fname);
344344 fail_file();
345345 }
346− if (EM_S390 == w2(ghdr->e_machine))
346+ if (w2(ghdr->e_machine) == EM_S390)
347347 reltype = R_390_64;
348− if (EM_MIPS == w2(ghdr->e_machine)) {
348+ if (w2(ghdr->e_machine) == EM_MIPS) {
349349 reltype = R_MIPS_64;
350350 Elf64_r_sym = MIPS64_r_sym;
351351 Elf64_r_info = MIPS64_r_info;
@@ -371,7 +371,7 @@ main(int argc, char const *argv[]) · 19 unmodified lines
371371 }
372372
373373 /* Process each file in turn, allowing deep failure. */
374− for (--argc, ++argv; 0 < argc; --argc, ++argv) {
374+ for (--argc, ++argv; argc > 0; --argc, ++argv) {
375375 int const sjval = setjmp(jmpenv);
376376 int len;
377377
scripts/recordmcount.h+8−8
@@ -275,12 +275,12 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, · 274 unmodified lines
275275 Elf_Sym const *const symp =
276276 &sym0[Elf_r_sym(relp)];
277277 char const *symname = &str0[w(symp->st_name)];
278− char const *mcount = '_' == gpfx ? "_mcount" : "mcount";
278+ char const *mcount = gpfx == '_' ? "_mcount" : "mcount";
279279
280− if ('.' == symname[0])
280+ if (symname[0] == '.')
281281 ++symname; /* ppc64 hack */
282− if (0 == strcmp(mcount, symname) ||
283− (altmcount && 0 == strcmp(altmcount, symname)))
282+ if (strcmp(mcount, symname) == 0 ||
283+ (altmcount && strcmp(altmcount, symname) == 0))
284284 mcountsym = Elf_r_sym(relp);
285285 }
286286
@@ -290,7 +290,7 @@ static uint_t *sift_rel_mcount(uint_t *mlocp, · 3 unmodified lines
290290 mrelp->r_offset = _w(offbase
291291 + ((void *)mlocp - (void *)mloc0));
292292 Elf_r_info(mrelp, recsym, reltype);
293− if (sizeof(Elf_Rela) == rel_entsize) {
293+ if (rel_entsize == sizeof(Elf_Rela)) {
294294 ((Elf_Rela *)mrelp)->r_addend = addend;
295295 *mlocp++ = 0;
296296 } else
@@ -354,12 +354,12 @@ __has_rel_mcount(Elf_Shdr const *const relhdr, /* is SHT_REL or SHT_RELA */ · 57 unmodified lines
354354 Elf_Shdr const *const txthdr = &shdr0[w(relhdr->sh_info)];
355355 char const *const txtname = &shstrtab[w(txthdr->sh_name)];
356356
357− if (0 == strcmp("__mcount_loc", txtname)) {
357+ if (strcmp("__mcount_loc", txtname) == 0) {
358358 fprintf(stderr, "warning: __mcount_loc already exists: %s\n",
359359 fname);
360360 succeed_file();
361361 }
362− if (SHT_PROGBITS != w(txthdr->sh_type) ||
362+ if (w(txthdr->sh_type) != SHT_PROGBITS ||
363363 !is_mcounted_section_name(txtname))
364364 return NULL;
365365 return txtname;
@@ -370,7 +370,7 @@ static char const *has_rel_mcount(Elf_Shdr const *const relhdr, · 4 unmodified lines
370370 char const *const shstrtab,
371371 char const *const fname)
372372 {
373− if (SHT_REL != w(relhdr->sh_type) && SHT_RELA != w(relhdr->sh_type))
373+ if (w(relhdr->sh_type) != SHT_REL && w(relhdr->sh_type) != SHT_RELA)
374374 return NULL;
375375 return __has_rel_mcount(relhdr, shdr0, shstrtab, fname);
376376 }