LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Nikanth Karthikesan <knikanth@suse.de>
To: grant@torque.net, tim@cyberelk.net
Cc: Christoph Hellwig <hch@infradead.org>,
	Valdis.Kletnieks@vt.edu, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] Change paride driver to use unlocked_ioctl instead of ioctl
Date: Thu, 10 Jan 2008 14:25:47 +0530	[thread overview]
Message-ID: <1199955347.6203.6.camel@nikanth-laptop.blr.novell.com> (raw)
In-Reply-To: <4784D3E0.BANGALORE.BLR.100.174746A.1.EABB.1@1:7.BANGALORE.BLR.100.0.1.0.1@16>

On Wed, 2008-01-09 at 03:23 -0500, Valdis.Kletnieks@vt.edu wrote:
> On Wed, 09 Jan 2008 08:06:20 GMT, Christoph Hellwig said:
> 
> > It's generally considered good style to only have as few as possible
> > return values.  And this is especially important when returning from
> > a section that's under a lock.  So in this case it would be much better
> > if you changes this function to have a local 'int error' variable
> > and then just do
> > 
> > 	error = -EFOO;
> > 	goto out_unlock;

agreed. resending the patch


> I think Christoph meant to say "as few as possible return locations".  One
> should write the code to have as many different return values as are
> meaningful, but return them from as few places as possible - which is what the
> "assign error and goto end" paradigm does...
> 

Is this following coding style, fine?

The ioctl handler is called with the BKL held. Registering
unlocked_ioctl handler instead of registering ioctl handler.

Signed-off-by: Nikanth Karthikesan <knikanth@suse.de>

---

diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index b91accf..17f32f0 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -146,6 +146,7 @@ static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
 #include <linux/mtio.h>
 #include <linux/device.h>
 #include <linux/sched.h>	/* current, TASK_*, schedule_timeout() */
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 
@@ -189,8 +190,8 @@ module_param_array(drive3, int, NULL, 0);
 #define ATAPI_LOG_SENSE		0x4d
 
 static int pt_open(struct inode *inode, struct file *file);
-static int pt_ioctl(struct inode *inode, struct file *file,
-		    unsigned int cmd, unsigned long arg);
+static long pt_ioctl(struct file *file, unsigned int cmd,
+		unsigned long arg);
 static int pt_release(struct inode *inode, struct file *file);
 static ssize_t pt_read(struct file *filp, char __user *buf,
 		       size_t count, loff_t * ppos);
@@ -236,7 +237,7 @@ static const struct file_operations pt_fops = {
 	.owner = THIS_MODULE,
 	.read = pt_read,
 	.write = pt_write,
-	.ioctl = pt_ioctl,
+	.unlocked_ioctl = pt_ioctl,
 	.open = pt_open,
 	.release = pt_release,
 };
@@ -685,39 +686,47 @@ out:
 	return err;
 }
 
-static int pt_ioctl(struct inode *inode, struct file *file,
-	 unsigned int cmd, unsigned long arg)
+static long pt_ioctl(struct file *file, unsigned int cmd,
+		unsigned long arg)
 {
 	struct pt_unit *tape = file->private_data;
 	struct mtop __user *p = (void __user *)arg;
 	struct mtop mtop;
+	long err = 0;
+
+	lock_kernel();
 
 	switch (cmd) {
 	case MTIOCTOP:
-		if (copy_from_user(&mtop, p, sizeof(struct mtop)))
-			return -EFAULT;
+		if (copy_from_user(&mtop, p, sizeof(struct mtop))) {
+			err = -EFAULT;
+			break;
+		}
 
 		switch (mtop.mt_op) {
 
 		case MTREW:
 			pt_rewind(tape);
-			return 0;
+			break;
 
 		case MTWEOF:
 			pt_write_fm(tape);
-			return 0;
+			break;
 
 		default:
 			printk("%s: Unimplemented mt_op %d\n", tape->name,
 			       mtop.mt_op);
-			return -EINVAL;
+			err = -EINVAL;
 		}
+		break;
 
 	default:
 		printk("%s: Unimplemented ioctl 0x%x\n", tape->name, cmd);
-		return -EINVAL;
-
+		err = -EINVAL;
+		
 	}
+	unlock_kernel();
+	return err;
 }
 
 static int





  parent reply	other threads:[~2008-01-09  8:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-10  6:14 Nikanth Karthikesan
2008-01-09  8:06 ` Christoph Hellwig
2008-01-09  8:23   ` Valdis.Kletnieks
     [not found]   ` <4784D3E0.BANGALORE.BLR.100.174746A.1.EABB.1@1:7.BANGALORE.BLR.100.0.1.0.1@16>
2008-01-10  8:55     ` Nikanth Karthikesan [this message]
2008-01-09 12:14       ` Jan Engelhardt
2008-01-09 12:20         ` Christoph Hellwig
2008-01-10  7:23 ` Nikanth Karthikesan
2008-01-09 12:33   ` Matthew Wilcox
2008-01-09 13:26     ` Jiri Kosina
2008-01-09 16:56       ` Alan Cox
2008-01-10 15:01         ` Jiri Kosina
2008-01-10 20:58           ` Alan Cox
     [not found]         ` <478681FE.BANGALORE.BLR.100.174746A.1.ECB1.1@1:7.BANGALORE.BLR.100.0.1.0.1@16>
2008-01-10 15:31           ` Nikanth Karthikesan
2008-01-10 15:50             ` Matthew Wilcox
     [not found]       ` <47854BF3.BANGALORE.BLR.100.174746A.1.EB89.1@1:7.BANGALORE.BLR.100.0.1.0.1@16>
2008-01-10  5:29         ` Nikanth Karthikesan

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=1199955347.6203.6.camel@nikanth-laptop.blr.novell.com \
    --to=knikanth@suse.de \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=grant@torque.net \
    --cc=hch@infradead.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tim@cyberelk.net \
    --subject='Re: [PATCH] Change paride driver to use unlocked_ioctl instead of ioctl' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).