public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <rml@tech9.net>
To: torvalds@transmeta.com, davej@suse.de
Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org
Subject: [PATCH] proper lseek locking in ALSA, take 3
Date: 20 Feb 2002 14:20:40 -0500	[thread overview]
Message-ID: <1014232841.18361.37.camel@phantasy> (raw)

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	

diff -urN linux-2.5.5/sound/core/info.c linux/sound/core/info.c
--- linux-2.5.5/sound/core/info.c	Tue Feb 19 21:11:01 2002
+++ linux/sound/core/info.c	Tue Feb 19 21:50:18 2002
@@ -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,





             reply	other threads:[~2002-02-20 19:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-20 19:20 Robert Love [this message]
2002-02-20 20:04 ` [PATCH] proper lseek locking in ALSA, take 3 Jaroslav Kysela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1014232841.18361.37.camel@phantasy \
    --to=rml@tech9.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=davej@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox