aboutsummaryrefslogtreecommitdiff
path: root/util-linux/swaponoff.c
diff options
context:
space:
mode:
authorMatt Whitlock <busybox@mattwhitlock.name>2014-03-22 18:54:24 -0400
committerDenys Vlasenko <vda.linux@googlemail.com>2014-03-23 18:36:22 +0100
commitc3a27b0bfdf758f649caab2c474e690067af3402 (patch)
treebe6d8243a249e362f7a079a46fc817def5f1ed4d /util-linux/swaponoff.c
parent504fe45f35bab29752d39cc2d39d2e8c43fe6eac (diff)
downloadbusybox-w32-c3a27b0bfdf758f649caab2c474e690067af3402.tar.gz
busybox-w32-c3a27b0bfdf758f649caab2c474e690067af3402.tar.bz2
busybox-w32-c3a27b0bfdf758f649caab2c474e690067af3402.zip
avoid calling bb_strtou twice in MIN macro expansion
Also, the maximum allowable value of swap priority is technically SWAP_FLAG_PRIO_MASK >> SWAP_FLAG_PRIO_SHIFT. Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/swaponoff.c')
-rw-r--r--util-linux/swaponoff.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 3f223343e..bcceff772 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -100,12 +100,12 @@ static int do_em_all(void)
100 g_flags = 0; /* each swap space might have different flags */ 100 g_flags = 0; /* each swap space might have different flags */
101 p = hasmntopt(m, "pri"); 101 p = hasmntopt(m, "pri");
102 if (p) { 102 if (p) {
103 /* Max allowed 32767 (==SWAP_FLAG_PRIO_MASK) */ 103 /* Max allowed 32767 (== SWAP_FLAG_PRIO_MASK) */
104 unsigned int swap_prio = MIN(bb_strtou(p + 4 , NULL, 10), SWAP_FLAG_PRIO_MASK); 104 unsigned prio = bb_strtou(p + 4, NULL, 10);
105 /* We want to allow "NNNN,foo", thus errno == EINVAL is allowed too */ 105 /* We want to allow "NNNN,foo", thus errno == EINVAL is allowed too */
106 if (errno != ERANGE) { 106 if (errno != ERANGE) {
107 g_flags = SWAP_FLAG_PREFER | 107 g_flags = SWAP_FLAG_PREFER |
108 (swap_prio << SWAP_FLAG_PRIO_SHIFT); 108 MIN(prio, SWAP_FLAG_PRIO_MASK);
109 } 109 }
110 } 110 }
111#endif 111#endif
@@ -124,6 +124,9 @@ int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
124int swap_on_off_main(int argc UNUSED_PARAM, char **argv) 124int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
125{ 125{
126 int ret; 126 int ret;
127#if ENABLE_FEATURE_SWAPON_PRI
128 unsigned prio;
129#endif
127 130
128 INIT_G(); 131 INIT_G();
129 132
@@ -132,11 +135,11 @@ int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
132#else 135#else
133 if (applet_name[5] == 'n') 136 if (applet_name[5] == 'n')
134 opt_complementary = "p+"; 137 opt_complementary = "p+";
135 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags); 138 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &prio);
136 139
137 if (ret & 2) { // -p 140 if (ret & 2) { // -p
138 g_flags = SWAP_FLAG_PREFER | 141 g_flags = SWAP_FLAG_PREFER |
139 ((g_flags & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT); 142 MIN(prio, SWAP_FLAG_PRIO_MASK);
140 ret &= 1; 143 ret &= 1;
141 } 144 }
142#endif 145#endif