Skip to contentSkip to conversation

vl.c: use 'break' instead of 'continue' in configure_accelerator()

PATCH In review Chen Gang 7 participants 41 messages Mar 27, 2014 – Apr 16, 2014

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 vl.c: use 'break' instead of 'continue' in configure_accelerator()

At present, each 'opt_name' of 'accel_list' is uniq with each other, so 'buf' can only match one 'opt_name'.

When drop into the matching code block, can 'break' outside related 'for' looping after finish processing it (just like the other 'break' within the matching block).

After print "... not support for this target", it can avoid to print "... accelerator does not exist".

---
 vl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +1 -1
index 842e897..b4f98fa 100644
@@ -2709,7 +2709,7 @@ static int configure_accelerator(QEMUMachine *machine)
                 if (!accel_list[i].available()) {
                     printf("%s not supported for this target\n",
                            accel_list[i].name);
-                    continue;
+                    break;
                 }
                 *(accel_list[i].allowed) = true;
                 ret = accel_list[i].init(machine);
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 9 lines · Chen Gang

At present, each 'opt_name' of 'accel_list' is uniq with each other, so 'buf' can only match one 'opt_name'.

When drop into the matching code block, can 'break' outside related 'for' looping after finish processing it (just like the other 'break' within the matching block).

After print "... not support for this target", it can avoid to print "... accelerator does not exist".

Hi,
Thanks for the patch!

I would re-write
1. The commit subject to:
Fix wrong warning on configure_accelerator
2. The commit message to:
No need to continue to iterate over the accelerators list after a match is found, even if it is not supported.

Quoted 12 lines
---
 vl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +0 -0
index 842e897..b4f98fa 100644

vl.c static int configure_accelerator(QEMUMachine *machine) · line 2712

Quoted 5 lines
vl.c +1 -1
@@ -2709,7 +2709,7 @@ static int configure_accelerator(QEMUMachine *machine)
                 if (!accel_list[i].available()) {
                     printf("%s not supported for this target\n",
                            accel_list[i].name);
-                    continue;
+                    break;

Seems like the right thing to do.

Thanks,
Marcel

Quoted 3 lines
vl.c +0 -0
                 }
                 *(accel_list[i].allowed) = true;
                 ret = accel_list[i].init(machine);
#3 lore raw
In reply to Chen Gang
Quoted 21 lines · Chen Gang

At present, each 'opt_name' of 'accel_list' is uniq with each other, so 'buf' can only match one 'opt_name'.

When drop into the matching code block, can 'break' outside related 'for' looping after finish processing it (just like the other 'break' within the matching block).

After print "... not support for this target", it can avoid to print "... accelerator does not exist".

---
 vl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +0 -0
index 842e897..b4f98fa 100644

vl.c static int configure_accelerator(QEMUMachine *machine) · line 2715

Quoted 8 lines
vl.c +1 -1
@@ -2709,7 +2709,7 @@ static int configure_accelerator(QEMUMachine *machine)
                 if (!accel_list[i].available()) {
                     printf("%s not supported for this target\n",
                            accel_list[i].name);
-                    continue;
+                    break;
                 }
                 *(accel_list[i].allowed) = true;
                 ret = accel_list[i].init(machine);

Works, because the opt_name in accel_list[] are distinct, as you explained in your commit message.

Apropos commit message. You first explain what you do, and only then state the problem you're trying to solve. That's backwards. Start with the problem. Only then explain your solution, if it needs explaining. This one, I think, doesn't.

Suggested commit message:

vl: Report accelerator not supported for target more nicely

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

$ qemu-system-arm -machine none,accel=kvm
KVM not supported for this target
"kvm" accelerator does not exist.
No accelerator found!

Suppress it.

author
#2 lore raw
In reply to Marcel Apfelbaum
Quoted 13 lines · Marcel Apfelbaum
Quoted 9 lines · Chen Gang

At present, each 'opt_name' of 'accel_list' is uniq with each other, so 'buf' can only match one 'opt_name'.

When drop into the matching code block, can 'break' outside related 'for' looping after finish processing it (just like the other 'break' within the matching block).

After print "... not support for this target", it can avoid to print "... accelerator does not exist".

Hi,
Thanks for the patch!

Quoted 7 lines

I would re-write
1. The commit subject to:
Fix wrong warning on configure_accelerator
2. The commit message to:
No need to continue to iterate over the accelerators list after a match is found, even if it is not supported.

OK, thank you for your work (re-write it before commit it).

Next I will/should notice about it. :-)

Quoted 28 lines
Quoted 12 lines
---
 vl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +0 -0
index 842e897..b4f98fa 100644

vl.c static int configure_accelerator(QEMUMachine *machine) · line 2712

Quoted 5 lines
vl.c +1 -1
@@ -2709,7 +2709,7 @@ static int configure_accelerator(QEMUMachine *machine)
                 if (!accel_list[i].available()) {
                     printf("%s not supported for this target\n",
                            accel_list[i].name);
-                    continue;
+                    break;

Seems like the right thing to do.

Thanks,
Marcel

Quoted 3 lines
vl.c +0 -0
                 }
                 *(accel_list[i].allowed) = true;
                 ret = accel_list[i].init(machine);
Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#4 lore raw
In reply to Markus Armbruster
Quoted 47 lines · Markus Armbruster
Quoted 21 lines · Chen Gang

At present, each 'opt_name' of 'accel_list' is uniq with each other, so 'buf' can only match one 'opt_name'.

When drop into the matching code block, can 'break' outside related 'for' looping after finish processing it (just like the other 'break' within the matching block).

After print "... not support for this target", it can avoid to print "... accelerator does not exist".

---
 vl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +0 -0
index 842e897..b4f98fa 100644

vl.c static int configure_accelerator(QEMUMachine *machine) · line 2715

Quoted 8 lines
vl.c +1 -1
@@ -2709,7 +2709,7 @@ static int configure_accelerator(QEMUMachine *machine)
                 if (!accel_list[i].available()) {
                     printf("%s not supported for this target\n",
                            accel_list[i].name);
-                    continue;
+                    break;
                 }
                 *(accel_list[i].allowed) = true;
                 ret = accel_list[i].init(machine);

Works, because the opt_name in accel_list[] are distinct, as you explained in your commit message.

Apropos commit message. You first explain what you do, and only then state the problem you're trying to solve. That's backwards. Start with the problem. Only then explain your solution, if it needs explaining. This one, I think, doesn't.

Suggested commit message:

vl: Report accelerator not supported for target more nicely

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

Quoted 7 lines

$ qemu-system-arm -machine none,accel=kvm
KVM not supported for this target
"kvm" accelerator does not exist.
No accelerator found!

Suppress it.

Thank you for your details, that sounds reasonable to me.

Next, I will/should notice start with the issue, and then explain the solution.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#5 lore raw

Hello Maintainers:

If it is necessary to send patch v2 by me, please let me know, I will/should send.

Thanks.

Quoted 66 lines · Chen Gang
Quoted 47 lines · Markus Armbruster
Quoted 21 lines · Chen Gang

At present, each 'opt_name' of 'accel_list' is uniq with each other, so 'buf' can only match one 'opt_name'.

When drop into the matching code block, can 'break' outside related 'for' looping after finish processing it (just like the other 'break' within the matching block).

After print "... not support for this target", it can avoid to print "... accelerator does not exist".

---
 vl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +0 -0
index 842e897..b4f98fa 100644

vl.c static int configure_accelerator(QEMUMachine *machine) · line 2715

Quoted 8 lines
vl.c +1 -1
@@ -2709,7 +2709,7 @@ static int configure_accelerator(QEMUMachine *machine)
                 if (!accel_list[i].available()) {
                     printf("%s not supported for this target\n",
                            accel_list[i].name);
-                    continue;
+                    break;
                 }
                 *(accel_list[i].allowed) = true;
                 ret = accel_list[i].init(machine);

Works, because the opt_name in accel_list[] are distinct, as you explained in your commit message.

Apropos commit message. You first explain what you do, and only then state the problem you're trying to solve. That's backwards. Start with the problem. Only then explain your solution, if it needs explaining. This one, I think, doesn't.

Suggested commit message:

vl: Report accelerator not supported for target more nicely

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

Quoted 7 lines

$ qemu-system-arm -machine none,accel=kvm
KVM not supported for this target
"kvm" accelerator does not exist.
No accelerator found!

Suppress it.

Thank you for your details, that sounds reasonable to me.

Next, I will/should notice start with the issue, and then explain the solution.

Thanks.

Signature · 3 lines
Chen Gang

Open, share and attitude like air, water and life which God blessed
#6 lore raw
Quoted 4 lines · Chen Gang

Hello Maintainers:

If it is necessary to send patch v2 by me, please let me know, I will/should send.

Not a maintainer, but if you send a v2 with an improved commit message, I'll R-by it, which can only help getting it merged.

author
#7 lore raw
Quoted 10 lines · Markus Armbruster
Quoted 4 lines · Chen Gang

Hello Maintainers:

If it is necessary to send patch v2 by me, please let me know, I will/should send.

Not a maintainer, but if you send a v2 with an improved commit message, I'll R-by it, which can only help getting it merged.

I guess your meaning is "not quite necessary" (for me, minor useful patches almost like spam). So if sending patch v2 is really required, please let me know, thanks.

At present, I am just trying to know about Qemu by reading code (start from 'vl.c' and continue), if I can find related issue, I will try to fix it and send the related patch for it.

Welcome any additional suggestions and completions for what I am doing.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#8 lore raw
Quoted 8 lines · Chen Gang
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Chen Gang

Hello Maintainers:

If it is necessary to send patch v2 by me, please let me know, I will/should send.

Quoted 7 lines
Quoted 3 lines

Not a maintainer, but if you send a v2 with an improved commit message, I'll R-by it, which can only help getting it merged.

I guess your meaning is "not quite necessary" (for me, minor useful patches almost like spam). So if sending patch v2 is really required, please let me know, thanks.

Basically, asking a maintainer to make changes to a patch as they apply it is asking them to do extra work beyond what they would normally do. Sometimes people will agree to do this, but in general it's better just to send a fixed version of the patch yourself.

(I've cc'd qemu-trivial since that's probably the best tree to take this patch.)

thanks
-- PMM

author
#9 lore raw
Quoted 17 lines · Peter Maydell
Quoted 8 lines · Chen Gang
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Chen Gang

Hello Maintainers:

If it is necessary to send patch v2 by me, please let me know, I will/should send.

Quoted 7 lines
Quoted 3 lines

Not a maintainer, but if you send a v2 with an improved commit message, I'll R-by it, which can only help getting it merged.

I guess your meaning is "not quite necessary" (for me, minor useful patches almost like spam). So if sending patch v2 is really required, please let me know, thanks.

Quoted 9 lines

Basically, asking a maintainer to make changes to a patch as they apply it is asking them to do extra work beyond what they would normally do. Sometimes people will agree to do this, but in general it's better just to send a fixed version of the patch yourself.

(I've cc'd qemu-trivial since that's probably the best tree to take this patch.)

OK, thanks. And excuse me, my English is not quite well, I guess, I misunderstood the original replier's meaning. I will/should send patch v2 for it within this week (2014-04-06).

Next, when I send trivial patches, I will/should cc to qemu-trivial. I guess, most of my future patches will be trivial patches (and for me, trivial != minor).

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#10 lore raw
Quoted 3 lines · Chen Gang

Next, when I send trivial patches, I will/should cc to qemu-trivial. I guess, most of my future patches will be trivial patches (and for me, trivial != minor).

We describe on the wiki what we mean by 'trivial':
http://wiki.qemu.org/Contribute/TrivialPatches

thanks
-- PMM

author
#11 lore raw
Quoted 8 lines · Peter Maydell
Quoted 3 lines · Chen Gang

Next, when I send trivial patches, I will/should cc to qemu-trivial. I guess, most of my future patches will be trivial patches (and for me, trivial != minor).

We describe on the wiki what we mean by 'trivial':
http://wiki.qemu.org/Contribute/TrivialPatches

Thank you for your information.

Next, when I send trivial patches, I will only send to qemu-trivial (not send/cc to qemu-devel again), that will be more efficient. :-)

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#12 lore raw
Quoted 2 lines · Chen Gang

Next, when I send trivial patches, I will only send to qemu-trivial (not send/cc to qemu-devel again), that will be more efficient. :-)

No, please always send to qemu-devel; just also cc qemu-trivial (or the relevant subsystem maintainers as listed in MAINTAINERS) if appropriate. Not everybody subscribes to qemu-trivial.

thanks
-- PMM

author
#13 lore raw
Quoted 8 lines · Peter Maydell
Quoted 2 lines · Chen Gang

Next, when I send trivial patches, I will only send to qemu-trivial (not send/cc to qemu-devel again), that will be more efficient. :-)

No, please always send to qemu-devel; just also cc qemu-trivial (or the relevant subsystem maintainers as listed in MAINTAINERS) if appropriate. Not everybody subscribes to qemu-trivial.

OK, thanks.

And when send trivial patch, I will/should always mark it as "[PATCH trivial]" to let another members know about it easily, and always cc to qemu-trivial.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#14 lore raw

PATCH v2 1/1 vl: Report accelerator not supported for target more nicely

In reply to Peter Maydell

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

  $ qemu-system-arm -machine none,accel=kvm
  KVM not supported for this target
  "kvm" accelerator does not exist.
  No accelerator found!

Suppress it.

---
 vl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +1 -1
index 842e897..b4f98fa 100644
@@ -2709,7 +2709,7 @@ static int configure_accelerator(QEMUMachine *machine)
                 if (!accel_list[i].available()) {
                     printf("%s not supported for this target\n",
                            accel_list[i].name);
-                    continue;
+                    break;
                 }
                 *(accel_list[i].allowed) = true;
                 ret = accel_list[i].init(machine);
Signature · 1 line
1.7.9.5
Reviewed-by on v2 1/1
#15 lore raw

Re: [Qemu-devel] [PATCH-trivial v2] vl: Report accelerator not supported for target more nicely

Quoted 8 lines · Chen Gang

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

  $ qemu-system-arm -machine none,accel=kvm
  KVM not supported for this target
  "kvm" accelerator does not exist.
  No accelerator found!
Quoted 4 lines

Suppress it.

#17 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH-trivial v2] vl: Report accelerator not supported for target more nicely

In reply to Chen Gang
Quoted 9 lines · Chen Gang

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

  $ qemu-system-arm -machine none,accel=kvm
  KVM not supported for this target
  "kvm" accelerator does not exist.
  No accelerator found!

Suppress it.

Applied to -trivial, thanks!

/mjt

author
#16 lore raw

Re: [Qemu-devel] [PATCH-trivial v2] vl: Report accelerator not supported for target more nicely

In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Chen Gang

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

  $ qemu-system-arm -machine none,accel=kvm
  KVM not supported for this target
  "kvm" accelerator does not exist.
  No accelerator found!
Quoted 7 lines
Quoted 4 lines

Suppress it.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#18 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH-trivial v2] vl: Report accelerator not supported for target more nicely

In reply to Michael Tokarev
Quoted 9 lines · Michael Tokarev
Quoted 8 lines · Chen Gang

When you ask for an accelerator not supported for your target, you get a bogus "accelerator does not exist" message:

  $ qemu-system-arm -machine none,accel=kvm
  KVM not supported for this target
  "kvm" accelerator does not exist.
  No accelerator found!
Quoted 6 lines
Quoted 1 line

Suppress it.

Applied to -trivial, thanks!

/mjt

Thanks !

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#19 lore raw

cover vl: simplify code for main() and get_boot_device()

In "vl.c", at least, we can simplify the code below, so can let readers read professional C code (especially for new readers, which often start reading code at main function).

- remove useless 'continue' in main().

- remove redundant local variable 'res' in get_boot_device().

- remove local variable 'args' in the middle of code block in main().

The following 3 patches are for the 3 'remove' above.

And "vl.c" has a very long function main() which is about 17K lines. Next, it can be split into sub-functions (so can bypass another code style issue: multiple "{...}" styles within "swith(...)").

---
 vl.c |   23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
author
#20 lore raw

PATCH 1/3 vl: remove useless 'continue'

Normal "if (...) {...} else {...}" is enough in "while(...) {...}", not need additional useless 'continue'.

---
 vl.c |    1 -
 1 file changed, 1 deletion(-)
vl.c +0 -1
index 9975e5a..7505002 100644
@@ -3034,7 +3034,6 @@ int main(int argc, char **argv, char **envp)
         if (argv[optind][0] != '-') {
             /* disk image */
             optind++;
-            continue;
         } else {
             const QEMUOption *popt;
 
Signature · 1 line
1.7.9.5
author
#21 lore raw

PATCH 2/3 vl: remove redundant local variable 'res'

In function, if no additional resources to free before quit, commonly, need not use additional local variable 'res' to notice about it. So remove it to simplify code.

---
 vl.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
vl.c +2 -4
index 7505002..377f962 100644
@@ -1188,18 +1188,16 @@ DeviceState *get_boot_device(uint32_t position)
 {
     uint32_t counter = 0;
     FWBootEntry *i = NULL;
-    DeviceState *res = NULL;
 
     if (!QTAILQ_EMPTY(&fw_boot_order)) {
         QTAILQ_FOREACH(i, &fw_boot_order, link) {
             if (counter == position) {
-                res = i->dev;
-                break;
+                return i->dev;
             }
             counter++;
         }
     }
-    return res;
+    return NULL;
 }
 
 /*
Signature · 1 line
1.7.9.5
author
#22 lore raw

PATCH 3/3 vl: remove local variable 'args' in the middle of code block

For C code, it does not recommend to define a local variable in the middle of code block without "{...}". The original author may want to zero members not mentioned in structure assignment.

So recommend to use structure initializing block "{...}" for structure assignment in the middle of code block.

And at present, we can assume that all related gcc versions will be latest enough to notice about this grammar.

---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +9 -9
index 377f962..d381443 100644
@@ -4368,15 +4368,15 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_init();
 
-    QEMUMachineInitArgs args = { .machine = machine,
-                                 .ram_size = ram_size,
-                                 .boot_order = boot_order,
-                                 .kernel_filename = kernel_filename,
-                                 .kernel_cmdline = kernel_cmdline,
-                                 .initrd_filename = initrd_filename,
-                                 .cpu_model = cpu_model };
-
-    current_machine->init_args = args;
+    current_machine->init_args = (QEMUMachineInitArgs) {
+        .machine = machine,
+        .ram_size = ram_size,
+        .boot_order = boot_order,
+        .kernel_filename = kernel_filename,
+        .kernel_cmdline = kernel_cmdline,
+        .initrd_filename = initrd_filename,
+        .cpu_model = cpu_model };
+
     machine->init(&current_machine->init_args);
 
     audio_init();
Signature · 1 line
1.7.9.5
author
#36 lore raw

Re: [Qemu-trivial] [PATCH trivial 0/3] vl: simplify code for main() and get_boot_device()

In reply to Chen Gang

May any member help to check them?

And next, I shall try to find bug issues (not code style or document issues), and fix them. Hope I can succeed.

Thanks.

Quoted 22 lines · Chen Gang

In "vl.c", at least, we can simplify the code below, so can let readers read professional C code (especially for new readers, which often start reading code at main function).

- remove useless 'continue' in main().

- remove redundant local variable 'res' in get_boot_device().

- remove local variable 'args' in the middle of code block in main().

The following 3 patches are for the 3 'remove' above.

And "vl.c" has a very long function main() which is about 17K lines. Next, it can be split into sub-functions (so can bypass another code style issue: multiple "{...}" styles within "swith(...)").

---
 vl.c |   23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
Reviewed-by on v1 1/3
#31 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 1/3] vl: remove useless 'continue'

In reply to Chen Gang
Quoted 3 lines · Chen Gang

Normal "if (...) {...} else {...}" is enough in "while(...) {...}", not need additional useless 'continue'.

Only in the case where the if-else is not followed by any code. Which is the case here. I found this sentance slightly confusing and TBH id just drop it or say something less codey like:

"This if else has no code between it and the end of the enclosing while loop. This makes this continue redundant."

Quoted 1 line

But patch is good:

Quoted 19 lines
---
 vl.c |    1 -
 1 file changed, 1 deletion(-)
vl.c +0 -2
index 9975e5a..7505002 100644
@@ -3034,7 +3034,6 @@ int main(int argc, char **argv, char **envp)
         if (argv[optind][0] != '-') {
             /* disk image */
             optind++;
-            continue;
         } else {
             const QEMUOption *popt;
 
--

1.7.9.5

#27 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 2/3] vl: remove redundant local variable 'res'

In reply to Chen Gang
Quoted 4 lines · Chen Gang

In function, if no additional resources to free before quit, commonly, need not use additional local variable 'res' to notice about it. So remove it to simplify code.

Styling wise, there is a school of thought that functions should only have one return statement which is probably the original authors intention.

Regards,
Peter

Quoted 33 lines
---
 vl.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
vl.c +2 -5
index 7505002..377f962 100644
@@ -1188,18 +1188,16 @@ DeviceState *get_boot_device(uint32_t position)
 {
     uint32_t counter = 0;
     FWBootEntry *i = NULL;
-    DeviceState *res = NULL;
 
     if (!QTAILQ_EMPTY(&fw_boot_order)) {
         QTAILQ_FOREACH(i, &fw_boot_order, link) {
             if (counter == position) {
-                res = i->dev;
-                break;
+                return i->dev;
             }
             counter++;
         }
     }
-    return res;
+    return NULL;
 }
 
 /*
--

1.7.9.5

author
#32 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 1/3] vl: remove useless 'continue'

In reply to Peter Crosthwaite
Quoted 8 lines · Peter Crosthwaite
Quoted 3 lines · Chen Gang
Quoted 3 lines

Normal "if (...) {...} else {...}" is enough in "while(...) {...}", not need additional useless 'continue'.

Only in the case where the if-else is not followed by any code. Which is the case here. I found this sentance slightly confusing and TBH id just drop it or say something less codey like:

Quoted 8 lines

"This if else has no code between it and the end of the enclosing while loop. This makes this continue redundant."

Quoted 1 line
Quoted 1 line

But patch is good:

OK, thanks.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#28 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 2/3] vl: remove redundant local variable 'res'

In reply to Peter Crosthwaite
Quoted 10 lines · Peter Crosthwaite
Quoted 4 lines · Chen Gang

In function, if no additional resources to free before quit, commonly, need not use additional local variable 'res' to notice about it. So remove it to simplify code.

Styling wise, there is a school of thought that functions should only have one return statement which is probably the original authors intention.

Hmm... maybe.

For me, the readers' feeling (let code simple and easy understanding) is more important than "school rules".

Welcome other members' styling tastes.

Quoted 32 lines

Regards,
Peter

Quoted 29 lines
---
 vl.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
vl.c +2 -4
index 7505002..377f962 100644
@@ -1188,18 +1188,16 @@ DeviceState *get_boot_device(uint32_t position)
 {
     uint32_t counter = 0;
     FWBootEntry *i = NULL;
-    DeviceState *res = NULL;
 
     if (!QTAILQ_EMPTY(&fw_boot_order)) {
         QTAILQ_FOREACH(i, &fw_boot_order, link) {
             if (counter == position) {
-                res = i->dev;
-                break;
+                return i->dev;
             }
             counter++;
         }
     }
-    return res;
+    return NULL;
 }
 
Quoted 4 lines
Quoted 4 lines
vl.c +0 -1
 /*
--

1.7.9.5

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#29 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 2/3] vl: remove redundant local variable 'res'

In reply to Peter Crosthwaite
Quoted 9 lines · Peter Crosthwaite
Quoted 4 lines · Chen Gang

In function, if no additional resources to free before quit, commonly, need not use additional local variable 'res' to notice about it. So remove it to simplify code.

Styling wise, there is a school of thought that functions should only have one return statement which is probably the original authors intention.

Plausible. But what matters here is whether we think the patch is worthwhile or not.

I find Chen's version a bit clearer, but I'm not sure it's worth the churn.

#37 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 0/3] vl: simplify code for main() and get_boot_device()

In reply to Chen Gang
Quoted 17 lines · Chen Gang

In "vl.c", at least, we can simplify the code below, so can let readers read professional C code (especially for new readers, which often start reading code at main function).

- remove useless 'continue' in main().

- remove redundant local variable 'res' in get_boot_device().

- remove local variable 'args' in the middle of code block in main().

The following 3 patches are for the 3 'remove' above.

And "vl.c" has a very long function main() which is about 17K lines. Next, it can be split into sub-functions (so can bypass another code style issue: multiple "{...}" styles within "swith(...)").

Quoted 4 lines
---
 vl.c |   23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

In future submissions, please send the patches in-reply-to the cover letter, not chained together in-reply-to the previous part. Check out git-send-email --no-chain-reply-to.

Reviewed-by on v1 1/3
#33 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 1/3] vl: remove useless 'continue'

In reply to Chen Gang
Quoted 13 lines · Chen Gang

Normal "if (...) {...} else {...}" is enough in "while(...) {...}", not need additional useless 'continue'.

---
 vl.c |    1 -
 1 file changed, 1 deletion(-)
vl.c +0 -0
index 9975e5a..7505002 100644

vl.c int main(int argc, char **argv, char **envp) · line 3038

Quoted 6 lines
vl.c +0 -1
@@ -3034,7 +3034,6 @@ int main(int argc, char **argv, char **envp)
         if (argv[optind][0] != '-') {
             /* disk image */
             optind++;
-            continue;
         } else {
             const QEMUOption *popt;
Reviewed-by on v1 3/3
#23 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 3/3] vl: remove local variable 'args' in the middle of code block

In reply to Chen Gang
Quoted 9 lines · Chen Gang

For C code, it does not recommend to define a local variable in the middle of code block without "{...}". The original author may want to zero members not mentioned in structure assignment.

So recommend to use structure initializing block "{...}" for structure assignment in the middle of code block.

And at present, we can assume that all related gcc versions will be latest enough to notice about this grammar.

Commit message is a bit confusing :) I'd write something like this:

vl: Eliminate a superfluous local variable

CODING_STYLE frowns upon mixing declarations and statements. main() has such a declaration. Clean up by eliminating the variable.

Quoted 25 lines
---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +2 -9
index 377f962..d381443 100644
@@ -4368,15 +4368,15 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_init();
 
-    QEMUMachineInitArgs args = { .machine = machine,
-                                 .ram_size = ram_size,
-                                 .boot_order = boot_order,
-                                 .kernel_filename = kernel_filename,
-                                 .kernel_cmdline = kernel_cmdline,
-                                 .initrd_filename = initrd_filename,
-                                 .cpu_model = cpu_model };
-
-    current_machine->init_args = args;
+    current_machine->init_args = (QEMUMachineInitArgs) {
+        .machine = machine,

vl.c int main(int argc, char **argv, char **envp) · line 4382

Quoted 10 lines
vl.c +7 -0
+        .ram_size = ram_size,
+        .boot_order = boot_order,
+        .kernel_filename = kernel_filename,
+        .kernel_cmdline = kernel_cmdline,
+        .initrd_filename = initrd_filename,
+        .cpu_model = cpu_model };
+
     machine->init(&current_machine->init_args);
 
     audio_init();
author
#30 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 2/3] vl: remove redundant local variable 'res'

In reply to Markus Armbruster
Quoted 12 lines · Markus Armbruster
Quoted 9 lines · Peter Crosthwaite
Quoted 4 lines · Chen Gang

In function, if no additional resources to free before quit, commonly, need not use additional local variable 'res' to notice about it. So remove it to simplify code.

Styling wise, there is a school of thought that functions should only have one return statement which is probably the original authors intention.

Quoted 6 lines

Plausible. But what matters here is whether we think the patch is worthwhile or not.

I find Chen's version a bit clearer, but I'm not sure it's worth the churn.

Hmm... after think of, for me, it will be fine to still remain the original state, it is not quit worth to churn.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#34 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 1/3] vl: remove useless 'continue'

In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Chen Gang

Normal "if (...) {...} else {...}" is enough in "while(...) {...}", not need additional useless 'continue'.

---
 vl.c |    1 -
 1 file changed, 1 deletion(-)
Quoted 14 lines

vl.c int main(int argc, char **argv, char **envp) · line 3038

Quoted 11 lines
vl.c +0 -1
index 9975e5a..7505002 100644
@@ -3034,7 +3034,6 @@ int main(int argc, char **argv, char **envp)
         if (argv[optind][0] != '-') {
             /* disk image */
             optind++;
-            continue;
         } else {
             const QEMUOption *popt;

OK, thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#24 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 3/3] vl: remove local variable 'args' in the middle of code block

In reply to Markus Armbruster
Quoted 12 lines · Markus Armbruster
Quoted 9 lines · Chen Gang

For C code, it does not recommend to define a local variable in the middle of code block without "{...}". The original author may want to zero members not mentioned in structure assignment.

So recommend to use structure initializing block "{...}" for structure assignment in the middle of code block.

And at present, we can assume that all related gcc versions will be latest enough to notice about this grammar.

Quoted 7 lines

Commit message is a bit confusing :) I'd write something like this:

vl: Eliminate a superfluous local variable

CODING_STYLE frowns upon mixing declarations and statements. main() has such a declaration. Clean up by eliminating the variable.

That sounds fine to me.

And excuse me, my English is not quite well (so may write confusing and redundancy comments)

Thanks.

Quoted 38 lines
Quoted 25 lines
---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +2 -9
index 377f962..d381443 100644
@@ -4368,15 +4368,15 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_init();
 
-    QEMUMachineInitArgs args = { .machine = machine,
-                                 .ram_size = ram_size,
-                                 .boot_order = boot_order,
-                                 .kernel_filename = kernel_filename,
-                                 .kernel_cmdline = kernel_cmdline,
-                                 .initrd_filename = initrd_filename,
-                                 .cpu_model = cpu_model };
-
-    current_machine->init_args = args;
+    current_machine->init_args = (QEMUMachineInitArgs) {
+        .machine = machine,

vl.c int main(int argc, char **argv, char **envp) · line 4382

Quoted 10 lines
vl.c +7 -0
+        .ram_size = ram_size,
+        .boot_order = boot_order,
+        .kernel_filename = kernel_filename,
+        .kernel_cmdline = kernel_cmdline,
+        .initrd_filename = initrd_filename,
+        .cpu_model = cpu_model };
+
     machine->init(&current_machine->init_args);
 
     audio_init();
Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
Reviewed-by on v1 3/3
#25 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 3/3] vl: remove local variable 'args' in the middle of code block

In reply to Chen Gang
Quoted 4 lines · Chen Gang

For C code, it does not recommend to define a local variable in the middle of code block without "{...}". The original author may want to zero members not mentioned in structure assignment.

Quoted 8 lines

So recommend to use structure initializing block "{...}" for structure assignment in the middle of code block.

And at present, we can assume that all related gcc versions will be latest enough to notice about this grammar.

With Markus' suggest commit message fixup:

Quoted 36 lines
---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +9 -10
index 377f962..d381443 100644
@@ -4368,15 +4368,15 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_init();
 
-    QEMUMachineInitArgs args = { .machine = machine,
-                                 .ram_size = ram_size,
-                                 .boot_order = boot_order,
-                                 .kernel_filename = kernel_filename,
-                                 .kernel_cmdline = kernel_cmdline,
-                                 .initrd_filename = initrd_filename,
-                                 .cpu_model = cpu_model };
-
-    current_machine->init_args = args;
+    current_machine->init_args = (QEMUMachineInitArgs) {
+        .machine = machine,
+        .ram_size = ram_size,
+        .boot_order = boot_order,
+        .kernel_filename = kernel_filename,
+        .kernel_cmdline = kernel_cmdline,
+        .initrd_filename = initrd_filename,
+        .cpu_model = cpu_model };
+
     machine->init(&current_machine->init_args);
 
     audio_init();
--

1.7.9.5

author
#26 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 3/3] vl: remove local variable 'args' in the middle of code block

Quoted 12 lines · Peter Crosthwaite
Quoted 11 lines · Chen Gang

For C code, it does not recommend to define a local variable in the middle of code block without "{...}". The original author may want to zero members not mentioned in structure assignment.

So recommend to use structure initializing block "{...}" for structure assignment in the middle of code block.

And at present, we can assume that all related gcc versions will be latest enough to notice about this grammar.

Quoted 6 lines
Quoted 1 line

With Markus' suggest commit message fixup:

OK, thanks. I will use the new commit message in the patch v2.

Quoted 36 lines
Quoted 36 lines
---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +9 -10
index 377f962..d381443 100644
@@ -4368,15 +4368,15 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_init();
 
-    QEMUMachineInitArgs args = { .machine = machine,
-                                 .ram_size = ram_size,
-                                 .boot_order = boot_order,
-                                 .kernel_filename = kernel_filename,
-                                 .kernel_cmdline = kernel_cmdline,
-                                 .initrd_filename = initrd_filename,
-                                 .cpu_model = cpu_model };
-
-    current_machine->init_args = args;
+    current_machine->init_args = (QEMUMachineInitArgs) {
+        .machine = machine,
+        .ram_size = ram_size,
+        .boot_order = boot_order,
+        .kernel_filename = kernel_filename,
+        .kernel_cmdline = kernel_cmdline,
+        .initrd_filename = initrd_filename,
+        .cpu_model = cpu_model };
+
     machine->init(&current_machine->init_args);
 
     audio_init();
--

1.7.9.5

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#38 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 0/3] vl: simplify code for main() and get_boot_device()

In reply to Markus Armbruster
Quoted 19 lines · Markus Armbruster
Quoted 17 lines · Chen Gang

In "vl.c", at least, we can simplify the code below, so can let readers read professional C code (especially for new readers, which often start reading code at main function).

- remove useless 'continue' in main().

- remove redundant local variable 'res' in get_boot_device().

- remove local variable 'args' in the middle of code block in main().

The following 3 patches are for the 3 'remove' above.

And "vl.c" has a very long function main() which is about 17K lines. Next, it can be split into sub-functions (so can bypass another code style issue: multiple "{...}" styles within "swith(...)").

Quoted 9 lines
Quoted 4 lines
---
 vl.c |   23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

In future submissions, please send the patches in-reply-to the cover letter, not chained together in-reply-to the previous part. Check out git-send-email --no-chain-reply-to.

OK, thanks. But excuse me, I use thunderbird client to send/recv mail (not use git send-mail), so not quit understand what you said. And I guess what your meaning is:

- start a new thread "[PATH 0/3]..."

- "[PATH 1/3]..." need "reply all" the "[PATH 0/3]..."

- "[PATH 2/3]..." need "reply all" the "[PATH 0/3]..."

- "[PATH 3/3]..." need "reply all" the "[PATH 0/3]..."

If what I guess is incorrect, please let me know, and it will be better to provide more detials.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#39 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 0/3] vl: simplify code for main() and get_boot_device()

Quoted 12 lines · Chen Gang
Quoted 4 lines · Markus Armbruster

In future submissions, please send the patches in-reply-to the cover letter, not chained together in-reply-to the previous part. Check out git-send-email --no-chain-reply-to.

OK, thanks. But excuse me, I use thunderbird client to send/recv mail (not use git send-mail), so not quit understand what you said. And I guess what your meaning is:

- start a new thread "[PATH 0/3]..."

Quoted 8 lines

- "[PATH 1/3]..." need "reply all" the "[PATH 0/3]..."

- "[PATH 2/3]..." need "reply all" the "[PATH 0/3]..."

- "[PATH 3/3]..." need "reply all" the "[PATH 0/3]..."

If what I guess is incorrect, please let me know, and it will be better to provide more detials.

Sounds okay. But sending with git-send-email is so much easier...

author
#40 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 0/3] vl: simplify code for main() and get_boot_device()

Quoted 16 lines · Markus Armbruster
Quoted 14 lines · Chen Gang
Quoted 4 lines · Markus Armbruster

In future submissions, please send the patches in-reply-to the cover letter, not chained together in-reply-to the previous part. Check out git-send-email --no-chain-reply-to.

OK, thanks. But excuse me, I use thunderbird client to send/recv mail (not use git send-mail), so not quit understand what you said. And I guess what your meaning is:

- start a new thread "[PATH 0/3]..."

- "[PATH 1/3]..." need "reply all" the "[PATH 0/3]..."

Quoted 9 lines
Quoted 6 lines

- "[PATH 2/3]..." need "reply all" the "[PATH 0/3]..."

- "[PATH 3/3]..." need "reply all" the "[PATH 0/3]..."

If what I guess is incorrect, please let me know, and it will be better to provide more detials.

Sounds okay. But sending with git-send-email is so much easier...

I guess so, too (sending with git-send-email is much easier, which I am not quite familiar).

I have already familiar with Thunderbird, and at least now, I am not a maintainer, neither a main patch maker. at present, I have no too many patches to process. So Thunderbird is enough to me. :-)

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#35 lore raw

Re: [Qemu-trivial] [Qemu-devel] [PATCH trivial 1/3] vl: remove useless 'continue'

In reply to Chen Gang

我怎样才能退订此邮件列表
How can I unsubscribe from this mailing list

2014-04-15 19:05 GMT+08:00 Chen Gang <[email protected]>:

Quoted 36 lines · Markus Armbruster
Quoted 10 lines
Quoted 8 lines · Chen Gang

Normal "if (...) {...} else {...}" is enough in "while(...) {...}", not need additional useless 'continue'.

---
 vl.c |    1 -
 1 file changed, 1 deletion(-)
Quoted 14 lines

vl.c int main(int argc, char **argv, char **envp) · line 3038

Quoted 11 lines
vl.c +0 -1
index 9975e5a..7505002 100644
@@ -3034,7 +3034,6 @@ int main(int argc, char **argv, char **envp)
         if (argv[optind][0] != '-') {
             /* disk image */
             optind++;
-            continue;
         } else {
             const QEMUOption *popt;

OK, thanks.

--
Chen Gang

Open, share, and attitude like air, water, and life which God blessed