public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 01/13] kexec: add _ALIGN* marcos for align operation
@ 2013-03-13 17:19 Zhang Yanfei
  2013-03-13 17:21 ` [PATCH 02/13] kexec: use _ALIGN() instead of align() Zhang Yanfei
                   ` (12 more replies)
  0 siblings, 13 replies; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:19 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

This patch imports Macros for align operation:
- _ALIGN_UP(addr, size): align addr up on a size boundary
- _ALIGN_DOWN(addr, size): align addr down on a size boundary
- _ALIGN(addr, size): align addr up on a size boundary

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/kexec.h |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/kexec/kexec.h b/kexec/kexec.h
index 94c62c1..916a24b 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -100,6 +100,18 @@ do { \
 	} \
 } while(0)
 
+#define _ALIGN_UP_MASK(addr, mask)   (((addr) + (mask)) & ~(mask))
+#define _ALIGN_DOWN_MASK(addr, mask) ((addr) & ~(mask))
+
+/* align addr on a size boundary - adjust address up/down if needed */
+#define _ALIGN_UP(addr, size)	     \
+	_ALIGN_UP_MASK(addr, (typeof(addr))(size) - 1)
+#define _ALIGN_DOWN(addr, size)	     \
+	_ALIGN_DOWN_MASK(addr, (typeof(addr))(size) - 1)
+
+/* align addr on a size boundary - adjust address up if needed */
+#define _ALIGN(addr, size)     _ALIGN_UP(addr, size)
+
 extern unsigned long long mem_min, mem_max;
 extern int kexec_debug;
 
-- 
1.7.1

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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 02/13] kexec: use _ALIGN() instead of align()
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
@ 2013-03-13 17:21 ` 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
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:21 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

Since we have imported macro _ALIGN() for global use, replace the call
of function align() with _ALIGN() and remove align().

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/kexec-elf-boot.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/kexec/kexec-elf-boot.c b/kexec/kexec-elf-boot.c
index 9a160bb..f082f8b 100644
--- a/kexec/kexec-elf-boot.c
+++ b/kexec/kexec-elf-boot.c
@@ -67,12 +67,6 @@ static struct boot_notes {
 	},
 };
 
-static inline unsigned long align(unsigned long val, unsigned long align)
-{
-	return (val + align - 1) & ~(align - 1);
-
-}
-
 unsigned long elf_boot_notes(
 	struct kexec_info *info, unsigned long max_addr,
 	const char *cmdline, int cmdline_len)
@@ -80,7 +74,7 @@ unsigned long elf_boot_notes(
 	unsigned long note_bytes;
 	unsigned long note_base;
 	struct boot_notes *notes;
-	note_bytes = sizeof(*notes) + align(cmdline_len, 4);
+	note_bytes = sizeof(*notes) + _ALIGN(cmdline_len, 4);
 	notes = xmalloc(note_bytes);
 	memcpy(notes, &boot_notes, sizeof(boot_notes));
 	memcpy(notes->command_line, cmdline, cmdline_len);
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 03/13] kexec: ppc: remove duplicated _ALIGN_* macros
  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-13 17:23 ` 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
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:23 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

We have defined the global align macros for use, so remove the
duplicated macros here.

And in file kexec/arch/ppc/include/page.h, we directly expand the
align operation for marco PAGE_ALIGN since we have removed marco
_ALIGN in this file.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/ppc/include/page.h      |    9 +--------
 kexec/arch/ppc64/crashdump-ppc64.h |    2 --
 2 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/kexec/arch/ppc/include/page.h b/kexec/arch/ppc/include/page.h
index 14eca30..65877bc 100644
--- a/kexec/arch/ppc/include/page.h
+++ b/kexec/arch/ppc/include/page.h
@@ -21,14 +21,7 @@
 #define PAGE_SIZE	(ASM_CONST(1) << PAGE_SHIFT)
 #define PAGE_MASK	(~(PAGE_SIZE-1))
 
-/* align addr on a size boundary - adjust address up/down if needed */
-#define _ALIGN_UP(addr,size)	(((addr)+((size)-1))&(~((size)-1)))
-#define _ALIGN_DOWN(addr,size)	((addr)&(~((size)-1)))
-
-/* align addr on a size boundary - adjust address up if needed */
-#define _ALIGN(addr,size)     _ALIGN_UP(addr,size)
-
 /* to align the pointer to the (next) page boundary */
-#define PAGE_ALIGN(addr)	_ALIGN(addr, PAGE_SIZE)
+#define PAGE_ALIGN(addr)	(((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
 
 #endif				/* _PPC_BOOT_PAGE_H */
diff --git a/kexec/arch/ppc64/crashdump-ppc64.h b/kexec/arch/ppc64/crashdump-ppc64.h
index 739c61f..e9d28c9 100644
--- a/kexec/arch/ppc64/crashdump-ppc64.h
+++ b/kexec/arch/ppc64/crashdump-ppc64.h
@@ -20,8 +20,6 @@ void add_usable_mem_rgns(unsigned long long base, unsigned long long size);
 #define BACKUP_SRC_SIZE     (BACKUP_SRC_END - BACKUP_SRC_START + 1)
 
 #define KDUMP_BACKUP_LIMIT	BACKUP_SRC_SIZE
-#define _ALIGN_UP(addr,size)	(((addr)+((size)-1))&(~((size)-1)))
-#define _ALIGN_DOWN(addr,size)	((addr)&(~((size)-1)))
 
 #define KERNEL_RUN_AT_ZERO_MAGIC 0x72756e30	/* "run0" */
 
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  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-13 17:23 ` [PATCH 03/13] kexec: ppc: remove duplicated _ALIGN_* macros Zhang Yanfei
@ 2013-03-13 17:26 ` Zhang Yanfei
  2013-03-14  9:08   ` Simon Horman
  2013-03-13 17:28 ` [PATCH 05/13] kexec: i386: " Zhang Yanfei
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:26 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

By replacing all the explicit align opertions with marco _ALIGN*,
the code logic could be 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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 05/13] kexec: i386: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (2 preceding siblings ...)
  2013-03-13 17:26 ` [PATCH 04/13] kexec: use _ALIGN* to make the logic clear Zhang Yanfei
@ 2013-03-13 17:28 ` Zhang Yanfei
  2013-03-14  9:50   ` Simon Horman
  2013-03-13 17:29 ` [PATCH 06/13] kexec: arm: " Zhang Yanfei
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:28 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/i386/crashdump-x86.c       |    6 +++---
 kexec/arch/i386/kexec-bzImage.c       |    2 +-
 kexec/arch/i386/kexec-multiboot-x86.c |    5 ++---
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 5cbe153..5462f8b 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -163,11 +163,11 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 			/* Look for kernel text mapping header. */
 			if ((saddr >= X86_64__START_KERNEL_map) &&
 			    (eaddr <= X86_64__START_KERNEL_map + X86_64_KERNEL_TEXT_SIZE)) {
-				saddr = (saddr) & (~(X86_64_KERN_VADDR_ALIGN - 1));
+				saddr = _ALIGN_DOWN(saddr, X86_64_KERN_VADDR_ALIGN);
 				elf_info->kern_vaddr_start = saddr;
 				size = eaddr - saddr;
 				/* Align size to page size boundary. */
-				size = (size + align - 1) & (~(align - 1));
+				size = _ALIGN(size, align);
 				elf_info->kern_size = size;
 				dbgprintf("kernel vaddr = 0x%llx size = 0x%llx\n",
 					saddr, size);
@@ -1035,7 +1035,7 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 
 	/* Create a backup region segment to store backup data*/
 	if (!(info->kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
-		sz = (info->backup_src_size + align) & ~(align - 1);
+		sz = _ALIGN(info->backup_src_size, align);
 		tmp = xmalloc(sz);
 		memset(tmp, 0, sz);
 		info->backup_start = add_buffer(info, tmp, sz, sz, align,
diff --git a/kexec/arch/i386/kexec-bzImage.c b/kexec/arch/i386/kexec-bzImage.c
index bad0c9c..99fd790 100644
--- a/kexec/arch/i386/kexec-bzImage.c
+++ b/kexec/arch/i386/kexec-bzImage.c
@@ -223,7 +223,7 @@ int do_bzImage_load(struct kexec_info *info,
 		if (kern16_size_needed > 0xfffc)
 			die("kern16_size_needed is more then 64k\n");
 		heap_size = 0xfffc - kern16_size_needed; /* less 64k */
-		heap_size &= ~(0x200 - 1);
+		heap_size = _ALIGN_DOWN(heap_size, 0x200);
 		kern16_size_needed += heap_size;
 	} else {
 		kern16_size_needed = kern16_size;
diff --git a/kexec/arch/i386/kexec-multiboot-x86.c b/kexec/arch/i386/kexec-multiboot-x86.c
index de2a423..7e55981 100644
--- a/kexec/arch/i386/kexec-multiboot-x86.c
+++ b/kexec/arch/i386/kexec-multiboot-x86.c
@@ -230,9 +230,8 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len,
 	 * module command lines
 	 * ==============
 	 */
-	mbi_bytes = (sizeof(*mbi) + command_line_len 
-		     + strlen (BOOTLOADER " " BOOTLOADER_VERSION) + 1
-		     + 3) & ~3;
+	mbi_bytes = _ALIGN(sizeof(*mbi) + command_line_len
+		     + strlen (BOOTLOADER " " BOOTLOADER_VERSION) + 1, 4);
 	mbi_buf = xmalloc(mbi_bytes);
 	mbi = mbi_buf;
 	memset(mbi, 0, sizeof(*mbi));
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 06/13] kexec: arm: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (3 preceding siblings ...)
  2013-03-13 17:28 ` [PATCH 05/13] kexec: i386: " Zhang Yanfei
@ 2013-03-13 17:29 ` Zhang Yanfei
  2013-03-14  9:50   ` Simon Horman
  2013-03-13 17:30 ` [PATCH 07/13] kexec: ia64: " Zhang Yanfei
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:29 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/arm/kexec-zImage-arm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index db29a7b..dd2e06f 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -414,7 +414,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		 * align it.
 		 */
 		dtb_offset = initrd_base + initrd_size + getpagesize();
-		dtb_offset &= ~(getpagesize() - 1);
+		dtb_offset = _ALIGN_DOWN(dtb_offset, getpagesize());
 
 		add_segment(info, dtb_buf, dtb_length,
 		            dtb_offset, dtb_length);
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 07/13] kexec: ia64: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (4 preceding siblings ...)
  2013-03-13 17:29 ` [PATCH 06/13] kexec: arm: " Zhang Yanfei
@ 2013-03-13 17:30 ` Zhang Yanfei
  2013-03-14  9:50   ` Simon Horman
  2013-03-13 17:31 ` [PATCH 08/13] kexec: mips: " Zhang Yanfei
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:30 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/ia64/crashdump-ia64.c |    6 +++---
 kexec/arch/ia64/kexec-elf-ia64.c |    2 +-
 kexec/arch/ia64/kexec-ia64.c     |    6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/kexec/arch/ia64/crashdump-ia64.c b/kexec/arch/ia64/crashdump-ia64.c
index 782f49e..726c9f4 100644
--- a/kexec/arch/ia64/crashdump-ia64.c
+++ b/kexec/arch/ia64/crashdump-ia64.c
@@ -83,7 +83,7 @@ static void add_loaded_segments_info(struct mem_ehdr *ehdr)
 		}
 
 		loaded_segments[loaded_segments_num].start =
-			phdr->p_paddr & ~(ELF_PAGE_SIZE-1);
+			_ALIGN_DOWN(phdr->p_paddr, ELF_PAGE_SIZE);
                 loaded_segments[loaded_segments_num].end =
 			loaded_segments[loaded_segments_num].start;
 
@@ -97,8 +97,8 @@ static void add_loaded_segments_info(struct mem_ehdr *ehdr)
 	                if (phdr->p_type != PT_LOAD)
 	                        break;
 			loaded_segments[loaded_segments_num].end =
-				(phdr->p_paddr + phdr->p_memsz +
-				ELF_PAGE_SIZE - 1) & ~(ELF_PAGE_SIZE - 1);
+				_ALIGN(phdr->p_paddr + phdr->p_memsz,
+				       ELF_PAGE_SIZE);
 			i++;
 		}
 		loaded_segments_num++;
diff --git a/kexec/arch/ia64/kexec-elf-ia64.c b/kexec/arch/ia64/kexec-elf-ia64.c
index 8da061e..7303c03 100644
--- a/kexec/arch/ia64/kexec-elf-ia64.c
+++ b/kexec/arch/ia64/kexec-elf-ia64.c
@@ -264,7 +264,7 @@ int elf_ia64_load(int argc, char **argv, const char *buf, off_t len,
 			strcat(cmdline, buf);
 		}
 
-		command_line_len = (command_line_len + 15)&(~15);
+		command_line_len = _ALIGN(command_line_len, 16);
 		command_line_base = add_buffer(info, cmdline,
 				command_line_len, command_line_len,
 				getpagesize(), 0UL,
diff --git a/kexec/arch/ia64/kexec-ia64.c b/kexec/arch/ia64/kexec-ia64.c
index aa510a9..418d997 100644
--- a/kexec/arch/ia64/kexec-ia64.c
+++ b/kexec/arch/ia64/kexec-ia64.c
@@ -50,8 +50,8 @@ static int split_range(int range, unsigned long start, unsigned long end)
 	unsigned int type = memory_range[range - 1].type;
 	int i;
 	//align end and start to page size of EFI
-	start = start & ~((1UL<<12) - 1);
-	end = (end + (1UL<<12) - 1)& ~((1UL<<12) - 1);
+	start = _ALIGN_DOWN(start, 1UL<<12);
+	end = _ALIGN(end, 1UL<<12);
 	for (i = 0; i < range; i++)
 		if(memory_range[i].start <= start && memory_range[i].end >=end)
 			break;
@@ -230,7 +230,7 @@ int update_loaded_segments(struct mem_ehdr *ehdr)
 	for (i = 0; i < memory_ranges; i++) {
 		if (memory_range[i].type != RANGE_RAM)
 			continue;
-		start = (memory_range[i].start + align - 1) & ~(align - 1);
+		start = _ALIGN(memory_range[i].start, align);
 		end = memory_range[i].end;
 		if (end > start && (end - start) > (end_addr - start_addr)) {
 		    move_loaded_segments(ehdr, start);
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 08/13] kexec: mips: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (5 preceding siblings ...)
  2013-03-13 17:30 ` [PATCH 07/13] kexec: ia64: " Zhang Yanfei
@ 2013-03-13 17:31 ` Zhang Yanfei
  2013-03-14  9:51   ` Simon Horman
  2013-03-13 17:32 ` [PATCH 09/13] kexec: ppc: " Zhang Yanfei
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:31 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/mips/crashdump-mips.c |    2 +-
 kexec/arch/mips/kexec-elf-mips.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kexec/arch/mips/crashdump-mips.c b/kexec/arch/mips/crashdump-mips.c
index 6f9f6c6..8e7b1c3 100644
--- a/kexec/arch/mips/crashdump-mips.c
+++ b/kexec/arch/mips/crashdump-mips.c
@@ -373,7 +373,7 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 	info->backup_src_start = BACKUP_SRC_START;
 	info->backup_src_size = BACKUP_SRC_SIZE;
 	/* Create a backup region segment to store backup data*/
-	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
+	sz = _ALIGN(BACKUP_SRC_SIZE, align);
 	tmp = xmalloc(sz);
 	memset(tmp, 0, sz);
 	info->backup_start = add_buffer(info, tmp, sz, sz, align,
diff --git a/kexec/arch/mips/kexec-elf-mips.c b/kexec/arch/mips/kexec-elf-mips.c
index 3e19ca2..6951247 100644
--- a/kexec/arch/mips/kexec-elf-mips.c
+++ b/kexec/arch/mips/kexec-elf-mips.c
@@ -34,7 +34,7 @@ static const int probe_debug = 0;
 
 #define BOOTLOADER         "kexec"
 #define MAX_COMMAND_LINE   256
-#define UPSZ(X) ((sizeof(X) + 3) & ~3)
+#define UPSZ(X) _ALIGN_UP(sizeof(X), 4)
 static char cmdline_buf[256] = "kexec ";
 
 int elf_mips_probe(const char *buf, off_t len)
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 09/13] kexec: ppc: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (6 preceding siblings ...)
  2013-03-13 17:31 ` [PATCH 08/13] kexec: mips: " Zhang Yanfei
@ 2013-03-13 17:32 ` Zhang Yanfei
  2013-03-14  9:09   ` Simon Horman
  2013-03-14  9:33   ` [PATCH v2 " Zhang Yanfei
  2013-03-13 17:33 ` [PATCH 10/13] kexec: ppc64: " Zhang Yanfei
                   ` (4 subsequent siblings)
  12 siblings, 2 replies; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:32 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Besides, remove the duplicate _ALIGN_* definition in file
kexec/arch/ppc/crashdump-powerpc.h.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/ppc/crashdump-powerpc.c |    2 +-
 kexec/arch/ppc/crashdump-powerpc.h |    2 --
 kexec/arch/ppc/fs2dt.c             |    5 ++---
 kexec/arch/ppc/kexec-dol-ppc.c     |   10 +++++-----
 kexec/arch/ppc/kexec-elf-ppc.c     |    8 ++++----
 5 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c
index d367643..eee5b37 100644
--- a/kexec/arch/ppc/crashdump-powerpc.c
+++ b/kexec/arch/ppc/crashdump-powerpc.c
@@ -329,7 +329,7 @@ int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline,
 	info->backup_src_size = BACKUP_SRC_SIZE;
 #ifndef CONFIG_BOOKE
 	/* Create a backup region segment to store backup data*/
-	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
+	sz = _ALIGN(BACKUP_SRC_SIZE, align);
 	tmp = xmalloc(sz);
 	memset(tmp, 0, sz);
 	info->backup_start = add_buffer(info, tmp, sz, sz, align,
diff --git a/kexec/arch/ppc/crashdump-powerpc.h b/kexec/arch/ppc/crashdump-powerpc.h
index 84a73aa..efdc7e3 100644
--- a/kexec/arch/ppc/crashdump-powerpc.h
+++ b/kexec/arch/ppc/crashdump-powerpc.h
@@ -35,8 +35,6 @@ extern struct arch_options_t arch_options;
 #endif
 
 #define KDUMP_BACKUP_LIMIT	BACKUP_SRC_SIZE
-#define _ALIGN_UP(addr, size)	(((addr)+((size)-1))&(~((size)-1)))
-#define _ALIGN_DOWN(addr, size)	((addr)&(~((size)-1)))
 
 extern unsigned long long crash_base;
 extern unsigned long long crash_size;
diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c
index cdae69e..56ffb91 100644
--- a/kexec/arch/ppc/fs2dt.c
+++ b/kexec/arch/ppc/fs2dt.c
@@ -407,8 +407,7 @@ int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
 	putnode();
 	*dt++ = 9;
 
-	len = sizeof(bb[0]);
-	len += 7; len &= ~7;
+	len = _ALIGN(sizeof(bb[0], 8);
 
 	bb->off_mem_rsvmap = len;
 
@@ -426,7 +425,7 @@ int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
 
 	len = propnum("");
 	bb->dt_strings_size = len;
-	len +=  3; len &= ~3;
+	len = _ALIGN(len, 4);
 	bb->totalsize = bb->off_dt_strings + len;
 
 	bb->magic = 0xd00dfeed;
diff --git a/kexec/arch/ppc/kexec-dol-ppc.c b/kexec/arch/ppc/kexec-dol-ppc.c
index 5fc5e06..8d0d1a0 100644
--- a/kexec/arch/ppc/kexec-dol-ppc.c
+++ b/kexec/arch/ppc/kexec-dol-ppc.c
@@ -87,11 +87,11 @@ typedef struct {
 #define PAGE_SHIFT		12
 #define PAGE_SIZE		(1UL << PAGE_SHIFT)
 #define PAGE_MASK		(~((1 << PAGE_SHIFT) - 1))
-#define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
+#define PAGE_ALIGN(addr)	_ALIGN(addr, PAGE_SIZE)
 
 #define MAX_COMMAND_LINE   256
 
-#define UPSZ(X) ((sizeof(X) + 3) & ~3)
+#define UPSZ(X) _ALIGN_UP(sizeof(X), 4)
 static struct boot_notes {
 	Elf_Bhdr hdr;
 	Elf_Nhdr bl_hdr;
@@ -442,14 +442,14 @@ int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 	}
 
 	/* build the setup glue and argument segment (segment 0) */
-	note_bytes = sizeof(elf_boot_notes) + ((command_line_len + 3) & ~3);
-	arg_bytes = note_bytes + ((setup_dol_size + 3) & ~3);
+	note_bytes = sizeof(elf_boot_notes) + _ALIGN(command_line_len, 4);
+	arg_bytes = note_bytes + _ALIGN(setup_dol_size, 4);
 
 	arg_buf = xmalloc(arg_bytes);
 	arg_base = add_buffer(info,
 		arg_buf, arg_bytes, arg_bytes, 4, 0, 0xFFFFFFFFUL, 1);
 
-	notes = (struct boot_notes *)(arg_buf + ((setup_dol_size + 3) & ~3));
+	notes = (struct boot_notes *)(arg_buf + _ALIGN(setup_dol_size, 4));
 
 	notes->hdr.b_size = note_bytes;
 	notes->cmd_hdr.n_descsz = command_line_len;
diff --git a/kexec/arch/ppc/kexec-elf-ppc.c b/kexec/arch/ppc/kexec-elf-ppc.c
index 5f63a64..65a65cc 100644
--- a/kexec/arch/ppc/kexec-elf-ppc.c
+++ b/kexec/arch/ppc/kexec-elf-ppc.c
@@ -37,7 +37,7 @@ const char *ramdisk;
 int create_flatten_tree(struct kexec_info *, unsigned char **, unsigned long *,
 			char *);
 
-#define UPSZ(X) ((sizeof(X) + 3) & ~3)
+#define UPSZ(X) _ALIGN_UP(sizeof(X), 4);
 #ifdef WITH_GAMECUBE
 static struct boot_notes {
 	Elf_Bhdr hdr;
@@ -327,14 +327,14 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 		setup_size = setup_simple_size;
 		setup_simple_regs.spr8 = ehdr.e_entry;	/* Link Register */
 	}
-	note_bytes = sizeof(elf_boot_notes) + ((command_line_len + 3) & ~3);
-	arg_bytes = note_bytes + ((setup_size + 3) & ~3);
+	note_bytes = sizeof(elf_boot_notes) + _ALIGN(command_line_len, 4);
+	arg_bytes = note_bytes + _ALIGN(setup_size, 4);
 
 	arg_buf = xmalloc(arg_bytes);
 	arg_base = add_buffer(info, 
 		arg_buf, arg_bytes, arg_bytes, 4, 0, elf_max_addr(&ehdr), 1);
 
-	notes = (struct boot_notes *)(arg_buf + ((setup_size + 3) & ~3));
+	notes = (struct boot_notes *)(arg_buf + _ALIGN(setup_size, 4));
 
 	memcpy(arg_buf, setup_start, setup_size);
 	memcpy(notes, &elf_boot_notes, sizeof(elf_boot_notes));
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 10/13] kexec: ppc64: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (7 preceding siblings ...)
  2013-03-13 17:32 ` [PATCH 09/13] kexec: ppc: " Zhang Yanfei
@ 2013-03-13 17:33 ` Zhang Yanfei
  2013-03-14  9:23   ` Simon Horman
  2013-03-14  9:38   ` [PATCH v2 " Zhang Yanfei
  2013-03-13 17:33 ` [PATCH 11/13] kexec: s390: remove ALIGN_UP and use _ALIGN_UP Zhang Yanfei
                   ` (3 subsequent siblings)
  12 siblings, 2 replies; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:33 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/ppc64/crashdump-ppc64.c |    4 ++--
 kexec/arch/ppc64/fs2dt.c           |    6 ++----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
index b8a63bd..49cab12 100644
--- a/kexec/arch/ppc64/crashdump-ppc64.c
+++ b/kexec/arch/ppc64/crashdump-ppc64.c
@@ -298,7 +298,7 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 		 * to the next page size boundary though, so makedumpfile can
 		 * read it safely without going south on us.
 		 */
-		cend = (cend + page_size - 1) & (~(page_size - 1));
+		cend = _ALIGN(cend, page_size);
 
 		crash_memory_range[memory_ranges].start = cstart;
 		crash_memory_range[memory_ranges++].end = cend;
@@ -400,7 +400,7 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 	info->backup_src_start = BACKUP_SRC_START;
 	info->backup_src_size = BACKUP_SRC_SIZE;
 	/* Create a backup region segment to store backup data*/
-	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
+	sz = _ALIGN(BACKUP_SRC_SIZE, align);
 	tmp = xmalloc(sz);
 	memset(tmp, 0, sz);
 	info->backup_start = add_buffer(info, tmp, sz, sz, align,
diff --git a/kexec/arch/ppc64/fs2dt.c b/kexec/arch/ppc64/fs2dt.c
index 9750c34..62edc93 100644
--- a/kexec/arch/ppc64/fs2dt.c
+++ b/kexec/arch/ppc64/fs2dt.c
@@ -698,8 +698,7 @@ int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
 	dt_reserve(&dt, 1);
 	*dt++ = 9;
 
-	len = sizeof(bb[0]);
-	len += 7; len &= ~7;
+	len = _ALIGN(sizeof(bb[0], 8);
 
 	bb->off_mem_rsvmap = len;
 
@@ -714,8 +713,7 @@ int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
 	len *= sizeof(unsigned);
 	bb->off_dt_strings = bb->off_dt_struct + len;
 
-	len = propnum("");
-	len +=  3; len &= ~3;
+	len = _ALIGN(propnum(""), 4);
 	bb->totalsize = bb->off_dt_strings + len;
 
 	bb->magic = 0xd00dfeed;
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 11/13] kexec: s390: remove ALIGN_UP and use _ALIGN_UP
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (8 preceding siblings ...)
  2013-03-13 17:33 ` [PATCH 10/13] kexec: ppc64: " Zhang Yanfei
@ 2013-03-13 17:33 ` 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
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:33 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

We have _ALIGN_UP now, so remove ALIGN_UP and use _ALIGN_UP
instead of it.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/s390/kexec-image.c |    2 +-
 kexec/arch/s390/kexec-s390.h  |    1 -
 2 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/kexec/arch/s390/kexec-image.c b/kexec/arch/s390/kexec-image.c
index ee101cb..d3af800 100644
--- a/kexec/arch/s390/kexec-image.c
+++ b/kexec/arch/s390/kexec-image.c
@@ -112,7 +112,7 @@ image_s390_load(int argc, char **argv, const char *kernel_buf,
 			return -1;
 		}
 		ramdisk_origin = MAX(RAMDISK_ORIGIN_ADDR, kernel_size);
-		ramdisk_origin = ALIGN_UP(ramdisk_origin, 0x100000);
+		ramdisk_origin = _ALIGN_UP(ramdisk_origin, 0x100000);
 		add_segment_check(info, rd_buffer, ramdisk_len,
 				  ramdisk_origin, ramdisk_len);
 	}
diff --git a/kexec/arch/s390/kexec-s390.h b/kexec/arch/s390/kexec-s390.h
index cbc3340..ee62888 100644
--- a/kexec/arch/s390/kexec-s390.h
+++ b/kexec/arch/s390/kexec-s390.h
@@ -21,7 +21,6 @@
 #define COMMAND_LINESIZE      896
 #define MAX_MEMORY_RANGES     1024
 
-#define ALIGN_UP(addr, size) (((addr) + ((size)-1)) & (~((size)-1)))
 #define MAX(x, y) ((x) > (y) ? (x) : (y))
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 12/13] kexec: sh: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (9 preceding siblings ...)
  2013-03-13 17:33 ` [PATCH 11/13] kexec: s390: remove ALIGN_UP and use _ALIGN_UP Zhang Yanfei
@ 2013-03-13 17:34 ` 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  9:47 ` [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Simon Horman
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:34 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/sh/kexec-netbsd-sh.c |    4 ++--
 kexec/arch/sh/kexec-zImage-sh.c |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kexec/arch/sh/kexec-netbsd-sh.c b/kexec/arch/sh/kexec-netbsd-sh.c
index 8e80486..8a7e75e 100644
--- a/kexec/arch/sh/kexec-netbsd-sh.c
+++ b/kexec/arch/sh/kexec-netbsd-sh.c
@@ -121,7 +121,7 @@ int netbsd_sh_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 		        size = bbs;
 		}
 
-		size = (size + psz - 1) & ~(psz - 1);
+		size = _ALIGN(size, psz);
 		memset(&img[bbs], 0, size-bbs);
 		add_segment(info, img, size, start, size);
 		start += size;
@@ -132,7 +132,7 @@ int netbsd_sh_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 	if (miniroot) {
 		miniroot_buf = slurp_file(miniroot, &miniroot_length);
 		howto_value |= 0x200;
-		size = (miniroot_length + psz - 1) & ~(psz - 1);
+		size = _ALIGN(miniroot_length, psz);
 		add_segment(info, miniroot_buf, size, start, size);
 		start += size;
 	}
diff --git a/kexec/arch/sh/kexec-zImage-sh.c b/kexec/arch/sh/kexec-zImage-sh.c
index 1ce185a..7399052 100644
--- a/kexec/arch/sh/kexec-zImage-sh.c
+++ b/kexec/arch/sh/kexec-zImage-sh.c
@@ -138,7 +138,7 @@ int zImage_sh_load(int argc, char **argv, const char *buf, off_t len,
 	 * the zImage will relocate itself, but only up seems supported.
 	 */
 
-	image_base = (empty_zero + (0x10000 - 1)) & ~(0x10000 - 1);
+	image_base = _ALIGN(empty_zero, 0x10000);
 	add_segment(info, buf, len, image_base, len);
 	info->entry = (void *)virt_to_phys(image_base);
 	return 0;
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 13/13] kexec: x86_64: use _ALIGN* to make the logic clear
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (10 preceding siblings ...)
  2013-03-13 17:34 ` [PATCH 12/13] kexec: sh: use _ALIGN* to make the logic clear Zhang Yanfei
@ 2013-03-13 17:35 ` 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
  12 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-13 17:35 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/x86_64/kexec-bzImage64.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kexec/arch/x86_64/kexec-bzImage64.c b/kexec/arch/x86_64/kexec-bzImage64.c
index 1496573..86e6d13 100644
--- a/kexec/arch/x86_64/kexec-bzImage64.c
+++ b/kexec/arch/x86_64/kexec-bzImage64.c
@@ -197,7 +197,7 @@ static int do_bzImage64_load(struct kexec_info *info,
 	k_size = kernel_len - kern16_size;
 	/* need to use run-time size for buffer searching */
 	dbgprintf("kernel init_size 0x%x\n", real_mode->init_size);
-	size = (real_mode->init_size + (4096 - 1)) & ~(4096 - 1);
+	size = _ALIGN(real_mode->init_size, 4096);
 	align = real_mode->kernel_alignment;
 	addr = add_buffer(info, kernel + kern16_size, k_size,
 			  size, align, 0x100000, -1, -1);
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  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  9:49     ` Simon Horman
  0 siblings, 2 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:08 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:26:56AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertions with marco _ALIGN*,
> the code logic could be more clear.

Not a big deal, but I believe this patch needs to come after
the arm changes in the series in order to avoid breaking the build
on that architecture.

> 
> 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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 09/13] kexec: ppc: use _ALIGN* to make the logic clear
  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
  1 sibling, 1 reply; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:09 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:32:20AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.
> 
> Besides, remove the duplicate _ALIGN_* definition in file
> kexec/arch/ppc/crashdump-powerpc.h.

This appears to break the build on ppc.


powerpc-linux-gnu-gcc -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -I/include -I./include -I./util_lib/include -Iinclude/ -I./kexec/libfdt -I./kexec/arch/ppc/include  -c -MD -o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/fs2dt.c
kexec/arch/ppc/fs2dt.c: In function 'add_usable_mem_property':
kexec/arch/ppc/fs2dt.c:146: warning: comparison between signed and unsigned integer expressions
kexec/arch/ppc/fs2dt.c:128: warning: unused variable 'buf'
kexec/arch/ppc/fs2dt.c:125: warning: unused parameter 'len'
kexec/arch/ppc/fs2dt.c: In function 'putnode':
kexec/arch/ppc/fs2dt.c:326: warning: passing argument 4 of 'scandir' from incompatible pointer type
/usr/powerpc-linux-gnu/include/dirent.h:252: note: expected 'int (*)(const struct dirent **, const struct dirent **)' but argument is of type 'int (*)(const void *, const void *)'
kexec/arch/ppc/fs2dt.c:449:1: error: unterminated argument list invoking macro "_ALIGN"
kexec/arch/ppc/fs2dt.c: In function 'create_flatten_tree':
kexec/arch/ppc/fs2dt.c:410: error: '_ALIGN' undeclared (first use in this function)
kexec/arch/ppc/fs2dt.c:410: error: (Each undeclared identifier is reported only once
kexec/arch/ppc/fs2dt.c:410: error: for each function it appears in.)
kexec/arch/ppc/fs2dt.c:410: error: expected ';' at end of input
kexec/arch/ppc/fs2dt.c:410: error: expected declaration or statement at end of input
kexec/arch/ppc/fs2dt.c:395: warning: unused variable 'buf'
kexec/arch/ppc/fs2dt.c:394: warning: unused variable 'tlen'
kexec/arch/ppc/fs2dt.c:390: warning: unused parameter 'info'
kexec/arch/ppc/fs2dt.c:390: warning: unused parameter 'bufp'
kexec/arch/ppc/fs2dt.c:391: warning: unused parameter 'sizep'
make: *** [kexec/arch/ppc/fs2dt.o] Error 1

> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> ---
>  kexec/arch/ppc/crashdump-powerpc.c |    2 +-
>  kexec/arch/ppc/crashdump-powerpc.h |    2 --
>  kexec/arch/ppc/fs2dt.c             |    5 ++---
>  kexec/arch/ppc/kexec-dol-ppc.c     |   10 +++++-----
>  kexec/arch/ppc/kexec-elf-ppc.c     |    8 ++++----
>  5 files changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c
> index d367643..eee5b37 100644
> --- a/kexec/arch/ppc/crashdump-powerpc.c
> +++ b/kexec/arch/ppc/crashdump-powerpc.c
> @@ -329,7 +329,7 @@ int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline,
>  	info->backup_src_size = BACKUP_SRC_SIZE;
>  #ifndef CONFIG_BOOKE
>  	/* Create a backup region segment to store backup data*/
> -	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
> +	sz = _ALIGN(BACKUP_SRC_SIZE, align);
>  	tmp = xmalloc(sz);
>  	memset(tmp, 0, sz);
>  	info->backup_start = add_buffer(info, tmp, sz, sz, align,
> diff --git a/kexec/arch/ppc/crashdump-powerpc.h b/kexec/arch/ppc/crashdump-powerpc.h
> index 84a73aa..efdc7e3 100644
> --- a/kexec/arch/ppc/crashdump-powerpc.h
> +++ b/kexec/arch/ppc/crashdump-powerpc.h
> @@ -35,8 +35,6 @@ extern struct arch_options_t arch_options;
>  #endif
>  
>  #define KDUMP_BACKUP_LIMIT	BACKUP_SRC_SIZE
> -#define _ALIGN_UP(addr, size)	(((addr)+((size)-1))&(~((size)-1)))
> -#define _ALIGN_DOWN(addr, size)	((addr)&(~((size)-1)))
>  
>  extern unsigned long long crash_base;
>  extern unsigned long long crash_size;
> diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c
> index cdae69e..56ffb91 100644
> --- a/kexec/arch/ppc/fs2dt.c
> +++ b/kexec/arch/ppc/fs2dt.c
> @@ -407,8 +407,7 @@ int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
>  	putnode();
>  	*dt++ = 9;
>  
> -	len = sizeof(bb[0]);
> -	len += 7; len &= ~7;
> +	len = _ALIGN(sizeof(bb[0], 8);
>  
>  	bb->off_mem_rsvmap = len;
>  
> @@ -426,7 +425,7 @@ int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
>  
>  	len = propnum("");
>  	bb->dt_strings_size = len;
> -	len +=  3; len &= ~3;
> +	len = _ALIGN(len, 4);
>  	bb->totalsize = bb->off_dt_strings + len;
>  
>  	bb->magic = 0xd00dfeed;
> diff --git a/kexec/arch/ppc/kexec-dol-ppc.c b/kexec/arch/ppc/kexec-dol-ppc.c
> index 5fc5e06..8d0d1a0 100644
> --- a/kexec/arch/ppc/kexec-dol-ppc.c
> +++ b/kexec/arch/ppc/kexec-dol-ppc.c
> @@ -87,11 +87,11 @@ typedef struct {
>  #define PAGE_SHIFT		12
>  #define PAGE_SIZE		(1UL << PAGE_SHIFT)
>  #define PAGE_MASK		(~((1 << PAGE_SHIFT) - 1))
> -#define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
> +#define PAGE_ALIGN(addr)	_ALIGN(addr, PAGE_SIZE)
>  
>  #define MAX_COMMAND_LINE   256
>  
> -#define UPSZ(X) ((sizeof(X) + 3) & ~3)
> +#define UPSZ(X) _ALIGN_UP(sizeof(X), 4)
>  static struct boot_notes {
>  	Elf_Bhdr hdr;
>  	Elf_Nhdr bl_hdr;
> @@ -442,14 +442,14 @@ int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
>  	}
>  
>  	/* build the setup glue and argument segment (segment 0) */
> -	note_bytes = sizeof(elf_boot_notes) + ((command_line_len + 3) & ~3);
> -	arg_bytes = note_bytes + ((setup_dol_size + 3) & ~3);
> +	note_bytes = sizeof(elf_boot_notes) + _ALIGN(command_line_len, 4);
> +	arg_bytes = note_bytes + _ALIGN(setup_dol_size, 4);
>  
>  	arg_buf = xmalloc(arg_bytes);
>  	arg_base = add_buffer(info,
>  		arg_buf, arg_bytes, arg_bytes, 4, 0, 0xFFFFFFFFUL, 1);
>  
> -	notes = (struct boot_notes *)(arg_buf + ((setup_dol_size + 3) & ~3));
> +	notes = (struct boot_notes *)(arg_buf + _ALIGN(setup_dol_size, 4));
>  
>  	notes->hdr.b_size = note_bytes;
>  	notes->cmd_hdr.n_descsz = command_line_len;
> diff --git a/kexec/arch/ppc/kexec-elf-ppc.c b/kexec/arch/ppc/kexec-elf-ppc.c
> index 5f63a64..65a65cc 100644
> --- a/kexec/arch/ppc/kexec-elf-ppc.c
> +++ b/kexec/arch/ppc/kexec-elf-ppc.c
> @@ -37,7 +37,7 @@ const char *ramdisk;
>  int create_flatten_tree(struct kexec_info *, unsigned char **, unsigned long *,
>  			char *);
>  
> -#define UPSZ(X) ((sizeof(X) + 3) & ~3)
> +#define UPSZ(X) _ALIGN_UP(sizeof(X), 4);
>  #ifdef WITH_GAMECUBE
>  static struct boot_notes {
>  	Elf_Bhdr hdr;
> @@ -327,14 +327,14 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
>  		setup_size = setup_simple_size;
>  		setup_simple_regs.spr8 = ehdr.e_entry;	/* Link Register */
>  	}
> -	note_bytes = sizeof(elf_boot_notes) + ((command_line_len + 3) & ~3);
> -	arg_bytes = note_bytes + ((setup_size + 3) & ~3);
> +	note_bytes = sizeof(elf_boot_notes) + _ALIGN(command_line_len, 4);
> +	arg_bytes = note_bytes + _ALIGN(setup_size, 4);
>  
>  	arg_buf = xmalloc(arg_bytes);
>  	arg_base = add_buffer(info, 
>  		arg_buf, arg_bytes, arg_bytes, 4, 0, elf_max_addr(&ehdr), 1);
>  
> -	notes = (struct boot_notes *)(arg_buf + ((setup_size + 3) & ~3));
> +	notes = (struct boot_notes *)(arg_buf + _ALIGN(setup_size, 4));
>  
>  	memcpy(arg_buf, setup_start, setup_size);
>  	memcpy(notes, &elf_boot_notes, sizeof(elf_boot_notes));
> -- 
> 1.7.1
> 

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 10/13] kexec: ppc64: use _ALIGN* to make the logic clear
  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
  1 sibling, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:23 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:33:07AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.

This appears to break the ppc64 build.

powerpc64-unknown-linux-gnu-gcc -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -I/home/horms/local/opt/crosstool/powerpc-970/gcc-4.1.1-glibc-2.3.6/powerpc64-unknown-linux-gnu/include -I./include -I./util_lib/include -Iinclude/  -I./kexec/arch/ppc64/include -c -MD -o kexec/arch/ppc64/fs2dt.o kexec/arch/ppc64/fs2dt.c
kexec/arch/ppc64/fs2dt.c: In function 'putnode':
kexec/arch/ppc64/fs2dt.c:492: warning: passing argument 4 of 'scandir' from
incompatible pointer type
kexec/arch/ppc64/fs2dt.c:738:1: error: unterminated argument list invoking
macro "_ALIGN"
kexec/arch/ppc64/fs2dt.c: In function 'create_flatten_tree':
kexec/arch/ppc64/fs2dt.c:701: error: '_ALIGN' undeclared (first use in this
function)
kexec/arch/ppc64/fs2dt.c:701: error: (Each undeclared identifier is
reported only once
kexec/arch/ppc64/fs2dt.c:701: error: for each function it appears in.)
kexec/arch/ppc64/fs2dt.c:701: error: expected ';' at end of input
kexec/arch/ppc64/fs2dt.c:676: warning: unused variable 'buf'
kexec/arch/ppc64/fs2dt.c:675: warning: unused variable 'tlen'
kexec/arch/ppc64/fs2dt.c:672: warning: unused parameter 'bufp'
kexec/arch/ppc64/fs2dt.c:672: warning: unused parameter 'sizep'
kexec/arch/ppc64/fs2dt.c:701: warning: control reaches end of non-void function

> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> ---
>  kexec/arch/ppc64/crashdump-ppc64.c |    4 ++--
>  kexec/arch/ppc64/fs2dt.c           |    6 ++----
>  2 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
> index b8a63bd..49cab12 100644
> --- a/kexec/arch/ppc64/crashdump-ppc64.c
> +++ b/kexec/arch/ppc64/crashdump-ppc64.c
> @@ -298,7 +298,7 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
>  		 * to the next page size boundary though, so makedumpfile can
>  		 * read it safely without going south on us.
>  		 */
> -		cend = (cend + page_size - 1) & (~(page_size - 1));
> +		cend = _ALIGN(cend, page_size);
>  
>  		crash_memory_range[memory_ranges].start = cstart;
>  		crash_memory_range[memory_ranges++].end = cend;
> @@ -400,7 +400,7 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
>  	info->backup_src_start = BACKUP_SRC_START;
>  	info->backup_src_size = BACKUP_SRC_SIZE;
>  	/* Create a backup region segment to store backup data*/
> -	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
> +	sz = _ALIGN(BACKUP_SRC_SIZE, align);
>  	tmp = xmalloc(sz);
>  	memset(tmp, 0, sz);
>  	info->backup_start = add_buffer(info, tmp, sz, sz, align,
> diff --git a/kexec/arch/ppc64/fs2dt.c b/kexec/arch/ppc64/fs2dt.c
> index 9750c34..62edc93 100644
> --- a/kexec/arch/ppc64/fs2dt.c
> +++ b/kexec/arch/ppc64/fs2dt.c
> @@ -698,8 +698,7 @@ int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
>  	dt_reserve(&dt, 1);
>  	*dt++ = 9;
>  
> -	len = sizeof(bb[0]);
> -	len += 7; len &= ~7;
> +	len = _ALIGN(sizeof(bb[0], 8);
>  
>  	bb->off_mem_rsvmap = len;
>  
> @@ -714,8 +713,7 @@ int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
>  	len *= sizeof(unsigned);
>  	bb->off_dt_strings = bb->off_dt_struct + len;
>  
> -	len = propnum("");
> -	len +=  3; len &= ~3;
> +	len = _ALIGN(propnum(""), 4);
>  	bb->totalsize = bb->off_dt_strings + len;
>  
>  	bb->magic = 0xd00dfeed;
> -- 
> 1.7.1
> 

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 09/13] kexec: ppc: use _ALIGN* to make the logic clear
  2013-03-14  9:09   ` Simon Horman
@ 2013-03-14  9:32     ` Zhang Yanfei
  0 siblings, 0 replies; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-14  9:32 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org, Zhang Yanfei

于 2013年03月14日 17:09, Simon Horman 写道:
> On Thu, Mar 14, 2013 at 01:32:20AM +0800, Zhang Yanfei wrote:
>> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
>>
>> By replacing all the explicit align opertion with marco _ALIGN*,
>> the code logic could be more clear.
>>
>> Besides, remove the duplicate _ALIGN_* definition in file
>> kexec/arch/ppc/crashdump-powerpc.h.
> 
> This appears to break the build on ppc.
> 
> 
> powerpc-linux-gnu-gcc -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -I/include -I./include -I./util_lib/include -Iinclude/ -I./kexec/libfdt -I./kexec/arch/ppc/include  -c -MD -o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/fs2dt.c
> kexec/arch/ppc/fs2dt.c: In function 'add_usable_mem_property':
> kexec/arch/ppc/fs2dt.c:146: warning: comparison between signed and unsigned integer expressions
> kexec/arch/ppc/fs2dt.c:128: warning: unused variable 'buf'
> kexec/arch/ppc/fs2dt.c:125: warning: unused parameter 'len'
> kexec/arch/ppc/fs2dt.c: In function 'putnode':
> kexec/arch/ppc/fs2dt.c:326: warning: passing argument 4 of 'scandir' from incompatible pointer type
> /usr/powerpc-linux-gnu/include/dirent.h:252: note: expected 'int (*)(const struct dirent **, const struct dirent **)' but argument is of type 'int (*)(const void *, const void *)'
> kexec/arch/ppc/fs2dt.c:449:1: error: unterminated argument list invoking macro "_ALIGN"
> kexec/arch/ppc/fs2dt.c: In function 'create_flatten_tree':
> kexec/arch/ppc/fs2dt.c:410: error: '_ALIGN' undeclared (first use in this function)
> kexec/arch/ppc/fs2dt.c:410: error: (Each undeclared identifier is reported only once
> kexec/arch/ppc/fs2dt.c:410: error: for each function it appears in.)
> kexec/arch/ppc/fs2dt.c:410: error: expected ';' at end of input
> kexec/arch/ppc/fs2dt.c:410: error: expected declaration or statement at end of input
> kexec/arch/ppc/fs2dt.c:395: warning: unused variable 'buf'
> kexec/arch/ppc/fs2dt.c:394: warning: unused variable 'tlen'
> kexec/arch/ppc/fs2dt.c:390: warning: unused parameter 'info'
> kexec/arch/ppc/fs2dt.c:390: warning: unused parameter 'bufp'
> kexec/arch/ppc/fs2dt.c:391: warning: unused parameter 'sizep'
> make: *** [kexec/arch/ppc/fs2dt.o] Error 1
> 
>>

Sorry for my carelessness. I forgot a ")" .

I've updated the patch.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH v2 09/13] kexec: ppc: use _ALIGN* to make the logic clear
  2013-03-13 17:32 ` [PATCH 09/13] kexec: ppc: " Zhang Yanfei
  2013-03-14  9:09   ` Simon Horman
@ 2013-03-14  9:33   ` Zhang Yanfei
  2013-03-14  9:54     ` Simon Horman
  1 sibling, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-14  9:33 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: Simon Horman, kexec@lists.infradead.org

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

Besides, remove the duplicate _ALIGN_* definition in file
kexec/arch/ppc/crashdump-powerpc.h.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/ppc/crashdump-powerpc.c |    2 +-
 kexec/arch/ppc/crashdump-powerpc.h |    2 --
 kexec/arch/ppc/fs2dt.c             |    5 ++---
 kexec/arch/ppc/kexec-dol-ppc.c     |   10 +++++-----
 kexec/arch/ppc/kexec-elf-ppc.c     |    8 ++++----
 5 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c
index d367643..eee5b37 100644
--- a/kexec/arch/ppc/crashdump-powerpc.c
+++ b/kexec/arch/ppc/crashdump-powerpc.c
@@ -329,7 +329,7 @@ int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline,
 	info->backup_src_size = BACKUP_SRC_SIZE;
 #ifndef CONFIG_BOOKE
 	/* Create a backup region segment to store backup data*/
-	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
+	sz = _ALIGN(BACKUP_SRC_SIZE, align);
 	tmp = xmalloc(sz);
 	memset(tmp, 0, sz);
 	info->backup_start = add_buffer(info, tmp, sz, sz, align,
diff --git a/kexec/arch/ppc/crashdump-powerpc.h b/kexec/arch/ppc/crashdump-powerpc.h
index 84a73aa..efdc7e3 100644
--- a/kexec/arch/ppc/crashdump-powerpc.h
+++ b/kexec/arch/ppc/crashdump-powerpc.h
@@ -35,8 +35,6 @@ extern struct arch_options_t arch_options;
 #endif
 
 #define KDUMP_BACKUP_LIMIT	BACKUP_SRC_SIZE
-#define _ALIGN_UP(addr, size)	(((addr)+((size)-1))&(~((size)-1)))
-#define _ALIGN_DOWN(addr, size)	((addr)&(~((size)-1)))
 
 extern unsigned long long crash_base;
 extern unsigned long long crash_size;
diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c
index cdae69e..56ffb91 100644
--- a/kexec/arch/ppc/fs2dt.c
+++ b/kexec/arch/ppc/fs2dt.c
@@ -407,8 +407,7 @@ int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
 	putnode();
 	*dt++ = 9;
 
-	len = sizeof(bb[0]);
-	len += 7; len &= ~7;
+	len = _ALIGN(sizeof(bb[0]), 8);
 
 	bb->off_mem_rsvmap = len;
 
@@ -426,7 +425,7 @@ int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
 
 	len = propnum("");
 	bb->dt_strings_size = len;
-	len +=  3; len &= ~3;
+	len = _ALIGN(len, 4);
 	bb->totalsize = bb->off_dt_strings + len;
 
 	bb->magic = 0xd00dfeed;
diff --git a/kexec/arch/ppc/kexec-dol-ppc.c b/kexec/arch/ppc/kexec-dol-ppc.c
index 5fc5e06..8d0d1a0 100644
--- a/kexec/arch/ppc/kexec-dol-ppc.c
+++ b/kexec/arch/ppc/kexec-dol-ppc.c
@@ -87,11 +87,11 @@ typedef struct {
 #define PAGE_SHIFT		12
 #define PAGE_SIZE		(1UL << PAGE_SHIFT)
 #define PAGE_MASK		(~((1 << PAGE_SHIFT) - 1))
-#define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
+#define PAGE_ALIGN(addr)	_ALIGN(addr, PAGE_SIZE)
 
 #define MAX_COMMAND_LINE   256
 
-#define UPSZ(X) ((sizeof(X) + 3) & ~3)
+#define UPSZ(X) _ALIGN_UP(sizeof(X), 4)
 static struct boot_notes {
 	Elf_Bhdr hdr;
 	Elf_Nhdr bl_hdr;
@@ -442,14 +442,14 @@ int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 	}
 
 	/* build the setup glue and argument segment (segment 0) */
-	note_bytes = sizeof(elf_boot_notes) + ((command_line_len + 3) & ~3);
-	arg_bytes = note_bytes + ((setup_dol_size + 3) & ~3);
+	note_bytes = sizeof(elf_boot_notes) + _ALIGN(command_line_len, 4);
+	arg_bytes = note_bytes + _ALIGN(setup_dol_size, 4);
 
 	arg_buf = xmalloc(arg_bytes);
 	arg_base = add_buffer(info,
 		arg_buf, arg_bytes, arg_bytes, 4, 0, 0xFFFFFFFFUL, 1);
 
-	notes = (struct boot_notes *)(arg_buf + ((setup_dol_size + 3) & ~3));
+	notes = (struct boot_notes *)(arg_buf + _ALIGN(setup_dol_size, 4));
 
 	notes->hdr.b_size = note_bytes;
 	notes->cmd_hdr.n_descsz = command_line_len;
diff --git a/kexec/arch/ppc/kexec-elf-ppc.c b/kexec/arch/ppc/kexec-elf-ppc.c
index 5f63a64..65a65cc 100644
--- a/kexec/arch/ppc/kexec-elf-ppc.c
+++ b/kexec/arch/ppc/kexec-elf-ppc.c
@@ -37,7 +37,7 @@ const char *ramdisk;
 int create_flatten_tree(struct kexec_info *, unsigned char **, unsigned long *,
 			char *);
 
-#define UPSZ(X) ((sizeof(X) + 3) & ~3)
+#define UPSZ(X) _ALIGN_UP(sizeof(X), 4);
 #ifdef WITH_GAMECUBE
 static struct boot_notes {
 	Elf_Bhdr hdr;
@@ -327,14 +327,14 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 		setup_size = setup_simple_size;
 		setup_simple_regs.spr8 = ehdr.e_entry;	/* Link Register */
 	}
-	note_bytes = sizeof(elf_boot_notes) + ((command_line_len + 3) & ~3);
-	arg_bytes = note_bytes + ((setup_size + 3) & ~3);
+	note_bytes = sizeof(elf_boot_notes) + _ALIGN(command_line_len, 4);
+	arg_bytes = note_bytes + _ALIGN(setup_size, 4);
 
 	arg_buf = xmalloc(arg_bytes);
 	arg_base = add_buffer(info, 
 		arg_buf, arg_bytes, arg_bytes, 4, 0, elf_max_addr(&ehdr), 1);
 
-	notes = (struct boot_notes *)(arg_buf + ((setup_size + 3) & ~3));
+	notes = (struct boot_notes *)(arg_buf + _ALIGN(setup_size, 4));
 
 	memcpy(arg_buf, setup_start, setup_size);
 	memcpy(notes, &elf_boot_notes, sizeof(elf_boot_notes));
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH v2 10/13] kexec: ppc64: use _ALIGN* to make the logic clear
  2013-03-13 17:33 ` [PATCH 10/13] kexec: ppc64: " Zhang Yanfei
  2013-03-14  9:23   ` Simon Horman
@ 2013-03-14  9:38   ` Zhang Yanfei
  2013-03-14 10:04     ` Simon Horman
  1 sibling, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-14  9:38 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: Simon Horman, kexec@lists.infradead.org

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

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
---
 kexec/arch/ppc64/crashdump-ppc64.c |    4 ++--
 kexec/arch/ppc64/fs2dt.c           |    6 ++----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
index b8a63bd..49cab12 100644
--- a/kexec/arch/ppc64/crashdump-ppc64.c
+++ b/kexec/arch/ppc64/crashdump-ppc64.c
@@ -298,7 +298,7 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 		 * to the next page size boundary though, so makedumpfile can
 		 * read it safely without going south on us.
 		 */
-		cend = (cend + page_size - 1) & (~(page_size - 1));
+		cend = _ALIGN(cend, page_size);
 
 		crash_memory_range[memory_ranges].start = cstart;
 		crash_memory_range[memory_ranges++].end = cend;
@@ -400,7 +400,7 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 	info->backup_src_start = BACKUP_SRC_START;
 	info->backup_src_size = BACKUP_SRC_SIZE;
 	/* Create a backup region segment to store backup data*/
-	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
+	sz = _ALIGN(BACKUP_SRC_SIZE, align);
 	tmp = xmalloc(sz);
 	memset(tmp, 0, sz);
 	info->backup_start = add_buffer(info, tmp, sz, sz, align,
diff --git a/kexec/arch/ppc64/fs2dt.c b/kexec/arch/ppc64/fs2dt.c
index 9750c34..62edc93 100644
--- a/kexec/arch/ppc64/fs2dt.c
+++ b/kexec/arch/ppc64/fs2dt.c
@@ -698,8 +698,7 @@ int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
 	dt_reserve(&dt, 1);
 	*dt++ = 9;
 
-	len = sizeof(bb[0]);
-	len += 7; len &= ~7;
+	len = _ALIGN(sizeof(bb[0]), 8);
 
 	bb->off_mem_rsvmap = len;
 
@@ -714,8 +713,7 @@ int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
 	len *= sizeof(unsigned);
 	bb->off_dt_strings = bb->off_dt_struct + len;
 
-	len = propnum("");
-	len +=  3; len &= ~3;
+	len = _ALIGN(propnum(""), 4);
 	bb->totalsize = bb->off_dt_strings + len;
 
 	bb->magic = 0xd00dfeed;
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 01/13] kexec: add _ALIGN* marcos for align operation
  2013-03-13 17:19 [PATCH 01/13] kexec: add _ALIGN* marcos for align operation Zhang Yanfei
                   ` (11 preceding siblings ...)
  2013-03-13 17:35 ` [PATCH 13/13] kexec: x86_64: " Zhang Yanfei
@ 2013-03-14  9:47 ` Simon Horman
  12 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:47 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:19:13AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> This patch imports Macros for align operation:
> - _ALIGN_UP(addr, size): align addr up on a size boundary
> - _ALIGN_DOWN(addr, size): align addr down on a size boundary
> - _ALIGN(addr, size): align addr up on a size boundary
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 02/13] kexec: use _ALIGN() instead of align()
  2013-03-13 17:21 ` [PATCH 02/13] kexec: use _ALIGN() instead of align() Zhang Yanfei
@ 2013-03-14  9:48   ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:48 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:21:43AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> Since we have imported macro _ALIGN() for global use, replace the call
> of function align() with _ALIGN() and remove align().
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  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
  1 sibling, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-14  9:48 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org, Zhang Yanfei

于 2013年03月14日 17:08, Simon Horman 写道:
> On Thu, Mar 14, 2013 at 01:26:56AM +0800, Zhang Yanfei wrote:
>> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
>>
>> By replacing all the explicit align opertions with marco _ALIGN*,
>> the code logic could be more clear.
> 
> Not a big deal, but I believe this patch needs to come after
> the arm changes in the series in order to avoid breaking the build
> on that architecture.

Sorry, could you explain more? I don't have an arm machine, so, I couldn't
test them.

And I found a bug in this patch, still the ")" issue

+	len = _ALIGN(sizeof(bb[0], 8);

oops...

> 
>>
>> 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
> 


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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 03/13] kexec: ppc: remove duplicated _ALIGN_* macros
  2013-03-13 17:23 ` [PATCH 03/13] kexec: ppc: remove duplicated _ALIGN_* macros Zhang Yanfei
@ 2013-03-14  9:48   ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:48 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:23:49AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> We have defined the global align macros for use, so remove the
> duplicated macros here.
> 
> And in file kexec/arch/ppc/include/page.h, we directly expand the
> align operation for marco PAGE_ALIGN since we have removed marco
> _ALIGN in this file.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-14  9:08   ` Simon Horman
  2013-03-14  9:48     ` Zhang Yanfei
@ 2013-03-14  9:49     ` Simon Horman
  2013-03-14  9:58       ` Simon Horman
  1 sibling, 1 reply; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:49 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 10:08:06AM +0100, Simon Horman wrote:
> On Thu, Mar 14, 2013 at 01:26:56AM +0800, Zhang Yanfei wrote:
> > From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> > 
> > By replacing all the explicit align opertions with marco _ALIGN*,
> > the code logic could be more clear.
> 
> Not a big deal, but I believe this patch needs to come after
> the arm changes in the series in order to avoid breaking the build
> on that architecture.

I have applied this as the last patch of this series that I have applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 05/13] kexec: i386: use _ALIGN* to make the logic clear
  2013-03-13 17:28 ` [PATCH 05/13] kexec: i386: " Zhang Yanfei
@ 2013-03-14  9:50   ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:50 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:28:36AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 06/13] kexec: arm: use _ALIGN* to make the logic clear
  2013-03-13 17:29 ` [PATCH 06/13] kexec: arm: " Zhang Yanfei
@ 2013-03-14  9:50   ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:50 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:29:34AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 07/13] kexec: ia64: use _ALIGN* to make the logic clear
  2013-03-13 17:30 ` [PATCH 07/13] kexec: ia64: " Zhang Yanfei
@ 2013-03-14  9:50   ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:50 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:30:27AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be simplified.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 08/13] kexec: mips: use _ALIGN* to make the logic clear
  2013-03-13 17:31 ` [PATCH 08/13] kexec: mips: " Zhang Yanfei
@ 2013-03-14  9:51   ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:51 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:31:31AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 09/13] kexec: ppc: use _ALIGN* to make the logic clear
  2013-03-14  9:33   ` [PATCH v2 " Zhang Yanfei
@ 2013-03-14  9:54     ` Simon Horman
  2013-03-14  9:57       ` Simon Horman
  0 siblings, 1 reply; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:54 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org, Zhang Yanfei

On Thu, Mar 14, 2013 at 05:33:10PM +0800, Zhang Yanfei wrote:
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.
> 
> Besides, remove the duplicate _ALIGN_* definition in file
> kexec/arch/ppc/crashdump-powerpc.h.

Hi,

I am still seeing a build problem with v2.

powerpc-linux-gnu-gcc -L/lib  -o build/sbin/kexec kexec/kexec.o kexec/ifdown.o kexec/kexec-elf.o kexec/kexec-elf-exec.o kexec/kexec-elf-core.o kexec/kexec-elf-rel.o kexec/kexec-elf-boot.o kexec/kexec-iomem.o kexec/firmware_memmap.o kexec/crashdump.o kexec/crashdump-xen.o kexec/phys_arch.o kexec/kernel_version.o kexec/lzma.o kexec/zlib.o kexec/proc_iomem.o kexec/virt_to_phys.o kexec/phys_to_virt.o kexec/add_segment.o kexec/add_buffer.o kexec/kexec-uImage.o kexec/arch/ppc/kexec-ppc.o kexec/arch/ppc/kexec-elf-ppc.o kexec/arch/ppc/kexec-elf-rel-ppc.o kexec/arch/ppc/kexec-dol-ppc.o kexec/arch/ppc/kexec-uImage-ppc.o kexec/arch/ppc/ppc-setup-simple.o kexec/arch/ppc/ppc-setup-dol.o kexec/arch/ppc/fixup_dtb.o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/crashdump-powerpc.o kexec/libfdt/fdt.o kexec/libfdt/fdt_ro.o kexec/libfdt/fdt_wip.o kexec/libfdt/fdt_sw.o kexec/libfdt/fdt_rw.o kexec/libfdt/fdt_strerror.o
kexec/arch/ppc/libfdt-wrapper.o kexec/purgatory.o libutil.a -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes 
kexec/libfdt/fdt.o: In function `fdt_next_tag':
fdt.c:(.text+0x304): undefined reference to `_ALIGN'
kexec/libfdt/fdt_sw.o: In function `fdt_begin_node':
fdt_sw.c:(.text+0x4f4): undefined reference to `_ALIGN'
kexec/libfdt/fdt_sw.o: In function `fdt_property':
fdt_sw.c:(.text+0x648): undefined reference to `_ALIGN'
kexec/libfdt/fdt_sw.o: In function `fdt_create':
fdt_sw.c:(.text+0x744): undefined reference to `_ALIGN'
kexec/libfdt/fdt_rw.o: In function `_fdt_blocks_misordered':
fdt_rw.c:(.text+0x40): undefined reference to `_ALIGN'
kexec/libfdt/fdt_rw.o:fdt_rw.c:(.text+0x19c): more undefined references to
`_ALIGN' follow
collect2: ld returned 1 exit status

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 09/13] kexec: ppc: use _ALIGN* to make the logic clear
  2013-03-14  9:54     ` Simon Horman
@ 2013-03-14  9:57       ` Simon Horman
  2013-03-14 10:01         ` Simon Horman
  0 siblings, 1 reply; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:57 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org, Zhang Yanfei

On Thu, Mar 14, 2013 at 10:54:14AM +0100, Simon Horman wrote:
> On Thu, Mar 14, 2013 at 05:33:10PM +0800, Zhang Yanfei wrote:
> > By replacing all the explicit align opertion with marco _ALIGN*,
> > the code logic could be more clear.
> > 
> > Besides, remove the duplicate _ALIGN_* definition in file
> > kexec/arch/ppc/crashdump-powerpc.h.
> 
> Hi,
> 
> I am still seeing a build problem with v2.
> 
> powerpc-linux-gnu-gcc -L/lib  -o build/sbin/kexec kexec/kexec.o kexec/ifdown.o kexec/kexec-elf.o kexec/kexec-elf-exec.o kexec/kexec-elf-core.o kexec/kexec-elf-rel.o kexec/kexec-elf-boot.o kexec/kexec-iomem.o kexec/firmware_memmap.o kexec/crashdump.o kexec/crashdump-xen.o kexec/phys_arch.o kexec/kernel_version.o kexec/lzma.o kexec/zlib.o kexec/proc_iomem.o kexec/virt_to_phys.o kexec/phys_to_virt.o kexec/add_segment.o kexec/add_buffer.o kexec/kexec-uImage.o kexec/arch/ppc/kexec-ppc.o kexec/arch/ppc/kexec-elf-ppc.o kexec/arch/ppc/kexec-elf-rel-ppc.o kexec/arch/ppc/kexec-dol-ppc.o kexec/arch/ppc/kexec-uImage-ppc.o kexec/arch/ppc/ppc-setup-simple.o kexec/arch/ppc/ppc-setup-dol.o kexec/arch/ppc/fixup_dtb.o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/crashdump-powerpc.o kexec/libfdt/fdt.o kexec/libfdt/fdt_ro.o kexec/libfdt/fdt_wip.o kexec/libfdt/fdt_sw.o kexec/libfdt/fdt_rw.o kexec/libfdt/fdt_strerror.o
> kexec/arch/ppc/libfdt-wrapper.o kexec/purgatory.o libutil.a -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes 
> kexec/libfdt/fdt.o: In function `fdt_next_tag':
> fdt.c:(.text+0x304): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_sw.o: In function `fdt_begin_node':
> fdt_sw.c:(.text+0x4f4): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_sw.o: In function `fdt_property':
> fdt_sw.c:(.text+0x648): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_sw.o: In function `fdt_create':
> fdt_sw.c:(.text+0x744): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_rw.o: In function `_fdt_blocks_misordered':
> fdt_rw.c:(.text+0x40): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_rw.o:fdt_rw.c:(.text+0x19c): more undefined references to
> `_ALIGN' follow
> collect2: ld returned 1 exit status

Actually, I think that the problem above relates to
"kexec: use _ALIGN* to make the logic clear"

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-14  9:49     ` Simon Horman
@ 2013-03-14  9:58       ` Simon Horman
  2013-03-14 11:24         ` [PATCH v2 " Zhang Yanfei
  2013-03-14 11:26         ` [PATCH " Zhang Yanfei
  0 siblings, 2 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14  9:58 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 10:49:51AM +0100, Simon Horman wrote:
> On Thu, Mar 14, 2013 at 10:08:06AM +0100, Simon Horman wrote:
> > On Thu, Mar 14, 2013 at 01:26:56AM +0800, Zhang Yanfei wrote:
> > > From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> > > 
> > > By replacing all the explicit align opertions with marco _ALIGN*,
> > > the code logic could be more clear.
> > 
> > Not a big deal, but I believe this patch needs to come after
> > the arm changes in the series in order to avoid breaking the build
> > on that architecture.
> 
> I have applied this as the last patch of this series that I have applied.

Actually, I take that back.

I am also seeing problems with this patch on ppc.
I have dropped this patch for now.

powerpc-linux-gnu-ar: creating libutil.a
powerpc-linux-gnu-gcc -L/lib  -o build/sbin/kexec kexec/kexec.o kexec/ifdown.o kexec/kexec-elf.o kexec/kexec-elf-exec.o kexec/kexec-elf-core.o kexec/kexec-elf-rel.o kexec/kexec-elf-boot.o kexec/kexec-iomem.o kexec/firmware_memmap.o kexec/crashdump.o kexec/crashdump-xen.o kexec/phys_arch.o kexec/kernel_version.o kexec/lzma.o kexec/zlib.o kexec/proc_iomem.o kexec/virt_to_phys.o kexec/phys_to_virt.o kexec/add_segment.o kexec/add_buffer.o kexec/kexec-uImage.o kexec/arch/ppc/kexec-ppc.o kexec/arch/ppc/kexec-elf-ppc.o kexec/arch/ppc/kexec-elf-rel-ppc.o kexec/arch/ppc/kexec-dol-ppc.o kexec/arch/ppc/kexec-uImage-ppc.o kexec/arch/ppc/ppc-setup-simple.o kexec/arch/ppc/ppc-setup-dol.o kexec/arch/ppc/fixup_dtb.o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/crashdump-powerpc.o kexec/libfdt/fdt.o kexec/libfdt/fdt_ro.o kexec/libfdt/fdt_wip.o kexec/libfdt/fdt_sw.o kexec/libfdt/fdt_rw.o kexec/libfdt/fdt_strerror.o kexec/arch/ppc/libfdt-wrapper.o kexec/purgatory.o libutil.a -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes 
kexec/libfdt/fdt.o: In function `fdt_next_tag':
fdt.c:(.text+0x304): undefined reference to `_ALIGN'
kexec/libfdt/fdt_sw.o: In function `fdt_begin_node':
fdt_sw.c:(.text+0x4f4): undefined reference to `_ALIGN'
kexec/libfdt/fdt_sw.o: In function `fdt_property':
fdt_sw.c:(.text+0x648): undefined reference to `_ALIGN'
kexec/libfdt/fdt_sw.o: In function `fdt_create':
fdt_sw.c:(.text+0x744): undefined reference to `_ALIGN'
kexec/libfdt/fdt_rw.o: In function `_fdt_blocks_misordered':
fdt_rw.c:(.text+0x40): undefined reference to `_ALIGN'
kexec/libfdt/fdt_rw.o:fdt_rw.c:(.text+0x19c): more undefined references to `_ALIGN' follow
collect2: ld returned 1 exit status

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 09/13] kexec: ppc: use _ALIGN* to make the logic clear
  2013-03-14  9:57       ` Simon Horman
@ 2013-03-14 10:01         ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14 10:01 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org, Zhang Yanfei

On Thu, Mar 14, 2013 at 10:57:50AM +0100, Simon Horman wrote:
> On Thu, Mar 14, 2013 at 10:54:14AM +0100, Simon Horman wrote:
> > On Thu, Mar 14, 2013 at 05:33:10PM +0800, Zhang Yanfei wrote:
> > > By replacing all the explicit align opertion with marco _ALIGN*,
> > > the code logic could be more clear.
> > > 
> > > Besides, remove the duplicate _ALIGN_* definition in file
> > > kexec/arch/ppc/crashdump-powerpc.h.
> > 
> > Hi,
> > 
> > I am still seeing a build problem with v2.
> > 
> > powerpc-linux-gnu-gcc -L/lib  -o build/sbin/kexec kexec/kexec.o kexec/ifdown.o kexec/kexec-elf.o kexec/kexec-elf-exec.o kexec/kexec-elf-core.o kexec/kexec-elf-rel.o kexec/kexec-elf-boot.o kexec/kexec-iomem.o kexec/firmware_memmap.o kexec/crashdump.o kexec/crashdump-xen.o kexec/phys_arch.o kexec/kernel_version.o kexec/lzma.o kexec/zlib.o kexec/proc_iomem.o kexec/virt_to_phys.o kexec/phys_to_virt.o kexec/add_segment.o kexec/add_buffer.o kexec/kexec-uImage.o kexec/arch/ppc/kexec-ppc.o kexec/arch/ppc/kexec-elf-ppc.o kexec/arch/ppc/kexec-elf-rel-ppc.o kexec/arch/ppc/kexec-dol-ppc.o kexec/arch/ppc/kexec-uImage-ppc.o kexec/arch/ppc/ppc-setup-simple.o kexec/arch/ppc/ppc-setup-dol.o kexec/arch/ppc/fixup_dtb.o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/crashdump-powerpc.o kexec/libfdt/fdt.o kexec/libfdt/fdt_ro.o kexec/libfdt/fdt_wip.o kexec/libfdt/fdt_sw.o kexec/libfdt/fdt_rw.o kexec/libfdt/fdt_strerror.o
> > kexec/arch/ppc/libfdt-wrapper.o kexec/purgatory.o libutil.a -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes 
> > kexec/libfdt/fdt.o: In function `fdt_next_tag':
> > fdt.c:(.text+0x304): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_sw.o: In function `fdt_begin_node':
> > fdt_sw.c:(.text+0x4f4): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_sw.o: In function `fdt_property':
> > fdt_sw.c:(.text+0x648): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_sw.o: In function `fdt_create':
> > fdt_sw.c:(.text+0x744): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_rw.o: In function `_fdt_blocks_misordered':
> > fdt_rw.c:(.text+0x40): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_rw.o:fdt_rw.c:(.text+0x19c): more undefined references to
> > `_ALIGN' follow
> > collect2: ld returned 1 exit status
> 
> Actually, I think that the problem above relates to
> "kexec: use _ALIGN* to make the logic clear"

Sorry for the confusion. I have applied this patch ("kexec: ppc: use
_ALIGN* to make the logic clear") after dropping "kexec: use _ALIGN* to
make the logic clear".

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 11/13] kexec: s390: remove ALIGN_UP and use _ALIGN_UP
  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
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14 10:02 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:33:53AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> We have _ALIGN_UP now, so remove ALIGN_UP and use _ALIGN_UP
> instead of it.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 12/13] kexec: sh: use _ALIGN* to make the logic clear
  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
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14 10:03 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:34:41AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 13/13] kexec: x86_64: use _ALIGN* to make the logic clear
  2013-03-13 17:35 ` [PATCH 13/13] kexec: x86_64: " Zhang Yanfei
@ 2013-03-14 10:03   ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14 10:03 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 01:35:26AM +0800, Zhang Yanfei wrote:
> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> 
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2 10/13] kexec: ppc64: use _ALIGN* to make the logic clear
  2013-03-14  9:38   ` [PATCH v2 " Zhang Yanfei
@ 2013-03-14 10:04     ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14 10:04 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org, Zhang Yanfei

On Thu, Mar 14, 2013 at 05:38:02PM +0800, Zhang Yanfei wrote:
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could be more clear.
> 
> Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-14  9:48     ` Zhang Yanfei
@ 2013-03-14 10:06       ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-14 10:06 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org, Zhang Yanfei

On Thu, Mar 14, 2013 at 05:48:40PM +0800, Zhang Yanfei wrote:
> 于 2013年03月14日 17:08, Simon Horman 写道:
> > On Thu, Mar 14, 2013 at 01:26:56AM +0800, Zhang Yanfei wrote:
> >> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> >>
> >> By replacing all the explicit align opertions with marco _ALIGN*,
> >> the code logic could be more clear.
> > 
> > Not a big deal, but I believe this patch needs to come after
> > the arm changes in the series in order to avoid breaking the build
> > on that architecture.
> 
> Sorry, could you explain more? I don't have an arm machine, so, I couldn't
> test them.

The problem is that kexec/fs2dt.c is used by ARM.
So _ALIGN() needs to be added to ARM before using _ALIGN() in kexec/fs2dt.c.

> And I found a bug in this patch, still the ")" issue
> 
> +	len = _ALIGN(sizeof(bb[0], 8);
> 
> oops...
> 
> > 
> >>
> >> 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
> > 
> 
> 

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH v2 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-14  9:58       ` Simon Horman
@ 2013-03-14 11:24         ` Zhang Yanfei
  2013-03-14 11:26         ` [PATCH " Zhang Yanfei
  1 sibling, 0 replies; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-14 11:24 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-14  9:58       ` Simon Horman
  2013-03-14 11:24         ` [PATCH v2 " Zhang Yanfei
@ 2013-03-14 11:26         ` Zhang Yanfei
  2013-03-15  8:35           ` Simon Horman
  1 sibling, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-14 11:26 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org

于 2013年03月14日 17:58, Simon Horman 写道:
> On Thu, Mar 14, 2013 at 10:49:51AM +0100, Simon Horman wrote:
>> On Thu, Mar 14, 2013 at 10:08:06AM +0100, Simon Horman wrote:
>>> On Thu, Mar 14, 2013 at 01:26:56AM +0800, Zhang Yanfei wrote:
>>>> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
>>>>
>>>> By replacing all the explicit align opertions with marco _ALIGN*,
>>>> the code logic could be more clear.
>>>
>>> Not a big deal, but I believe this patch needs to come after
>>> the arm changes in the series in order to avoid breaking the build
>>> on that architecture.
>>
>> I have applied this as the last patch of this series that I have applied.
> 
> Actually, I take that back.
> 
> I am also seeing problems with this patch on ppc.
> I have dropped this patch for now.
> 
> powerpc-linux-gnu-ar: creating libutil.a
> powerpc-linux-gnu-gcc -L/lib  -o build/sbin/kexec kexec/kexec.o kexec/ifdown.o kexec/kexec-elf.o kexec/kexec-elf-exec.o kexec/kexec-elf-core.o kexec/kexec-elf-rel.o kexec/kexec-elf-boot.o kexec/kexec-iomem.o kexec/firmware_memmap.o kexec/crashdump.o kexec/crashdump-xen.o kexec/phys_arch.o kexec/kernel_version.o kexec/lzma.o kexec/zlib.o kexec/proc_iomem.o kexec/virt_to_phys.o kexec/phys_to_virt.o kexec/add_segment.o kexec/add_buffer.o kexec/kexec-uImage.o kexec/arch/ppc/kexec-ppc.o kexec/arch/ppc/kexec-elf-ppc.o kexec/arch/ppc/kexec-elf-rel-ppc.o kexec/arch/ppc/kexec-dol-ppc.o kexec/arch/ppc/kexec-uImage-ppc.o kexec/arch/ppc/ppc-setup-simple.o kexec/arch/ppc/ppc-setup-dol.o kexec/arch/ppc/fixup_dtb.o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/crashdump-powerpc.o kexec/libfdt/fdt.o kexec/libfdt/fdt_ro.o kexec/libfdt/fdt_wip.o kexec/libfdt/fdt_sw.o kexec/libfdt/fdt_rw.o kexec/libfdt/fdt_strerror.o kexec/arch/ppc/libfdt-wrapper.o kexec/purgatory.o libutil.a -Wall -Wextra -Wpointer-arith -Ww
rite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes 
> kexec/libfdt/fdt.o: In function `fdt_next_tag':
> fdt.c:(.text+0x304): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_sw.o: In function `fdt_begin_node':
> fdt_sw.c:(.text+0x4f4): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_sw.o: In function `fdt_property':
> fdt_sw.c:(.text+0x648): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_sw.o: In function `fdt_create':
> fdt_sw.c:(.text+0x744): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_rw.o: In function `_fdt_blocks_misordered':
> fdt_rw.c:(.text+0x40): undefined reference to `_ALIGN'
> kexec/libfdt/fdt_rw.o:fdt_rw.c:(.text+0x19c): more undefined references to `_ALIGN' follow
> collect2: ld returned 1 exit status

Hi simon,

Could you try the v2, please?

Thanks
Zhang

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-14 11:26         ` [PATCH " Zhang Yanfei
@ 2013-03-15  8:35           ` Simon Horman
  2013-03-15  9:46             ` [PATCH v3 " Zhang Yanfei
  0 siblings, 1 reply; 42+ messages in thread
From: Simon Horman @ 2013-03-15  8:35 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org

On Thu, Mar 14, 2013 at 07:26:18PM +0800, Zhang Yanfei wrote:
> 于 2013年03月14日 17:58, Simon Horman 写道:
> > On Thu, Mar 14, 2013 at 10:49:51AM +0100, Simon Horman wrote:
> >> On Thu, Mar 14, 2013 at 10:08:06AM +0100, Simon Horman wrote:
> >>> On Thu, Mar 14, 2013 at 01:26:56AM +0800, Zhang Yanfei wrote:
> >>>> From: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
> >>>>
> >>>> By replacing all the explicit align opertions with marco _ALIGN*,
> >>>> the code logic could be more clear.
> >>>
> >>> Not a big deal, but I believe this patch needs to come after
> >>> the arm changes in the series in order to avoid breaking the build
> >>> on that architecture.
> >>
> >> I have applied this as the last patch of this series that I have applied.
> > 
> > Actually, I take that back.
> > 
> > I am also seeing problems with this patch on ppc.
> > I have dropped this patch for now.
> > 
> > powerpc-linux-gnu-ar: creating libutil.a
> > powerpc-linux-gnu-gcc -L/lib  -o build/sbin/kexec kexec/kexec.o kexec/ifdown.o kexec/kexec-elf.o kexec/kexec-elf-exec.o kexec/kexec-elf-core.o kexec/kexec-elf-rel.o kexec/kexec-elf-boot.o kexec/kexec-iomem.o kexec/firmware_memmap.o kexec/crashdump.o kexec/crashdump-xen.o kexec/phys_arch.o kexec/kernel_version.o kexec/lzma.o kexec/zlib.o kexec/proc_iomem.o kexec/virt_to_phys.o kexec/phys_to_virt.o kexec/add_segment.o kexec/add_buffer.o kexec/kexec-uImage.o kexec/arch/ppc/kexec-ppc.o kexec/arch/ppc/kexec-elf-ppc.o kexec/arch/ppc/kexec-elf-rel-ppc.o kexec/arch/ppc/kexec-dol-ppc.o kexec/arch/ppc/kexec-uImage-ppc.o kexec/arch/ppc/ppc-setup-simple.o kexec/arch/ppc/ppc-setup-dol.o kexec/arch/ppc/fixup_dtb.o kexec/arch/ppc/fs2dt.o kexec/arch/ppc/crashdump-powerpc.o kexec/libfdt/fdt.o kexec/libfdt/fdt_ro.o kexec/libfdt/fdt_wip.o kexec/libfdt/fdt_sw.o kexec/libfdt/fdt_rw.o kexec/libfdt/fdt_strerror.o kexec/arch/ppc/libfdt-wrapper.o kexec/purgatory.o libutil.a -Wall -Wextra -Wpointer-arith -Ww
> rite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes 
> > kexec/libfdt/fdt.o: In function `fdt_next_tag':
> > fdt.c:(.text+0x304): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_sw.o: In function `fdt_begin_node':
> > fdt_sw.c:(.text+0x4f4): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_sw.o: In function `fdt_property':
> > fdt_sw.c:(.text+0x648): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_sw.o: In function `fdt_create':
> > fdt_sw.c:(.text+0x744): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_rw.o: In function `_fdt_blocks_misordered':
> > fdt_rw.c:(.text+0x40): undefined reference to `_ALIGN'
> > kexec/libfdt/fdt_rw.o:fdt_rw.c:(.text+0x19c): more undefined references to `_ALIGN' follow
> > collect2: ld returned 1 exit status
> 
> Hi simon,
> 
> Could you try the v2, please?

Unfortunately I am still seeing the same problem with v2.

What I suggest is that we drop the kexec/libfdt/libfdt_internal.h portion
of the patch entirely. With that version in place I can compile the code
cleanly for all supported architectures.

If you are ok with this change could you please send it as v3?


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

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH v3 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-15  8:35           ` Simon Horman
@ 2013-03-15  9:46             ` Zhang Yanfei
  2013-03-15 15:52               ` Simon Horman
  0 siblings, 1 reply; 42+ messages in thread
From: Zhang Yanfei @ 2013-03-15  9:46 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec@lists.infradead.org, Zhang Yanfei

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 +++++++--------
 6 files changed, 19 insertions(+), 22 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..1f5b0cf 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 - \
-- 
1.7.1


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

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH v3 04/13] kexec: use _ALIGN* to make the logic clear
  2013-03-15  9:46             ` [PATCH v3 " Zhang Yanfei
@ 2013-03-15 15:52               ` Simon Horman
  0 siblings, 0 replies; 42+ messages in thread
From: Simon Horman @ 2013-03-15 15:52 UTC (permalink / raw)
  To: Zhang Yanfei; +Cc: kexec@lists.infradead.org, Zhang Yanfei

On Fri, Mar 15, 2013 at 05:46:35PM +0800, Zhang Yanfei wrote:
> By replacing all the explicit align opertion with marco _ALIGN*,
> the code logic could more clear.

Thanks, applied.

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

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2013-03-15 15:52 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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         ` [PATCH v2 " Zhang Yanfei
2013-03-14 11:26         ` [PATCH " 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox