@samitouri / QOSamiQemu / commits / f73440f536

system/vl: inline qemu_opts_parse_noisily() result checks

In qemu_init()'s option parsing switch, several cases assigned the return value of qemu_opts_parse_noisily() to the shared 'opts' variable solely to check for NULL, without using the pointer afterwards. Inline the call directly into the if-condition, matching the style already used by QEMU_OPTION_action. This affects the following options: -drive, -numa, -iscsi, -m, -mon, -chardev, -fsdev, -fwcfg Cases where the returned QemuOpts* is subsequently used (e.g. -acpitable, -smbios, -virtfs) are left unchanged. Signed-off-by: Bin Guo <guobin@linux.alibaba.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260429062004.36582-4-guobin@linux.alibaba.com> [PMD: Reduce @opts declaration to innermost block] Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Bin Guo committed Apr 29, 2026 at 14:20 UTC f73440f5361bf7c86694aa5c3f8c482d9e2b264a
1 file changed +16 -23
system/vl.c
+16 -23
@@ -2842,7 +2842,6 @@ void qmp_x_exit_preconfig(Error **errp)
2842
2843 void qemu_init(int argc, char **argv)
2844 {
2845 - QemuOpts *opts;
2845 QemuOpts *icount_opts = NULL, *accel_opts = NULL;
2846 QemuOptsList *olist;
2847 int optind;
@@ -2928,6 +2927,7 @@ void qemu_init(int argc, char **argv)
2927 drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2928 } else {
2929 const QEMUOption *popt;
2930 + QemuOpts *opts;
2931
2932 popt = lookup_opt(argc, argv, &optarg, &optind);
2933 if (!qemu_arch_available(popt->arch_mask)) {
@@ -2963,9 +2963,8 @@ void qemu_init(int argc, char **argv)
2963 break;
2964 }
2965 case QEMU_OPTION_drive:
2966 - opts = qemu_opts_parse_noisily(qemu_find_opts("drive"),
2967 - optarg, false);
2968 - if (opts == NULL) {
2966 + if (!qemu_opts_parse_noisily(qemu_find_opts("drive"),
2967 + optarg, false)) {
2968 exit(1);
2969 }
2970 break;
@@ -2990,9 +2989,8 @@ void qemu_init(int argc, char **argv)
2989 replay_add_blocker("-snapshot");
2990 break;
2991 case QEMU_OPTION_numa:
2993 - opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
2994 - optarg, true);
2995 - if (!opts) {
2992 + if (!qemu_opts_parse_noisily(qemu_find_opts("numa"),
2993 + optarg, true)) {
2994 exit(1);
2995 }
2996 break;
@@ -3051,9 +3049,8 @@ void qemu_init(int argc, char **argv)
3049 break;
3050 #ifdef CONFIG_LIBISCSI
3051 case QEMU_OPTION_iscsi:
3054 - opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3055 - optarg, false);
3056 - if (!opts) {
3052 + if (!qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3053 + optarg, false)) {
3054 exit(1);
3055 }
3056 break;
@@ -3106,8 +3103,8 @@ void qemu_init(int argc, char **argv)
3103 exit(0);
3104 break;
3105 case QEMU_OPTION_m:
3109 - opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), optarg, true);
3110 - if (opts == NULL) {
3106 + if (!qemu_opts_parse_noisily(qemu_find_opts("memory"),
3107 + optarg, true)) {
3108 exit(1);
3109 }
3110 break;
@@ -3228,17 +3225,15 @@ void qemu_init(int argc, char **argv)
3225 default_monitor = 0;
3226 break;
3227 case QEMU_OPTION_mon:
3231 - opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
3232 - true);
3233 - if (!opts) {
3228 + if (!qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
3229 + true)) {
3230 exit(1);
3231 }
3232 default_monitor = 0;
3233 break;
3234 case QEMU_OPTION_chardev:
3239 - opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3240 - optarg, true);
3241 - if (!opts) {
3235 + if (!qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3236 + optarg, true)) {
3237 exit(1);
3238 }
3239 break;
@@ -3248,8 +3243,7 @@ void qemu_init(int argc, char **argv)
3243 error_report("fsdev support is disabled");
3244 exit(1);
3245 }
3251 - opts = qemu_opts_parse_noisily(olist, optarg, true);
3252 - if (!opts) {
3246 + if (!qemu_opts_parse_noisily(olist, optarg, true)) {
3247 exit(1);
3248 }
3249 break;
@@ -3388,9 +3382,8 @@ void qemu_init(int argc, char **argv)
3382 smbios_entry_add(opts, &error_fatal);
3383 break;
3384 case QEMU_OPTION_fwcfg:
3391 - opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3392 - optarg, true);
3393 - if (opts == NULL) {
3385 + if (!qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3386 + optarg, true)) {
3387 exit(1);
3388 }
3389 break;