Skip to contentSkip to conversation

selftests: KVM: Replace optarg with arg in guest_modes_cmdline

PATCH Superseded [email protected] 2 participants 3 messages Feb 1, 2023 – Feb 2, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: KVM: Replace optarg with arg in guest_modes_cmdline

From: Shaoqin Huang <[email protected]>

The parameter arg in guest_modes_cmdline not being used now, and the optarg should be replaced with arg in guest_modes_cmdline.

---
 tools/testing/selftests/kvm/lib/guest_modes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/lib/guest_modes.c +1 -1
index 99a575bbbc52..1f2dca4520ab 100644
@@ -127,7 +127,7 @@ void guest_modes_cmdline(const char *arg)
 		mode_selected = true;
 	}
 
-	mode = strtoul(optarg, NULL, 10);
+	mode = strtoul(arg, NULL, 10);
 	TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode);
 	guest_modes[mode].enabled = true;
 }
Signature · 1 line
2.39.0
#1 lore raw
Quoted 16 lines · On Tue, Jan 31, 2023 at 9:46 PM <[email protected]> wrote:

From: Shaoqin Huang <[email protected]>

The parameter arg in guest_modes_cmdline not being used now, and the optarg should be replaced with arg in guest_modes_cmdline.

---
 tools/testing/selftests/kvm/lib/guest_modes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/lib/guest_modes.c +0 -0
index 99a575bbbc52..1f2dca4520ab 100644

tools/testing/selftests/kvm/lib/guest_modes.c void guest_modes_cmdline(const char *arg) · line 130

Quoted 5 lines
tools/testing/selftests/kvm/lib/guest_modes.c +1 -1
@@ -127,7 +127,7 @@ void guest_modes_cmdline(const char *arg)
                mode_selected = true;
        }
 
-       mode = strtoul(optarg, NULL, 10);
+       mode = strtoul(arg, NULL, 10);

While you are at it, can you also change strtoul to atoi_non_negative()?

An underflow negative number will print an error message with a wrong positive guest mode ID not passed by the user.

Quoted 6 lines
tools/testing/selftests/kvm/lib/guest_modes.c +0 -1
        TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode);
        guest_modes[mode].enabled = true;
 }
--

2.39.0

#2 lore raw
Quoted 19 lines · Vipin Sharma
Quoted 18 lines · On Tue, Jan 31, 2023 at 9:46 PM <[email protected]> wrote:

From: Shaoqin Huang <[email protected]>

The parameter arg in guest_modes_cmdline not being used now, and the optarg should be replaced with arg in guest_modes_cmdline.

---
  tools/testing/selftests/kvm/lib/guest_modes.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/lib/guest_modes.c +0 -0
index 99a575bbbc52..1f2dca4520ab 100644
@@ -127,7 +127,7 @@ void guest_modes_cmdline(const char *arg)
                 mode_selected = true;
         }
 
Quoted 6 lines

tools/testing/selftests/kvm/lib/guest_modes.c void guest_modes_cmdline(const char *arg) · line 130

Quoted 2 lines
tools/testing/selftests/kvm/lib/guest_modes.c +1 -1
-       mode = strtoul(optarg, NULL, 10);
+       mode = strtoul(arg, NULL, 10);

While you are at it, can you also change strtoul to atoi_non_negative()?

An underflow negative number will print an error message with a wrong positive guest mode ID not passed by the user.

Of course I can do that. Thanks for you Suggestion.

Thanks,

Shaoqin

Quoted 6 lines
Quoted 6 lines
tools/testing/selftests/kvm/lib/guest_modes.c +0 -1
         TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode);
         guest_modes[mode].enabled = true;
  }
--

2.39.0