[LEDE-DEV] [PATCH] kmodloader: don't store aliases info in struct module

Yousong Zhou yszhou4tech at gmail.com
Wed Feb 22 19:25:56 PST 2017


This also fixes FS#544 as the allocation causing possible address alignment
issue should now disappear

Size comparison on x86_64 system

	function                                             old     new   delta
	alloc_module                                         398     245    -153
	------------------------------------------------------------------------------
	(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-153)           Total: -153 bytes

Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
---
Ted, please test it on your board to see if it can fix your issue.

The patch was only run-tested on armvirt cortex-a15 machine.

I actually thought about patching calloc_a to make sizeof_long-aligned
allocation as the comment in libubox/utils.h says the func should "allocate a
block of memory big enough to hold multiple aligned objects."

But that's too corase a solution for a fundamental lib and can waste runtime
memory.  Maybe we should reword that comment and provide a few helper macros
like SHORT_ALIGN, INT_ALIGN, LONG_ALIGN?

 kmodloader.c | 32 ++++----------------------------
 1 file changed, 4 insertions(+), 28 deletions(-)

diff --git a/kmodloader.c b/kmodloader.c
index ac14bac..892ddd8 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -48,8 +48,6 @@ struct module {
 	char *name;
 	char *depends;
 	char *opts;
-	char **aliases;
-	int naliases;
 
 	int size;
 	int usage;
@@ -250,16 +248,11 @@ alloc_module(const char *name, const char * const *aliases, int naliases, const
 {
 	struct module *m;
 	char *_name, *_dep;
-	char **_aliases;
-	int i, len_aliases;
+	int i;
 
-	len_aliases = naliases * sizeof(aliases[0]);
-	for (i = 0; i < naliases; i++)
-		len_aliases += strlen(aliases[i]) + 1;
 	m = calloc_a(sizeof(*m),
 		&_name, strlen(name) + 1,
-		&_dep, depends ? strlen(depends) + 2 : 0,
-		&_aliases, len_aliases);
+		&_dep, depends ? strlen(depends) + 2 : 0);
 	if (!m)
 		return NULL;
 
@@ -275,28 +268,11 @@ alloc_module(const char *name, const char * const *aliases, int naliases, const
 		}
 	}
 	m->size = size;
-	m->naliases = naliases;
-	if (naliases == 0)
-		m->aliases = NULL;
-	else {
-		char *ptr = (char *)_aliases + naliases * sizeof(_aliases[0]);
-		int len;
-
-		i = 0;
-		do {
-			len = strlen(aliases[i]) + 1;
-			memcpy(ptr, aliases[i], len);
-			_aliases[i] = ptr;
-			ptr += len;
-			i++;
-		} while (i < naliases);
-		m->aliases = _aliases;
-	}
 
 	m->refcnt = 0;
 	alloc_module_node(m->name, m, false);
-	for (i = 0; i < m->naliases; i++)
-		alloc_module_node(m->aliases[i], m, true);
+	for (i = 0; i < naliases; i++)
+		alloc_module_node(aliases[i], m, true);
 
 	return m;
 }
-- 
2.6.4




More information about the Lede-dev mailing list