Commit 456aec73 authored by Justin Skists's avatar Justin Skists Committed by Greg Kroah-Hartman

staging: speakup: refactor synths array to use a list

The synths[] array is a collection of synths acting like a list.
There is no need for synths to be an array, so refactor synths[] to use
standard kernel list_head API, instead, and modify the usages to suit.
As a side-effect, the maximum number of synths has also become redundant.
Signed-off-by: default avatarJustin Skists <justin.skists@juzza.co.uk>
Reviewed-by: default avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2665df51
...@@ -160,6 +160,8 @@ struct spk_io_ops { ...@@ -160,6 +160,8 @@ struct spk_io_ops {
}; };
struct spk_synth { struct spk_synth {
struct list_head node;
const char *name; const char *name;
const char *version; const char *version;
const char *long_name; const char *long_name;
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
#include "speakup.h" #include "speakup.h"
#include "serialio.h" #include "serialio.h"
#define MAXSYNTHS 16 /* Max number of synths in array. */ static LIST_HEAD(synths);
static struct spk_synth *synths[MAXSYNTHS + 1];
struct spk_synth *synth; struct spk_synth *synth;
char spk_pitch_buff[32] = ""; char spk_pitch_buff[32] = "";
static int module_status; static int module_status;
...@@ -355,9 +354,8 @@ struct var_t synth_time_vars[] = { ...@@ -355,9 +354,8 @@ struct var_t synth_time_vars[] = {
/* called by: speakup_init() */ /* called by: speakup_init() */
int synth_init(char *synth_name) int synth_init(char *synth_name)
{ {
int i;
int ret = 0; int ret = 0;
struct spk_synth *synth = NULL; struct spk_synth *tmp, *synth = NULL;
if (!synth_name) if (!synth_name)
return 0; return 0;
...@@ -371,9 +369,10 @@ int synth_init(char *synth_name) ...@@ -371,9 +369,10 @@ int synth_init(char *synth_name)
mutex_lock(&spk_mutex); mutex_lock(&spk_mutex);
/* First, check if we already have it loaded. */ /* First, check if we already have it loaded. */
for (i = 0; i < MAXSYNTHS && synths[i]; i++) list_for_each_entry(tmp, &synths, node) {
if (strcmp(synths[i]->name, synth_name) == 0) if (strcmp(tmp->name, synth_name) == 0)
synth = synths[i]; synth = tmp;
}
/* If we got one, initialize it now. */ /* If we got one, initialize it now. */
if (synth) if (synth)
...@@ -448,29 +447,23 @@ void synth_release(void) ...@@ -448,29 +447,23 @@ void synth_release(void)
/* called by: all_driver_init() */ /* called by: all_driver_init() */
int synth_add(struct spk_synth *in_synth) int synth_add(struct spk_synth *in_synth)
{ {
int i;
int status = 0; int status = 0;
struct spk_synth *tmp;
mutex_lock(&spk_mutex); mutex_lock(&spk_mutex);
for (i = 0; i < MAXSYNTHS && synths[i]; i++)
/* synth_remove() is responsible for rotating the array down */ list_for_each_entry(tmp, &synths, node) {
if (in_synth == synths[i]) { if (tmp == in_synth) {
mutex_unlock(&spk_mutex); mutex_unlock(&spk_mutex);
return 0; return 0;
} }
if (i == MAXSYNTHS) {
pr_warn("Error: attempting to add a synth past end of array\n");
mutex_unlock(&spk_mutex);
return -1;
} }
if (in_synth->startup) if (in_synth->startup)
status = do_synth_init(in_synth); status = do_synth_init(in_synth);
if (!status) { if (!status)
synths[i++] = in_synth; list_add_tail(&in_synth->node, &synths);
synths[i] = NULL;
}
mutex_unlock(&spk_mutex); mutex_unlock(&spk_mutex);
return status; return status;
...@@ -479,17 +472,10 @@ EXPORT_SYMBOL_GPL(synth_add); ...@@ -479,17 +472,10 @@ EXPORT_SYMBOL_GPL(synth_add);
void synth_remove(struct spk_synth *in_synth) void synth_remove(struct spk_synth *in_synth)
{ {
int i;
mutex_lock(&spk_mutex); mutex_lock(&spk_mutex);
if (synth == in_synth) if (synth == in_synth)
synth_release(); synth_release();
for (i = 0; synths[i]; i++) { list_del(&in_synth->node);
if (in_synth == synths[i])
break;
}
for ( ; synths[i]; i++) /* compress table */
synths[i] = synths[i + 1];
module_status = 0; module_status = 0;
mutex_unlock(&spk_mutex); mutex_unlock(&spk_mutex);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment