Skip to contentSkip to conversation

checkpatch.pl: Add warning for new __packed additions

PATCH New Tom Rini 1 participant 2 messages Feb 25, 2014

Subsystems (4)
lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH v3 1/2 checkpatch.pl: Add warning for new __packed additions

While there are valid reasons to use __packed, often the answer is that you should be doing something else here instead.

---
 scripts/checkpatch.pl |    5 +++++
 1 file changed, 5 insertions(+)
scripts/checkpatch.pl +5 -0
index 88c5bc7..df0820c 100755
@@ -3331,6 +3331,11 @@ sub process {
 			WARN("PREFER_PACKED",
 			     "__packed is preferred over __attribute__((packed))\n" . $herecurr);
 		}
+# Check for new packed members, warn to use care
+		if ($line =~ /\b(__attribute__\s*\(\s*\(.*\bpacked|__packed)\b/) {
+			WARN("NEW_PACKED",
+			     "Adding new packed members is to be done with care\n" . $herecurr);
+		}
 
 # Check for __attribute__ aligned, prefer __aligned
 		if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v3 2/2 arm: Switch to -mno-unaligned-access when supported by the compiler

When we tell the compiler to optimize for ARMv7 (and ARMv6 for that matter) it assumes a default of SCTRL.A being cleared and unaligned accesses being allowed and fast at the hardware level. We set this bit and must pass along -mno-unaligned-access so that the compiler will still breakdown accesses and not trigger a data abort.

To better help understand the requirements of the project with respect to unaligned memory access, the Documentation/unaligned-memory-access.txt file has been added as doc/README.unaligned-memory-access.txt and is taken from the v3.14-rc1 tag of the kernel.

Cc Albert ARIBAUD <[email protected]>
Cc Mans Rullgard <[email protected]>

---
Changes in v3:
- Rebase on v2014.04-rc1
- Add doc/README.unaligned-memory-access.txt based on kernel Documentation/unaligned-memory-access.txt
- Correct comment in arch/arm/cpu/armv7/config.mk about what bit is having what done with it.
- Put back a printf in do_data_abort

Changes in v2:
- Drop references to README.arm-unaligned-accesses from arch/arm/lib/interrupts.c and top-level README

---
 README                                 |    2 +-
 arch/arm/cpu/armv7/config.mk           |    7 +-
 arch/arm/cpu/armv8/config.mk           |    5 +-
 arch/arm/lib/interrupts.c              |    2 +-
 common/Makefile                        |    2 -
 doc/README.arm-unaligned-accesses      |  122 ----------------
 doc/README.unaligned-memory-access.txt |  240 ++++++++++++++++++++++++++++++++
 fs/ubifs/Makefile                      |    3 -
 lib/Makefile                           |    3 -
 9 files changed, 248 insertions(+), 138 deletions(-)
 delete mode 100644 doc/README.arm-unaligned-accesses
 create mode 100644 doc/README.unaligned-memory-access.txt
README +1 -1
index f51f17e..2a775aa 100644
@@ -1741,7 +1741,7 @@ CBFS (Coreboot Filesystem) support
 
 		If this option is set, then U-Boot will prevent the environment
 		variable "splashimage" from being set to a problematic address
-		(see README.displaying-bmps and README.arm-unaligned-accesses).
+		(see README.displaying-bmps).
 		This option is useful for targets where, due to alignment
 		restrictions, an improperly aligned BMP image will cause a data
 		abort. If you think you will not have problems with unaligned
arch/arm/cpu/armv7/config.mk +5 -2
index d01f3d9..c048531 100644
@@ -10,9 +10,12 @@
 PF_CPPFLAGS_ARMV7 := $(call cc-option, -march=armv7-a, -march=armv5)
 PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARMV7)
 
-# SEE README.arm-unaligned-accesses
+# On supported platforms we set the bit which causes us to trap on unaligned
+# memory access.  This is the opposite of what the compiler expects to be
+# the default so we must pass in -mno-unaligned-access so that it is aware
+# of our decision.
 PF_NO_UNALIGNED := $(call cc-option, -mno-unaligned-access,)
-PLATFORM_NO_UNALIGNED := $(PF_NO_UNALIGNED)
+PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED)
 
 ifneq ($(CONFIG_IMX_CONFIG),)
 ifdef CONFIG_SPL
arch/arm/cpu/armv8/config.mk +1 -4
index 027a68c..f5b9559 100644
@@ -6,10 +6,7 @@
 #
 PLATFORM_RELFLAGS += -fno-common -ffixed-x18
 
-# SEE README.arm-unaligned-accesses
-PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)
-PLATFORM_NO_UNALIGNED := $(PF_NO_UNALIGNED)
-
 PF_CPPFLAGS_ARMV8 := $(call cc-option, -march=armv8-a)
+PF_NO_UNALIGNED := $(call cc-option, -mstrict-align)
 PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARMV8)
 PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED)
arch/arm/lib/interrupts.c +1 -1
index 603bf14..758b013 100644
@@ -153,7 +153,7 @@ void do_prefetch_abort (struct pt_regs *pt_regs)
 
 void do_data_abort (struct pt_regs *pt_regs)
 {
-	printf ("data abort\n\n    MAYBE you should read doc/README.arm-unaligned-accesses\n\n");
+	printf ("data abort\n");
 	show_regs (pt_regs);
 	bad_mode ();
 }
common/Makefile +0 -2
index 6652ad4..ca9af13 100644
@@ -238,5 +238,3 @@ obj-y += memsize.o
 obj-y += stdio.o
 
 CFLAGS_env_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null)
-CFLAGS_hush.o := $(PLATFORM_NO_UNALIGNED)
-CFLAGS_fdt_support.o := $(PLATFORM_NO_UNALIGNED)
doc/README.arm-unaligned-accesses deleted +0 -122

122 lines not on this page · raw message

doc/README.unaligned-memory-access.txt new file +240 -0

240 lines not on this page · raw message

fs/ubifs/Makefile +0 -3
index 6b1a9a5..8c8c6ac 100644
@@ -13,6 +13,3 @@ obj-y := ubifs.o io.o super.o sb.o master.o lpt.o
 obj-y += lpt_commit.o scan.o lprops.o
 obj-y += tnc.o tnc_misc.o debug.o crc16.o budget.o
 obj-y += log.o orphan.o recovery.o replay.o
-
-# SEE README.arm-unaligned-accesses
-CFLAGS_super.o := $(PLATFORM_NO_UNALIGNED)
lib/Makefile +0 -3
index 8c483c9..dedb97b 100644
@@ -65,6 +65,3 @@ obj-y += vsprintf.o
 obj-$(CONFIG_RANDOM_MACADDR) += rand.o
 obj-$(CONFIG_BOOTP_RANDOM_DELAY) += rand.o
 obj-$(CONFIG_CMD_LINK_LOCAL) += rand.o
-
-# SEE README.arm-unaligned-accesses
-CFLAGS_bzlib.o := $(PLATFORM_NO_UNALIGNED)
Signature · 1 line
1.7.9.5