public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* kernel oops due to aligment error in cmdlinepart.c
@ 2003-08-01  0:02 George G. Davis
  2003-08-01 13:24 ` David Woodhouse
  0 siblings, 1 reply; 2+ messages in thread
From: George G. Davis @ 2003-08-01  0:02 UTC (permalink / raw)
  To: linux-mtd

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

Greetings,

I've been using the latest MTD CVS (+/- a few days) on an ARM Integrator/CM920T
running linux-2.4.20'ish and have found that cmdlinepart.c has a struct alignment
problem which causes a kernel oops. The attached patch fixes the alignment problem
for me (YMMV : ). I've successfully tested this on an ARM Integrator/CM920T, ADS
Graphics Client Plus and TI Innovator/OMAP1510, FWIW. : )

--
Regards,
George


[-- Attachment #2: cmdlinepart.patch --]
[-- Type: text/plain, Size: 1228 bytes --]

Index: drivers/mtd/cmdlinepart.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/cmdlinepart.c,v
retrieving revision 1.10
diff -u -r1.10 cmdlinepart.c
--- drivers/mtd/cmdlinepart.c	29 May 2003 09:25:22 -0000	1.10
+++ drivers/mtd/cmdlinepart.c	31 Jul 2003 23:48:20 -0000
@@ -241,6 +241,7 @@
 				&num_parts,	/* out: number of parts */
 				0,		/* first partition */
 				(unsigned char**)&this_mtd, /* out: extra mem */
+				__alignof__(*this_mtd) - 1 +
 				mtd_id_len + 1 + sizeof(*this_mtd));
 		if(!parts)
 		{
@@ -252,7 +253,21 @@
 			 * unlikely to succeed in parsing any more
 			 */
 			 return 0;
-		 }
+		}
+
+		if ((unsigned long)(this_mtd) & (__alignof__(*this_mtd) - 1))
+		{
+			/* Some archs do not allow non-aligned accesses
+			 * within the kernel. So make sure we're properly
+			 * aligned here.
+			 */
+			unsigned long fixup = (unsigned long) this_mtd;
+			dbg(("this_mtd: 0x%0x\n", this_mtd));
+			fixup += __alignof__(*this_mtd) - 1;
+			fixup &= ~(__alignof__(*this_mtd) - 1);
+			this_mtd = (struct cmdline_mtd_partition *) fixup;
+			dbg(("this_mtd: 0x%0x (aligned)\n", this_mtd));
+		}
 
 		/* enter results */	    
 		this_mtd->parts = parts;

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

* Re: kernel oops due to aligment error in cmdlinepart.c
  2003-08-01  0:02 kernel oops due to aligment error in cmdlinepart.c George G. Davis
@ 2003-08-01 13:24 ` David Woodhouse
  0 siblings, 0 replies; 2+ messages in thread
From: David Woodhouse @ 2003-08-01 13:24 UTC (permalink / raw)
  To: gdavis; +Cc: linux-mtd

On Fri, 2003-08-01 at 01:02, George G. Davis wrote:
> Greetings,
> 
> I've been using the latest MTD CVS (+/- a few days) on an ARM
> Integrator/CM920T running linux-2.4.20'ish and have found that
> cmdlinepart.c has a struct alignment problem which causes a kernel
> oops. The attached patch fixes the alignment problem

No Likee. Linux requires that you fix up misaligned loads and stores.
Therefore, explicit working around alignment 'breakage' isn't permitted.
I've added it before and been told to remove it.

IF your hardware _cannot_ do this, and I know some ARM7 uCLinux systems
really can't, then you need to deal with it properly in 2.5 -- talk to
DaveM and Linus about it. 

Alternatively, in this case you could probably just refactor the code to
allocate the idents separately or at least arrange its storage so that
the aligned bits are first, like I think the RedBoot code does.

-- 
dwmw2

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

end of thread, other threads:[~2003-08-01 13:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-01  0:02 kernel oops due to aligment error in cmdlinepart.c George G. Davis
2003-08-01 13:24 ` David Woodhouse

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