All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Blanchard <anton@samba.org>
To: Simon Horman <horms@verge.net.au>, Matt Evans <matt@ozlabs.org>,
	Michael Neuling <mikey@neuling.org>,
	Milton Miller <miltonm@bga.com>,
	amodra@gmail.com
Cc: kexec@lists.infradead.org
Subject: [PATCH 3/3] kexec-tools: powerpc: Cleanup relocation code
Date: Mon, 14 Nov 2011 18:56:22 +1100	[thread overview]
Message-ID: <20111114185622.79fe0a18@kryten> (raw)
In-Reply-To: <20111114185329.19ddc2b4@kryten>


Some cleanup of the relocation code:

- Whitespace changes
- Use braces to add clarity to nested for/if loop.
- Order ADDR16 relocations
- No need for to return from a void function.

Signed-off-by: Anton Blanchard <anton@samba.org>
---

Index: kexec-tools/kexec/arch/ppc64/kexec-elf-rel-ppc64.c
===================================================================
--- kexec-tools.orig/kexec/arch/ppc64/kexec-elf-rel-ppc64.c	2011-11-14 18:06:07.492903716 +1100
+++ kexec-tools/kexec/arch/ppc64/kexec-elf-rel-ppc64.c	2011-11-14 18:09:14.168245553 +1100
@@ -16,6 +16,7 @@ int machine_verify_elf_rel(struct mem_eh
 	if (ehdr->e_machine != EM_PPC64) {
 		return 0;
 	}
+
 	return 1;
 }
 
@@ -23,13 +24,16 @@ static struct mem_shdr *toc_section(cons
 {
 	struct mem_shdr *shdr, *shdr_end;
 	unsigned char *strtab;
+
 	strtab = (unsigned char *)ehdr->e_shdr[ehdr->e_shstrndx].sh_data;
 	shdr_end = &ehdr->e_shdr[ehdr->e_shnum];
-	for(shdr = ehdr->e_shdr; shdr != shdr_end; shdr++)
-		if ( shdr->sh_size &&
-			strcmp((char *)&strtab[shdr->sh_name],
-						".toc") == 0)
+	for (shdr = ehdr->e_shdr; shdr != shdr_end; shdr++) {
+		if (shdr->sh_size &&
+			strcmp((char *)&strtab[shdr->sh_name], ".toc") == 0) {
 			return shdr;
+		}
+	}
+
 	return NULL;
 }
 
@@ -39,10 +43,12 @@ static struct mem_shdr *toc_section(cons
 unsigned long my_r2(const struct mem_ehdr *ehdr)
 {
 	struct mem_shdr *shdr;
+
 	shdr = toc_section(ehdr);
 	if (!shdr) {
 		die("TOC reloc without a toc section?");
 	}
+
 	return shdr->sh_addr + 0x8000;
 }
 
@@ -112,14 +118,13 @@ void machine_apply_elf_rel(struct mem_eh
 	case R_PPC64_REL24:
 		/* Convert value to relative */
 		value -= address;
-		if (value + 0x2000000 > 0x3ffffff || (value & 3) != 0){
-			die("REL24 %li out of range!\n",
-				(long int)value);
+		if (value + 0x2000000 > 0x3ffffff || (value & 3) != 0) {
+			die("REL24 %li out of range!\n", (long int)value);
 		}
 
 		/* Only replace bits 2 through 26 */
-		*(uint32_t *)location = (*(uint32_t *)location & ~0x03fffffc)
-					| (value & 0x03fffffc);
+		*(uint32_t *)location = (*(uint32_t *)location & ~0x03fffffc) |
+					(value & 0x03fffffc);
 		break;
 
 	case R_PPC64_ADDR16_LO:
@@ -127,23 +132,23 @@ void machine_apply_elf_rel(struct mem_eh
 		break;
 
 	case R_PPC64_ADDR16_HI:
-		*(uint16_t *)location = (value>>16) & 0xffff;
+		*(uint16_t *)location = (value >> 16) & 0xffff;
 		break;
 
 	case R_PPC64_ADDR16_HA:
-		*(uint16_t *)location = (((value+0x8000)>>16)  & 0xffff);
+		*(uint16_t *)location = (((value + 0x8000) >> 16) & 0xffff);
 		break;
 
-	case R_PPC64_ADDR16_HIGHEST:
-		*(uint16_t *)location = (((uint64_t)value>>48)  & 0xffff);
-		break;
 	case R_PPC64_ADDR16_HIGHER:
-		*(uint16_t *)location = (((uint64_t)value>>32)  & 0xffff);
+		*(uint16_t *)location = (((uint64_t)value >> 32) & 0xffff);
+		break;
+
+	case R_PPC64_ADDR16_HIGHEST:
+		*(uint16_t *)location = (((uint64_t)value >> 48) & 0xffff);
 		break;
 
 	default:
 		die("Unknown rela relocation: %lu\n", r_type);
 		break;
 	}
-	return;
 }

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2011-11-14  8:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-14  7:53 [PATCH 1/3] kexec-tools: powerpc: Fix 64bit optimize for size (gcc -Os) build Anton Blanchard
2011-11-14  7:54 ` [PATCH 2/3] kexec-tools: powerpc: Add more 64bit relocations Anton Blanchard
2011-11-14  7:56 ` Anton Blanchard [this message]
2011-11-14  8:46 ` [PATCH 1/3] kexec-tools: powerpc: Fix 64bit optimize for size (gcc -Os) build Simon Horman
2011-11-14 22:14 ` Alan Modra
2011-11-14 22:24   ` Anton Blanchard
2011-11-14 22:30     ` Alan Modra
2011-11-17 23:48       ` Simon Horman
2011-11-28 11:49         ` Anton Blanchard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111114185622.79fe0a18@kryten \
    --to=anton@samba.org \
    --cc=amodra@gmail.com \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.org \
    --cc=matt@ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=miltonm@bga.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.