Skip to contentSkip to conversation

proper lseek locking in ALSA, take 3

PATCH In review Robert Love 2 participants 3 messages Feb 20, 2002 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proper lseek locking in ALSA, take 3

The attached patch implements proper locking in ALSA lseek methods. Note ALSA has 3 lseek implementations, but only:

sound/core/info.c :: snd_info_entry_llseek()

requires locking. I wrapped the function in the BKL. According to Jaroslav Kysela the gus_mem_proc method is only called from above. The third lseek, in hwdep.c, clearly doesn't need locking. Without this patch, the above lseek is not safe.

Patch is against 2.5.5, please apply.

Robert Love

sound/core/info.c +16 -6
diff -urN linux-2.5.5/sound/core/info.c linux/sound/core/info.c
@@ -29,6 +29,7 @@
 #include <sound/info.h>
 #include <sound/version.h>
 #include <linux/proc_fs.h>
+#include <linux/smp_lock.h>
 #ifdef CONFIG_DEVFS_FS
 #include <linux/devfs_fs_kernel.h>
 #endif
@@ -162,31 +163,40 @@
 {
 	snd_info_private_data_t *data;
 	struct snd_info_entry *entry;
+	int ret = -EINVAL;
 
 	data = snd_magic_cast(snd_info_private_data_t, file->private_data, return -ENXIO);
 	entry = data->entry;
+	lock_kernel();
 	switch (entry->content) {
 	case SNDRV_INFO_CONTENT_TEXT:
 		switch (orig) {
 		case 0:	/* SEEK_SET */
 			file->f_pos = offset;
-			return file->f_pos;
+			ret = file->f_pos;
+			goto out;
 		case 1:	/* SEEK_CUR */
 			file->f_pos += offset;
-			return file->f_pos;
+			ret = file->f_pos;
+			goto out;
 		case 2:	/* SEEK_END */
 		default:
-			return -EINVAL;
+			goto out;
 		}
 		break;
 	case SNDRV_INFO_CONTENT_DATA:
-		if (entry->c.ops->llseek)
-			return entry->c.ops->llseek(entry,
+		if (entry->c.ops->llseek) {
+			ret = entry->c.ops->llseek(entry,
 						    data->file_private_data,
 						    file, offset, orig);
+			goto out;
+		}
 		break;
 	}
-	return -ENXIO;
+	ret = -ENXIO;
+out:
+	unlock_kernel();
+	return ret;
 }
 
 static ssize_t snd_info_entry_read(struct file *file, char *buffer,

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#1 lore raw
Quoted 11 lines · Robert Love

The attached patch implements proper locking in ALSA lseek methods. Note ALSA has 3 lseek implementations, but only:

sound/core/info.c :: snd_info_entry_llseek()

requires locking. I wrapped the function in the BKL. According to Jaroslav Kysela the gus_mem_proc method is only called from above. The third lseek, in hwdep.c, clearly doesn't need locking. Without this patch, the above lseek is not safe.

Patch is against 2.5.5, please apply.

We have this patch already in our ALSA CVS tree, so it will be commited to Linus in next patch round. Thanks.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project http://www.alsa-project.org
SuSE Linux http://www.suse.com

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#2 lore raw
In reply to Robert Love
Quoted 11 lines · Robert Love

The attached patch implements proper locking in ALSA lseek methods. Note ALSA has 3 lseek implementations, but only:

sound/core/info.c :: snd_info_entry_llseek()

requires locking. I wrapped the function in the BKL. According to Jaroslav Kysela the gus_mem_proc method is only called from above. The third lseek, in hwdep.c, clearly doesn't need locking. Without this patch, the above lseek is not safe.

Patch is against 2.5.5, please apply.

We have this patch already in our ALSA CVS tree, so it will be commited to Linus in next patch round. Thanks.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project http://www.alsa-project.org
SuSE Linux http://www.suse.com