diff options
author | Takashi Iwai <tiwai@suse.de> | 2010-04-13 11:39:47 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2010-04-13 12:01:20 +0200 |
commit | 73029e0ff18dfac8a1aab1dc188e1e150bbe3adc (patch) | |
tree | 680d00a2e5bc124b5b1b642508a47a90e3c47b3f /sound/core/info.c | |
parent | d97e1b78239c7e7e441088e0b644bd3b076002e6 (diff) | |
download | blackbird-op-linux-73029e0ff18dfac8a1aab1dc188e1e150bbe3adc.tar.gz blackbird-op-linux-73029e0ff18dfac8a1aab1dc188e1e150bbe3adc.zip |
ALSA: info - Implement common llseek for binary mode
The llseek implementation is identical for existing driver implementations,
so let's merge to the common layer. The same code for the text proc file
can be used even for the binary proc file.
The driver can provide its own llseek method if needed. Then the common
code will be skipped.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core/info.c')
-rw-r--r-- | sound/core/info.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/sound/core/info.c b/sound/core/info.c index f90a6fd43fb4..b70564ed8b37 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -164,39 +164,43 @@ static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig) { struct snd_info_private_data *data; struct snd_info_entry *entry; - loff_t ret; + loff_t ret = -EINVAL, size; data = file->private_data; entry = data->entry; mutex_lock(&entry->access); - switch (entry->content) { - case SNDRV_INFO_CONTENT_TEXT: - switch (orig) { - case SEEK_SET: - file->f_pos = offset; - ret = file->f_pos; - goto out; - case SEEK_CUR: - file->f_pos += offset; - ret = file->f_pos; - goto out; - case SEEK_END: - default: - ret = -EINVAL; - goto out; - } + if (entry->content == SNDRV_INFO_CONTENT_DATA && + entry->c.ops->llseek) { + offset = entry->c.ops->llseek(entry, + data->file_private_data, + file, offset, orig); + goto out; + } + if (entry->content == SNDRV_INFO_CONTENT_DATA) + size = entry->size; + else + size = 0; + switch (orig) { + case SEEK_SET: break; - case SNDRV_INFO_CONTENT_DATA: - if (entry->c.ops->llseek) { - ret = entry->c.ops->llseek(entry, - data->file_private_data, - file, offset, orig); + case SEEK_CUR: + offset += file->f_pos; + break; + case SEEK_END: + if (!size) goto out; - } + offset += size; break; - } - ret = -ENXIO; -out: + default: + goto out; + } + if (offset < 0) + goto out; + if (size && offset > size) + offset = size; + file->f_pos = offset; + ret = offset; + out: mutex_unlock(&entry->access); return ret; } |