Commit 40fe4f89 authored by Ben Hutchings's avatar Ben Hutchings Committed by Greg Kroah-Hartman

staging: speakup_soft: Fix reading of init string

softsynth_read() reads a character at a time from the init string;
when it finds the null terminator it sets the initialized flag but
then repeats the last character.

Additionally, if the read() buffer is not big enough for the init
string, the next read() will start reading from the beginning again.
So the caller may never progress to reading anything else.

Replace the simple initialized flag with the current position in
the init string, carried over between calls.  Switch to reading
real data once this reaches the null terminator.

(This assumes that the length of the init string can't change, which
seems to be the case.  Really, the string and position belong together
in a per-file private struct.)
Tested-by: default avatarSamuel Thibault <sthibault@debian.org>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0c4a9f6e
...@@ -40,7 +40,7 @@ static int softsynth_is_alive(struct spk_synth *synth); ...@@ -40,7 +40,7 @@ static int softsynth_is_alive(struct spk_synth *synth);
static unsigned char get_index(void); static unsigned char get_index(void);
static struct miscdevice synth_device; static struct miscdevice synth_device;
static int initialized; static int init_pos;
static int misc_registered; static int misc_registered;
static struct var_t vars[] = { static struct var_t vars[] = {
...@@ -194,7 +194,7 @@ static int softsynth_close(struct inode *inode, struct file *fp) ...@@ -194,7 +194,7 @@ static int softsynth_close(struct inode *inode, struct file *fp)
unsigned long flags; unsigned long flags;
spk_lock(flags); spk_lock(flags);
synth_soft.alive = 0; synth_soft.alive = 0;
initialized = 0; init_pos = 0;
spk_unlock(flags); spk_unlock(flags);
/* Make sure we let applications go before leaving */ /* Make sure we let applications go before leaving */
speakup_start_ttys(); speakup_start_ttys();
...@@ -239,13 +239,8 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count, ...@@ -239,13 +239,8 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
ch = '\x18'; ch = '\x18';
} else if (synth_buffer_empty()) { } else if (synth_buffer_empty()) {
break; break;
} else if (!initialized) { } else if (init[init_pos]) {
if (*init) { ch = init[init_pos++];
ch = *init;
init++;
} else {
initialized = 1;
}
} else { } else {
ch = synth_buffer_getc(); ch = synth_buffer_getc();
} }
......
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