aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox/2003-modinfo-fix-argument-parsing-and-printing-of-firmwar.patch
blob: 434759d13099551e59c43d40563c0fdec4ab7741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From a19967762fa8b8e6da7fcbcf7447131f33b0135b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Wed, 28 Oct 2015 10:20:57 +0200
Subject: [PATCH 2003/2003] modinfo: fix argument parsing, and printing of
 firmware
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

getopt was missing a short option for 'firmware', thus the -F option
for specific keyword was flagged as last OPT_TAGS entry. This caused
"-F firmware" to print twice the firmware fields (once due to incorrectly
set OPT_TAGS and once for OPT_F) and incorrectly with the fieldname
prefix.

This adds -f as shortcut for "-F firmware" so that OPT_TAGS and OPT_F
are now set properly by getopt32(). This allows removing the incorrect
and unneeded OPT_F setting based on the keyword field.

function                                             old     new   delta
modinfo_main                                         438     430      -8
modinfo                                              457     438     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-27)             Total: -27 bytes
   text	   data	    bss	    dec	    hex	filename
 787574	  15136	   3656	 806366	  c4dde	busybox_old
 787547	  15136	   3656	 806339	  c4dc3	busybox_unstripped

Fixes: 772f17a843 "modinfo: match more standard module fields and fix version field"
Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Cc: Tanguy Pruvot <tanguy.pruvot@gmail.com>
---
 modutils/modinfo.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/modutils/modinfo.c b/modutils/modinfo.c
index 8e74b64..e2c9df3 100644
--- a/modutils/modinfo.c
+++ b/modutils/modinfo.c
@@ -31,7 +31,7 @@ enum {
 
 struct modinfo_env {
 	char *field;
-	int tags;
+	unsigned tags;
 };
 
 static void display(const char *data, const char *pattern, int flag)
@@ -62,11 +62,13 @@ static void modinfo(const char *path, const char *version,
 		"firmware",
 	};
 	size_t len;
-	int j;
+	unsigned j;
 	char *ptr, *the_module;
 	const char *field = env->field;
-	int tags = env->tags;
+	unsigned tags = env->tags;
 
+	if (!tags)
+		tags = OPT_TAGS;
 	if (tags & 1) { /* filename */
 		display(path, shortcuts[0], 1 != tags);
 	}
@@ -84,8 +86,6 @@ static void modinfo(const char *path, const char *version,
 			return;
 	}
 
-	if (field)
-		tags |= OPT_F;
 	for (j = 1; (1<<j) & (OPT_TAGS + OPT_F); j++) {
 		const char *pattern;
 
@@ -141,8 +141,8 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
 
 	env.field = NULL;
 	opt_complementary = "-1"; /* minimum one param */
-	opts = getopt32(argv, "nladvAsDumpF:0", &env.field);
-	env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS;
+	opts = getopt32(argv, "nladvAsDumpfF:0", &env.field);
+	env.tags = opts & (OPT_TAGS + OPT_F);
 	argv += optind;
 
 	uname(&uts);
-- 
2.6.1