| From 9bf05abe85282af4ce38dfac9c5d20e237ad7482 Mon Sep 17 00:00:00 2001 |
| From: Mandeep Singh Baines <msb@chromium.org> |
| Date: Tue, 5 Feb 2013 22:04:09 -0800 |
| Subject: [PATCH] modutils: use finit_module if available |
| |
| Signed-off-by: Mandeep Singh Baines <msb@chromium.org> |
| --- |
| modutils/modprobe-small.c | 22 ++++++++++++++++++++++ |
| modutils/modutils.c | 21 +++++++++++++++++++++ |
| 2 files changed, 43 insertions(+) |
| |
| diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c |
| index 5b78363..0e073f8 100644 |
| --- a/modutils/modprobe-small.c |
| +++ b/modutils/modprobe-small.c |
| @@ -18,10 +18,15 @@ |
| /* After libbb.h, since it needs sys/types.h on some systems */ |
| #include <sys/utsname.h> /* uname() */ |
| #include <fnmatch.h> |
| +#include <sys/syscall.h> |
| |
| extern int init_module(void *module, unsigned long len, const char *options); |
| extern int delete_module(const char *module, unsigned flags); |
| extern int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret); |
| +#ifdef __NR_finit_module |
| +# define finit_module(fd, uargs, flags) \ |
| + syscall(__NR_finit_module, fd, uargs, flags) |
| +#endif |
| |
| |
| #if 1 |
| @@ -174,6 +179,22 @@ static const char *moderror(int err) |
| } |
| } |
| |
| +#ifdef finit_module |
| +static int load_module(const char *fname, const char *options) |
| +{ |
| + int fd, rc; |
| + |
| + fd = open(fname, O_RDONLY); |
| + if (fd < 0) |
| + return 1; |
| + |
| + rc = finit_module(fd, options ? options : "", 0) != 0; |
| + |
| + close(fd); |
| + |
| + return rc; |
| +} |
| +#else |
| static int load_module(const char *fname, const char *options) |
| { |
| #if 1 |
| @@ -193,6 +214,7 @@ static int load_module(const char *fname, const char *options) |
| return 1; |
| #endif |
| } |
| +#endif |
| |
| static void parse_module(module_info *info, const char *pathname) |
| { |
| diff --git a/modutils/modutils.c b/modutils/modutils.c |
| index 6187ca7..25fb642 100644 |
| --- a/modutils/modutils.c |
| +++ b/modutils/modutils.c |
| @@ -13,6 +13,10 @@ extern int delete_module(const char *module, unsigned int flags); |
| #else |
| # include <sys/syscall.h> |
| # define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts) |
| +#ifdef __NR_finit_module |
| +# define finit_module(fd, uargs, flags) \ |
| + syscall(__NR_finit_module, fd, uargs, flags) |
| +#endif |
| # define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) |
| #endif |
| |
| @@ -137,6 +141,22 @@ void* FAST_FUNC try_to_mmap_module(const char *filename, size_t *image_size_p) |
| * -errno on open/read error, |
| * errno on init_module() error |
| */ |
| +#ifdef finit_module |
| +int FAST_FUNC bb_init_module(const char *filename, const char *options) |
| +{ |
| + int fd, rc; |
| + |
| + fd = open(filename, O_RDONLY); |
| + if (fd < 0) |
| + return 1; |
| + |
| + rc = finit_module(fd, options ? options : "", 0) != 0; |
| + |
| + close(fd); |
| + |
| + return rc; |
| +} |
| +#else |
| int FAST_FUNC bb_init_module(const char *filename, const char *options) |
| { |
| size_t image_size; |
| @@ -174,6 +194,7 @@ int FAST_FUNC bb_init_module(const char *filename, const char *options) |
| free(image); |
| return rc; |
| } |
| +#endif |
| |
| int FAST_FUNC bb_delete_module(const char *module, unsigned int flags) |
| { |
| -- |
| 1.7.12.4 |
| |