public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: "Timofei V. Bondarenko" <timm@ipi.ac.ru>
Cc: linux-mtd@lists.infradead.org
Subject: Re: misaligned memory access in cmdlinepart.c
Date: Mon, 06 Jun 2005 19:28:13 +0400	[thread overview]
Message-ID: <42A46B8D.9030607@ipi.ac.ru> (raw)
In-Reply-To: <20050606141453.GF31739@wohnheim.fh-wedel.de>

Jörn Engel wrote:
> On Mon, 6 June 2005 18:01:16 +0400, Timofei V. Bondarenko wrote:
> 
>>Index: cmdlinepart.c
>>===================================================================
>>RCS file: /home/cvs/mtd/drivers/mtd/cmdlinepart.c,v
>>retrieving revision 1.17
>>diff -u -p -r1.17 cmdlinepart.c
>>--- cmdlinepart.c	26 Nov 2004 11:18:47 -0000	1.17
>>+++ cmdlinepart.c	6 Jun 2005 13:57:08 -0000
>>@@ -234,12 +234,14 @@ static int mtdpart_setup_real(char *s)
>> 		 * parse one mtd. have it reserve memory for the
>> 		 * struct cmdline_mtd_partition and the mtd-id string.
>> 		 */
>>+#define THIS_MTD_ALIGN_CONST sizeof(void*)
> 
> Not sure if this macro is worth the pain.  If it is, you should
> declare it outside the function.  Just above is what most people do.

Ok.. That's matter of taste. I'm rather like to complicate things.

>>+		/* align this_mtd */
>>+                this_mtd = (struct cmdline_mtd_partition *)
>>+                    ALIGN((unsigned long)this_mtd, THIS_MTD_ALIGN_CONST);
>>+		/* enter results */
> 
> 
> Gcc allows arithmetic with (void*) exactly for code like this:
> 		this_mtd = ALIGN((void*)this_mtd, THIS_MTD_ALIGN_CONST);
> or:
> 		this_mtd = ALIGN((void*)this_mtd, sizeof(void*));
> 
> You should retest it, though.

error: invalid operands to binary &

Then we've to cast it from integer to a pointer type.

--
	Timofei.


Index: cmdlinepart.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/cmdlinepart.c,v
retrieving revision 1.17
diff -u -p -r1.17 cmdlinepart.c
--- cmdlinepart.c	26 Nov 2004 11:18:47 -0000	1.17
+++ cmdlinepart.c	6 Jun 2005 14:33:59 -0000
@@ -239,7 +239,8 @@ static int mtdpart_setup_real(char *s)
  				&num_parts,	/* out: number of parts */
  				0,		/* first partition */
  				(unsigned char**)&this_mtd, /* out: extra mem */
-				mtd_id_len + 1 + sizeof(*this_mtd));
+				mtd_id_len + 1 + sizeof(*this_mtd) +
+                                sizeof(void*)-1 /*alignment*/);
  		if(!parts)
  		{
  			/*
@@ -252,7 +253,10 @@ static int mtdpart_setup_real(char *s)
  			 return 0;
  		 }

-		/* enter results */	
+		/* align this_mtd */
+                this_mtd = (struct cmdline_mtd_partition *)
+                    ALIGN((unsigned long)this_mtd, sizeof(void*));
+		/* enter results */
  		this_mtd->parts = parts;
  		this_mtd->num_parts = num_parts;
  		this_mtd->mtd_id = (char*)(this_mtd + 1);

  parent reply	other threads:[~2005-06-06 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-27 11:03 misaligned memory access in cmdlinepart.c Timofei V. Bondarenko
2005-06-06 13:26 ` Timofei V. Bondarenko
2005-06-06 13:34 ` Jörn Engel
     [not found]   ` <42A4572C.8020107@ipi.ac.ru>
     [not found]     ` <20050606141453.GF31739@wohnheim.fh-wedel.de>
2005-06-06 15:28       ` Timofei V. Bondarenko [this message]
     [not found]       ` <42A460BB.50800@ipi.ac.ru>
     [not found]         ` <20050606162648.GJ31739@wohnheim.fh-wedel.de>
2005-06-06 16:49           ` Timofei V. Bondarenko
2005-06-06 17:44             ` Jörn Engel
2005-06-07  8:30               ` Timofei V. Bondarenko
2005-06-07  9:01                 ` Vitaly Wool
2005-06-07  9:26                   ` Timofei V. Bondarenko
2005-06-07 11:34                   ` Timofei V. Bondarenko
2005-06-07 13:02                 ` Jörn Engel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42A46B8D.9030607@ipi.ac.ru \
    --to=timm@ipi.ac.ru \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox