Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1460911

[PATCH 15/18] autofs: Add autofs_dev_ioctl_version() for AUTOFS_DEV_IOCTL_VERSION_CMD

From Ian Kent <raven@themaw.net>
Newsgroups linux.kernel
Subject [PATCH 15/18] autofs: Add autofs_dev_ioctl_version() for AUTOFS_DEV_IOCTL_VERSION_CMD
Date 2016-08-12 04:50 +0200
Message-ID <s5aHM-4bR-25@gated-at.bofh.it> (permalink)
References <s5aHL-4bR-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>

No functional changes, based on the following justification.

1. Make the code more consistent using the ioctl vector _ioctls[],
   rather than assigning NULL only for this ioctl command.
2. Remove goto done; for better maintainability in the long run.
3. The existing code is based on the fact that validate_dev_ioctl()
   sets ioctl version for any command, but AUTOFS_DEV_IOCTL_VERSION_CMD
   should explicitly set it regardless of the default behavior.

Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Signed-off-by: Ian Kent <ikent@redhat.com>
---
 fs/autofs4/dev-ioctl.c |   25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index 13e7517..7289216 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -172,6 +172,17 @@ static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f)
 	return sbi;
 }
 
+/* Return autofs dev ioctl version */
+static int autofs_dev_ioctl_version(struct file *fp,
+				    struct autofs_sb_info *sbi,
+				    struct autofs_dev_ioctl *param)
+{
+	/* This should have already been set. */
+	param->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
+	param->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
+	return 0;
+}
+
 /* Return autofs module protocol version */
 static int autofs_dev_ioctl_protover(struct file *fp,
 				     struct autofs_sb_info *sbi,
@@ -590,7 +601,8 @@ static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
 		int cmd;
 		ioctl_fn fn;
 	} _ioctls[] = {
-		{cmd_idx(AUTOFS_DEV_IOCTL_VERSION_CMD), NULL},
+		{cmd_idx(AUTOFS_DEV_IOCTL_VERSION_CMD),
+			 autofs_dev_ioctl_version},
 		{cmd_idx(AUTOFS_DEV_IOCTL_PROTOVER_CMD),
 			 autofs_dev_ioctl_protover},
 		{cmd_idx(AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD),
@@ -655,10 +667,6 @@ static int _autofs_dev_ioctl(unsigned int command,
 	if (err)
 		goto out;
 
-	/* The validate routine above always sets the version */
-	if (cmd == AUTOFS_DEV_IOCTL_VERSION_CMD)
-		goto done;
-
 	fn = lookup_dev_ioctl(cmd);
 	if (!fn) {
 		pr_warn("unknown command 0x%08x\n", command);
@@ -672,9 +680,11 @@ static int _autofs_dev_ioctl(unsigned int command,
 	/*
 	 * For obvious reasons the openmount can't have a file
 	 * descriptor yet. We don't take a reference to the
-	 * file during close to allow for immediate release.
+	 * file during close to allow for immediate release,
+	 * and the same for retrieving ioctl version.
 	 */
-	if (cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
+	if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD &&
+	    cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
 	    cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) {
 		fp = fget(param->ioctlfd);
 		if (!fp) {
@@ -707,7 +717,6 @@ cont:
 
 	if (fp)
 		fput(fp);
-done:
 	if (err >= 0 && copy_to_user(user, param, AUTOFS_DEV_IOCTL_SIZE))
 		err = -EFAULT;
 out:

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 01/18] autofs: Fix typos in  Documentation/filesystems/autofs4.txt Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 04/18] autofs - fix autofs4_fill_super() error exit handling Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 15/18] autofs: Add autofs_dev_ioctl_version() for  AUTOFS_DEV_IOCTL_VERSION_CMD Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 13/18] autofs: Fix pr_debug() message Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 18/18] autofs4 - move linux/auto_dev-ioctl.h to uapi/linux Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 05/18] autofs: Add WARN_ON(1) for non dir/link inode case Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 06/18] autofs - remove ino free in autofs4_dir_symlink() Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 11/18] autofs: Fix Documentation regarding devid on ioctl Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 16/18] autofs: Fix print format for ioctl warning message Ian Kent <raven@themaw.net> - 2016-08-12 04:50 +0200
  [PATCH 09/18] autofs: Don't fail to free_dev_ioctl(param) Ian Kent <raven@themaw.net> - 2016-08-12 05:00 +0200
  [PATCH 14/18] autofs - fix dev ioctl number range check Ian Kent <raven@themaw.net> - 2016-08-12 05:00 +0200
  [PATCH 12/18] autofs: Update struct autofs_dev_ioctl in  Documentation Ian Kent <raven@themaw.net> - 2016-08-12 05:00 +0200
  [PATCH 02/18] autofs: Drop unnecessary extern in autofs_i.h Ian Kent <raven@themaw.net> - 2016-08-12 05:00 +0200

csiph-web