summaryrefslogtreecommitdiff
path: root/libkmod
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.cz>2013-01-16 10:18:17 +0100
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-01-16 09:53:46 -0200
commitf64458cab522670135950adc4b04f18df20ae947 (patch)
tree57f8cd6d270a22ff7df14bac1bec10f917377bb5 /libkmod
parent4111bc0fc7fa00b40f401445bc84da1e39afeeb5 (diff)
downloadkmod-f64458cab522670135950adc4b04f18df20ae947.tar.gz
kmod-f64458cab522670135950adc4b04f18df20ae947.tar.bz2
kmod-f64458cab522670135950adc4b04f18df20ae947.zip
libkmod-module: Add helper for building the module info list
Diffstat (limited to 'libkmod')
-rw-r--r--libkmod/libkmod-module.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 0d87ce1..ae0d9c8 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -2094,6 +2094,25 @@ static void kmod_module_info_free(struct kmod_module_info *info)
free(info);
}
+static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const char *key, size_t keylen, const char *value, size_t valuelen)
+{
+ struct kmod_module_info *info;
+ struct kmod_list *n;
+
+ info = kmod_module_info_new(key, keylen, value, valuelen);
+ if (info == NULL) {
+ kmod_module_info_free_list(*list);
+ return NULL;
+ }
+ n = kmod_list_append(*list, info);
+ if (n == NULL) {
+ kmod_module_info_free(info);
+ kmod_module_info_free_list(*list);
+ }
+ *list = n;
+ return n;
+}
+
/**
* kmod_module_get_info:
* @mod: kmod module
@@ -2114,7 +2133,7 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
{
struct kmod_elf *elf;
char **strings;
- int i, count, ret = 0;
+ int i, count, ret = -ENOMEM;
if (mod == NULL || list == NULL)
return -ENOENT;
@@ -2130,7 +2149,6 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
return count;
for (i = 0; i < count; i++) {
- struct kmod_module_info *info;
struct kmod_list *n;
const char *key, *value;
size_t keylen, valuelen;
@@ -2146,24 +2164,9 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
valuelen = strlen(value);
}
- info = kmod_module_info_new(key, keylen, value, valuelen);
- if (info == NULL) {
- ret = -errno;
- kmod_module_info_free_list(*list);
- *list = NULL;
- goto list_error;
- }
-
- n = kmod_list_append(*list, info);
- if (n != NULL)
- *list = n;
- else {
- kmod_module_info_free(info);
- kmod_module_info_free_list(*list);
- *list = NULL;
- ret = -ENOMEM;
+ n = kmod_module_info_append(list, key, keylen, value, valuelen);
+ if (n == NULL)
goto list_error;
- }
}
ret = count;