From: Michal MalĂ˝ Date: Fri, 19 Sep 2014 23:42:16 +0000 (+0200) Subject: Return ints from stream manipulation functions for better error handling X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=a63f7b09b823712244c807962dd5a3b83c3bf850;p=KLGD.git Return ints from stream manipulation functions for better error handling --- diff --git a/klgd.c b/klgd.c index 76fdc4a..39c963a 100644 --- a/klgd.c +++ b/klgd.c @@ -53,54 +53,54 @@ struct klgd_command_stream * klgd_alloc_stream(void) } EXPORT_SYMBOL_GPL(klgd_alloc_stream); -bool klgd_append_cmd(struct klgd_command_stream *target, const struct klgd_command *cmd) +int klgd_append_cmd(struct klgd_command_stream *target, const struct klgd_command *cmd) { const struct klgd_command **temp; if (!target) { printk(KERN_NOTICE "Cannot append to NULL stream\n"); - return false; + return -EINVAL; } if (!cmd) { printk(KERN_NOTICE "Cannot append NULL cmd\n"); - return false; + return -EINVAL; } temp = krealloc(target->commands, sizeof(struct klgd_command *) * (target->count + 1), GFP_KERNEL); if (!temp) - return false; + return -ENOMEM; target->commands = temp; target->commands[target->count] = cmd; target->count++; - return true; + return 0; } EXPORT_SYMBOL_GPL(klgd_append_cmd); -bool klgd_append_stream(struct klgd_command_stream *target, const struct klgd_command_stream *source) +int klgd_append_stream(struct klgd_command_stream *target, const struct klgd_command_stream *source) { const struct klgd_command **temp; size_t idx; /* We got NULL command, skip it */ if (!source) - return true; + return 0; /* We got command of zero length, skip it */ if (!source->count) - return true; + return 0; temp = krealloc(target->commands, sizeof(struct klgd_command *) * (target->count + source->count), GFP_KERNEL); if (!temp) - return false; + return -ENOMEM; target->commands = temp; for (idx = 0; idx < source->count; idx++) target->commands[idx + target->count] = source->commands[idx]; target->count += source->count; - return true; + return 0; } EXPORT_SYMBOL_GPL(klgd_append_stream); @@ -119,7 +119,7 @@ int klgd_build_command_stream(struct klgd_main_private *priv, struct klgd_comman for (idx = 0; idx < priv->plugin_count; idx++) { struct klgd_plugin *plugin = priv->plugins[idx]; struct klgd_command_stream *ss = plugin->get_commands(plugin, now); - if (!klgd_append_stream(*s, ss)) { + if (klgd_append_stream(*s, ss)) { klgd_free_stream(*s); return -EAGAIN; } diff --git a/klgd.h b/klgd.h index 6fc384b..11c93ca 100644 --- a/klgd.h +++ b/klgd.h @@ -25,8 +25,8 @@ struct klgd_plugin { struct klgd_command * klgd_alloc_cmd(const size_t length); struct klgd_command_stream * klgd_alloc_stream(void); -bool klgd_append_cmd(struct klgd_command_stream *target, const struct klgd_command *cmd); -bool klgd_append_stream(struct klgd_command_stream *target, const struct klgd_command_stream *source); +int klgd_append_cmd(struct klgd_command_stream *target, const struct klgd_command *cmd); +int klgd_append_stream(struct klgd_command_stream *target, const struct klgd_command_stream *source); void klgd_deinit(struct klgd_main *ctx); void klgd_free_stream(struct klgd_command_stream *s); int klgd_init(struct klgd_main *ctx, void *dev_ctx, int (*callback)(void *, const struct klgd_command_stream *), const unsigned long plugin_count);