public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhang Yanfei <zhangyanfei.yes@gmail.com>
To: Simon Horman <horms@verge.net.au>
Cc: "kexec@lists.infradead.org" <kexec@lists.infradead.org>
Subject: [PATCH v2 04/13] kexec: use _ALIGN* to make the logic clear
Date: Thu, 14 Mar 2013 19:24:46 +0800	[thread overview]
Message-ID: <5141B37E.50205@gmail.com> (raw)
In-Reply-To: <20130314095852.GY11196@verge.net.au>

From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

By replacing all the explicit align opertion with marco _ALIGN*,
the code logic could more clear.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/crashdump-elf.c          |    3 +--
 kexec/fs2dt.c                  |    5 ++---
 kexec/kexec-elf-boot.c         |    2 +-
 kexec/kexec-elf-rel.c          |    8 ++++----
 kexec/kexec-elf.c              |    8 ++++----
 kexec/kexec.c                  |   15 +++++++--------
 kexec/libfdt/libfdt_internal.h |    2 +-
 7 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/kexec/crashdump-elf.c b/kexec/crashdump-elf.c
index ec66548..2baa357 100644
--- a/kexec/crashdump-elf.c
+++ b/kexec/crashdump-elf.c
@@ -96,8 +96,7 @@ int FUNC(struct kexec_info *info,
 		return -1;
 	}
 
-	sz += align - 1;
-	sz &= ~(align - 1);
+	sz = _ALIGN(sz, align);
 
 	bufp = xmalloc(sz);
 	memset(bufp, 0, sz);
diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
index 5d933c8..bd972ba 100644
--- a/kexec/fs2dt.c
+++ b/kexec/fs2dt.c
@@ -697,8 +697,7 @@ static void add_boot_block(char **bufp, off_t *sizep)
 	unsigned long tlen, toff;
 	char *buf;
 
-	len = sizeof(bb[0]);
-	len += 7; len &= ~7;
+	len = _ALIGN(sizeof(bb[0]), 8);
 
 	bb->off_mem_rsvmap = cpu_to_be32(len);
 
@@ -721,7 +720,7 @@ static void add_boot_block(char **bufp, off_t *sizep)
 
 	len = propnum("");
 	bb->dt_strings_size = cpu_to_be32(len);
-	len +=  3; len &= ~3;
+	len = _ALIGN(len, 4);
 	bb->totalsize = cpu_to_be32(be32_to_cpu(bb->off_dt_strings) + len);
 
 	bb->magic = cpu_to_be32(0xd00dfeed);
diff --git a/kexec/kexec-elf-boot.c b/kexec/kexec-elf-boot.c
index f082f8b..38f9056 100644
--- a/kexec/kexec-elf-boot.c
+++ b/kexec/kexec-elf-boot.c
@@ -31,7 +31,7 @@
 #include "kexec-elf-boot.h"
 
 
-#define UPSZ(X) ((sizeof(X) + 3) &~3)
+#define UPSZ(X) _ALIGN_UP(sizeof(X), 4)
 
 static struct boot_notes {
 	Elf_Bhdr hdr;
diff --git a/kexec/kexec-elf-rel.c b/kexec/kexec-elf-rel.c
index 8880c8b..38e34ec 100644
--- a/kexec/kexec-elf-rel.c
+++ b/kexec/kexec-elf-rel.c
@@ -225,7 +225,7 @@ int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,
 				buf_align = align;
 			}
 			/* Now align bufsz */
-			bufsz = (bufsz + (align - 1)) & ~(align - 1);
+			bufsz = _ALIGN(bufsz, align);
 			/* And now add our buffer */
 			bufsz += shdr->sh_size;
 		}
@@ -237,7 +237,7 @@ int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,
 				bss_align = align;
 			}
 			/* Now align bsssz */
-			bsssz = (bsssz + (align - 1)) & ~(align -1);
+			bsssz = _ALIGN(bsssz, align);
 			/* And now add our buffer */
 			bsssz += shdr->sh_size;
 		}
@@ -269,7 +269,7 @@ int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,
 		if (shdr->sh_type != SHT_NOBITS) {
 			unsigned long off;
 			/* Adjust the address */
-			data_addr = (data_addr + (align - 1)) & ~(align -1);
+			data_addr = _ALIGN(data_addr, align);
 
 			/* Update the section */
 			off = data_addr - buf_addr;
@@ -281,7 +281,7 @@ int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,
 			data_addr += shdr->sh_size;
 		} else {
 			/* Adjust the address */
-			bss_addr = (bss_addr + (align - 1)) & ~(align -1);
+			bss_addr = _ALIGN(bss_addr, align);
 
 			/* Update the section */
 			shdr->sh_addr = bss_addr;
diff --git a/kexec/kexec-elf.c b/kexec/kexec-elf.c
index b88aced..3515203 100644
--- a/kexec/kexec-elf.c
+++ b/kexec/kexec-elf.c
@@ -704,8 +704,8 @@ static int build_mem_notes(struct mem_ehdr *ehdr)
 		ElfNN_Nhdr hdr;
 		read_nhdr(ehdr, &hdr, note);
 		note_size  = sizeof(hdr);
-		note_size += (hdr.n_namesz + 3) & ~3;
-		note_size += (hdr.n_descsz + 3) & ~3;
+		note_size += _ALIGN(hdr.n_namesz, 4);
+		note_size += _ALIGN(hdr.n_descsz, 4);
 		ehdr->e_notenum += 1;
 	}
 	/* Now walk and normalize the notes */
@@ -716,9 +716,9 @@ static int build_mem_notes(struct mem_ehdr *ehdr)
 		read_nhdr(ehdr, &hdr, note);
 		note_size  = sizeof(hdr);
 		name       = note + note_size;
-		note_size += (hdr.n_namesz + 3) & ~3;
+		note_size += _ALIGN(hdr.n_namesz, 4);
 		desc       = note + note_size;
-		note_size += (hdr.n_descsz + 3) & ~3;
+		note_size += _ALIGN(hdr.n_descsz, 4);
 
 		if ((hdr.n_namesz != 0) && (name[hdr.n_namesz -1] != '\0')) {
 			/* If note name string is not null terminated, just
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 494c5b3..f3928af 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -257,8 +257,7 @@ unsigned long locate_hole(struct kexec_info *info,
 		if (start < hole_min) {
 			start = hole_min;
 		}
-		start = (start + hole_align - 1) &
-			~((unsigned long long)hole_align - 1);
+		start = _ALIGN(start, hole_align);
 		if (end > mem_max) {
 			end = mem_max;
 		}
@@ -276,8 +275,8 @@ unsigned long locate_hole(struct kexec_info *info,
 				hole_base = start;
 				break;
 			} else {
-				hole_base = (end - hole_size) &
-					~((unsigned long long)hole_align - 1);
+				hole_base = _ALIGN_DOWN(end - hole_size,
+					hole_align);
 			}
 		}
 	}
@@ -313,7 +312,7 @@ void add_segment_phys_virt(struct kexec_info *info,
 
 	/* Round memsz up to a multiple of pagesize */
 	pagesize = getpagesize();
-	memsz = (memsz + (pagesize - 1)) & ~(pagesize - 1);
+	memsz = _ALIGN(memsz, pagesize);
 
 	/* Verify base is pagesize aligned.
 	 * Finding a way to cope with this problem
@@ -363,7 +362,7 @@ unsigned long add_buffer_phys_virt(struct kexec_info *info,
 
 	/* Round memsz up to a multiple of pagesize */
 	pagesize = getpagesize();
-	memsz = (memsz + (pagesize - 1)) & ~(pagesize - 1);
+	memsz = _ALIGN(memsz, pagesize);
 
 	base = locate_hole(info, memsz, buf_align, buf_min, buf_max, buf_end);
 	if (base == ULONG_MAX) {
@@ -457,8 +456,8 @@ int add_backup_segments(struct kexec_info *info, unsigned long backup_base,
 				return -1;
 			if (!find_segment_hole(info, &bkseg_base, &bkseg_size))
 				break;
-			start = (bkseg_base + pagesize - 1) & ~(pagesize - 1);
-			end = (bkseg_base + bkseg_size) & ~(pagesize - 1);
+			start = _ALIGN(bkseg_base, pagesize);
+			end = _ALIGN_DOWN(bkseg_base + bkseg_size, pagesize);
 			add_segment_phys_virt(info, NULL, 0,
 					      start, end-start, 0);
 			mem_size = mem_base + mem_size - \
diff --git a/kexec/libfdt/libfdt_internal.h b/kexec/libfdt/libfdt_internal.h
index 46eb93e..3635d98 100644
--- a/kexec/libfdt/libfdt_internal.h
+++ b/kexec/libfdt/libfdt_internal.h
@@ -52,7 +52,7 @@
  */
 #include <fdt.h>
 
-#define FDT_ALIGN(x, a)		(((x) + (a) - 1) & ~((a) - 1))
+#define FDT_ALIGN(x, a)		_ALIGN(x, a)
 #define FDT_TAGALIGN(x)		(FDT_ALIGN((x), FDT_TAGSIZE))
 
 #define FDT_CHECK_HEADER(fdt) \
-- 
1.7.1


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

  reply	other threads:[~2013-03-14 11:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
2013-03-13 17:21 ` [PATCH 02/13] kexec: use _ALIGN() instead of align() Zhang Yanfei
2013-03-14  9:48   ` Simon Horman
2013-03-13 17:23 ` [PATCH 03/13] kexec: ppc: remove duplicated _ALIGN_* macros Zhang Yanfei
2013-03-14  9:48   ` Simon Horman
2013-03-13 17:26 ` [PATCH 04/13] kexec: use _ALIGN* to make the logic clear Zhang Yanfei
2013-03-14  9:08   ` Simon Horman
2013-03-14  9:48     ` Zhang Yanfei
2013-03-14 10:06       ` Simon Horman
2013-03-14  9:49     ` Simon Horman
2013-03-14  9:58       ` Simon Horman
2013-03-14 11:24         ` Zhang Yanfei [this message]
2013-03-14 11:26         ` Zhang Yanfei
2013-03-15  8:35           ` Simon Horman
2013-03-15  9:46             ` [PATCH v3 " Zhang Yanfei
2013-03-15 15:52               ` Simon Horman
2013-03-13 17:28 ` [PATCH 05/13] kexec: i386: " Zhang Yanfei
2013-03-14  9:50   ` Simon Horman
2013-03-13 17:29 ` [PATCH 06/13] kexec: arm: " Zhang Yanfei
2013-03-14  9:50   ` Simon Horman
2013-03-13 17:30 ` [PATCH 07/13] kexec: ia64: " Zhang Yanfei
2013-03-14  9:50   ` Simon Horman
2013-03-13 17:31 ` [PATCH 08/13] kexec: mips: " Zhang Yanfei
2013-03-14  9:51   ` Simon Horman
2013-03-13 17:32 ` [PATCH 09/13] kexec: ppc: " Zhang Yanfei
2013-03-14  9:09   ` Simon Horman
2013-03-14  9:32     ` Zhang Yanfei
2013-03-14  9:33   ` [PATCH v2 " Zhang Yanfei
2013-03-14  9:54     ` Simon Horman
2013-03-14  9:57       ` Simon Horman
2013-03-14 10:01         ` Simon Horman
2013-03-13 17:33 ` [PATCH 10/13] kexec: ppc64: " Zhang Yanfei
2013-03-14  9:23   ` Simon Horman
2013-03-14  9:38   ` [PATCH v2 " Zhang Yanfei
2013-03-14 10:04     ` Simon Horman
2013-03-13 17:33 ` [PATCH 11/13] kexec: s390: remove ALIGN_UP and use _ALIGN_UP Zhang Yanfei
2013-03-14 10:02   ` Simon Horman
2013-03-13 17:34 ` [PATCH 12/13] kexec: sh: use _ALIGN* to make the logic clear Zhang Yanfei
2013-03-14 10:03   ` Simon Horman
2013-03-13 17:35 ` [PATCH 13/13] kexec: x86_64: " Zhang Yanfei
2013-03-14 10:03   ` Simon Horman
2013-03-14  9:47 ` [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Simon Horman

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=5141B37E.50205@gmail.com \
    --to=zhangyanfei.yes@gmail.com \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox