* libkmod - interface to kernel module operations
*
* Copyright (C) 2011-2013 ProFUSION embedded systems
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
const char *command_name,
struct kmod_list **list)
{
- struct kmod_command *cmd;
+ _cleanup_free_ struct kmod_command *cmd;
struct kmod_list *l;
size_t modnamelen = strlen(modname) + 1;
size_t commandlen = strlen(command) + 1;
command);
cmd = malloc(sizeof(*cmd) + modnamelen + commandlen);
- if (cmd == NULL)
- goto oom_error_init;
+ if (!cmd)
+ return -ENOMEM;
cmd->command = sizeof(*cmd) + modnamelen + (char *)cmd;
memcpy(cmd->modname, modname, modnamelen);
memcpy(cmd->command, command, commandlen);
l = kmod_list_append(*list, cmd);
- if (l == NULL)
- goto oom_error;
+ if (!l)
+ return -ENOMEM;
*list = l;
+ cmd = NULL;
return 0;
-
-oom_error:
- free(cmd);
-oom_error_init:
- ERR(config->ctx, "out-of-memory\n");
- return -ENOMEM;
}
static void kmod_config_free_command(struct kmod_config *config,
static int kmod_config_add_options(struct kmod_config *config,
const char *modname, const char *options)
{
- struct kmod_options *opt;
+ _cleanup_free_ struct kmod_options *opt;
struct kmod_list *list;
size_t modnamelen = strlen(modname) + 1;
size_t optionslen = strlen(options) + 1;
DBG(config->ctx, "modname='%s' options='%s'\n", modname, options);
opt = malloc(sizeof(*opt) + modnamelen + optionslen);
- if (opt == NULL)
- goto oom_error_init;
+ if (!opt)
+ return -ENOMEM;
opt->options = sizeof(*opt) + modnamelen + (char *)opt;
strchr_replace(opt->options, '\t', ' ');
list = kmod_list_append(config->options, opt);
- if (list == NULL)
- goto oom_error;
+ if (!list)
+ return -ENOMEM;
+ opt = NULL;
config->options = list;
return 0;
-
-oom_error:
- free(opt);
-oom_error_init:
- ERR(config->ctx, "out-of-memory\n");
- return -ENOMEM;
}
static void kmod_config_free_options(struct kmod_config *config,
static int kmod_config_add_alias(struct kmod_config *config,
const char *name, const char *modname)
{
- struct kmod_alias *alias;
+ _cleanup_free_ struct kmod_alias *alias;
struct kmod_list *list;
size_t namelen = strlen(name) + 1, modnamelen = strlen(modname) + 1;
alias = malloc(sizeof(*alias) + namelen + modnamelen);
if (!alias)
- goto oom_error_init;
+ return -ENOMEM;
alias->name = sizeof(*alias) + modnamelen + (char *)alias;
list = kmod_list_append(config->aliases, alias);
if (!list)
- goto oom_error;
+ return -ENOMEM;
+ alias = NULL;
config->aliases = list;
return 0;
-
-oom_error:
- free(alias);
-oom_error_init:
- ERR(config->ctx, "out-of-memory name=%s modname=%s\n", name, modname);
- return -ENOMEM;
}
static void kmod_config_free_alias(struct kmod_config *config,
static int kmod_config_add_blacklist(struct kmod_config *config,
const char *modname)
{
- char *p;
+ _cleanup_free_ char *p;
struct kmod_list *list;
DBG(config->ctx, "modname=%s\n", modname);
p = strdup(modname);
if (!p)
- goto oom_error_init;
+ return -ENOMEM;
list = kmod_list_append(config->blacklists, p);
if (!list)
- goto oom_error;
+ return -ENOMEM;
+
+ p = NULL;
config->blacklists = list;
return 0;
-
-oom_error:
- free(p);
-oom_error_init:
- ERR(config->ctx, "out-of-memory modname=%s\n", modname);
- return -ENOMEM;
}
static void kmod_config_free_blacklist(struct kmod_config *config,