Skip to contentSkip to conversation

tidy up chrdev_open

PATCH New Christoph Hellwig 1 participant 1 message Aug 11, 2008 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tidy up chrdev_open

Use a single goto label for chrdev_put + return error cases.

fs/char_dev.c +14 -7
Index: linux-2.6/fs/char_dev.c
===================================================================
@@ -389,15 +389,22 @@ static int chrdev_open(struct inode *ino
 	cdev_put(new);
 	if (ret)
 		return ret;
+
+	ret = -ENXIO;
 	filp->f_op = fops_get(p->ops);
-	if (!filp->f_op) {
-		cdev_put(p);
-		return -ENXIO;
-	}
-	if (filp->f_op->open)
+	if (!filp->f_op)
+		goto out_cdev_put;
+
+	if (filp->f_op->open) {
 		ret = filp->f_op->open(inode,filp);
-	if (ret)
-		cdev_put(p);
+		if (ret)
+			goto out_cdev_put;
+	}
+
+	return ret;
+
+ out_cdev_put:
+ 	cdev_put(p);
 	return ret;
 }