Patchwork [3/7] jffs2reader: introduce ADD_BYTES macro

login
register
mail settings
Submitter Andy Shevchenko
Date Sept. 19, 2011, 11:25 a.m.
Message ID <8eaff6a30879c583f2f17944ea1868b51c9c2df2.1316431431.git.andriy.shevchenko@linux.intel.com>
Download mbox | patch
Permalink /patch/115389/
State New
Headers show

Comments

Andy Shevchenko - Sept. 19, 2011, 11:25 a.m.
This macro is dedicated to get rid of the compiler errors:
	lvalue required as left operand of assignment

Signed-off-by: Alexey Dokuchaev <danfe@nsu.ru>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 jffs2reader.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

Patch

diff --git a/jffs2reader.c b/jffs2reader.c
index 1fc9e74..9aee92c 100644
--- a/jffs2reader.c
+++ b/jffs2reader.c
@@ -88,6 +88,9 @@  BUGS:
 #define MINOR(dev) ((dev)&0xff)
 #endif
 
+/* macro to avoid "lvalue required as left operand of assignment" error */
+#define ADD_BYTES(p, n)		((p) = (typeof(p))((char *)(p) + (n)))
+
 #define DIRENT_INO(dirent) ((dirent)!=NULL?je32_to_cpu((dirent)->ino):0)
 #define DIRENT_PINO(dirent) ((dirent)!=NULL?je32_to_cpu((dirent)->pino):0)
 
@@ -441,7 +444,7 @@  struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino)
 
 	do {
 		while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK)
-			((char *) n) += 4;
+			ADD_BYTES(n, 4);
 
 		if (n < e && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) {
 			if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_INODE &&
@@ -459,7 +462,7 @@  struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino)
 					return (&(n->i));
 			}
 
-			((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3);
+			ADD_BYTES(n, ((je32_to_cpu(n->u.totlen) + 3) & ~3));
 		} else
 			n = (union jffs2_node_union *) o;	/* we're at the end, rewind to the beginning */
 
@@ -509,7 +512,7 @@  struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d)
 
 	do {
 		while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK)
-			((char *) n) += 4;
+			ADD_BYTES(n, 4);
 
 		if (n < e && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) {
 			if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_DIRENT &&
@@ -532,7 +535,7 @@  struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d)
 				}
 			}
 
-			((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3);
+			ADD_BYTES(n, ((je32_to_cpu(n->u.totlen) + 3) & ~3));
 		} else
 			n = (union jffs2_node_union *) o;	/* we're at the end, rewind to the beginning */
 
@@ -596,7 +599,7 @@  struct jffs2_raw_dirent *resolvedirent(char *o, size_t size,
 
 	do {
 		while (n < e && je16_to_cpu(n->u.magic) != JFFS2_MAGIC_BITMASK)
-			((char *) n) += 4;
+			ADD_BYTES(n, 4);
 
 		if (n < e && je16_to_cpu(n->u.magic) == JFFS2_MAGIC_BITMASK) {
 			if (je16_to_cpu(n->u.nodetype) == JFFS2_NODETYPE_DIRENT &&
@@ -613,7 +616,7 @@  struct jffs2_raw_dirent *resolvedirent(char *o, size_t size,
 				}
 			}
 
-			((char *) n) += ((je32_to_cpu(n->u.totlen) + 3) & ~3);
+			ADD_BYTES(n, ((je32_to_cpu(n->u.totlen) + 3) & ~3));
 		} else
 			return dd;
 	} while (1);