lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Wed,  9 Jan 2013 10:17:48 +0100
From:	Michal Nazarewicz <mpn@...gle.com>
To:	Felipe Balbi <balbi@...com>, linux-usb@...r.kernel.org
Cc:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Benoit Goby <benoit@...roid.com>, linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] usb: gadget: FunctionFS: Refactor option parsing

From: Michal Nazarewicz <mina86@...a86.com>

The use of memcmp() is clever and all and maybe even it makes parsing a
bit faster (since only options with given length need to be checked) but
option parsing is hardly a critical path and the additional code
complexity is not worth it.

Signed-off-by: Michal Nazarewicz <mina86@...a86.com>
---
 drivers/usb/gadget/f_fs.c |   55 ++++++++++++++------------------------------
 1 files changed, 18 insertions(+), 37 deletions(-)

diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 38388d7..6a7e187 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -1126,45 +1126,26 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
 		}
 
 		/* Interpret option */
-		switch (eq - opts) {
-		case 5:
-			if (!memcmp(opts, "rmode", 5))
-				data->root_mode  = (value & 0555) | S_IFDIR;
-			else if (!memcmp(opts, "fmode", 5))
-				data->perms.mode = (value & 0666) | S_IFREG;
-			else
-				goto invalid;
-			break;
-
-		case 4:
-			if (!memcmp(opts, "mode", 4)) {
-				data->root_mode  = (value & 0555) | S_IFDIR;
-				data->perms.mode = (value & 0666) | S_IFREG;
-			} else {
-				goto invalid;
+		if (!strcmp(opts, "rmode")) {
+			data->root_mode  = (value & 0555) | S_IFDIR;
+		} else if (!strcmp(opts, "fmode")) {
+			data->perms.mode = (value & 0666) | S_IFREG;
+		} else if (!strcmp(opts, "mode")) {
+			data->root_mode  = (value & 0555) | S_IFDIR;
+			data->perms.mode = (value & 0666) | S_IFREG;
+		} else if (!strcmp(opts, "uid")) {
+			data->perms.uid = make_kuid(current_user_ns(), value);
+			if (!uid_valid(data->perms.uid)) {
+				pr_err("%s: unmapped value: %lu\n", opts, value);
+				return -EINVAL;
 			}
-			break;
-
-		case 3:
-			if (!memcmp(opts, "uid", 3)) {
-				data->perms.uid = make_kuid(current_user_ns(), value);
-				if (!uid_valid(data->perms.uid)) {
-					pr_err("%s: unmapped value: %lu\n", opts, value);
-					return -EINVAL;
-				}
-			} else if (!memcmp(opts, "gid", 3)) {
-				data->perms.gid = make_kgid(current_user_ns(), value);
-				if (!gid_valid(data->perms.gid)) {
-					pr_err("%s: unmapped value: %lu\n", opts, value);
-					return -EINVAL;
-				}
-			} else {
-				goto invalid;
+		} else if (!strcmp(opts, "gid")) {
+			data->perms.gid = make_kgid(current_user_ns(), value);
+			if (!gid_valid(data->perms.gid)) {
+				pr_err("%s: unmapped value: %lu\n", opts, value);
+				return -EINVAL;
 			}
-			break;
-
-		default:
-invalid:
+		} else {
 			pr_err("%s: invalid option\n", opts);
 			return -EINVAL;
 		}
-- 
1.7.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ