kernel oops due to aligment error in cmdlinepart.c
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
Index: drivers/mtd/cmdlinepart.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/cmdlinepart.c,v retrieving revision 1.10
mtd/cmdlinepart.c +16 -1
@@ -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;
Quoted 6 lines · George G. Davis
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.chas 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.
Signature · 1 line
dwmw2