From: Ingo Molnar <mingo@elte.hu>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: penberg@cs.helsinki.fi, kvm@vger.kernel.org,
asias.hejun@gmail.com, gorcunov@gmail.com
Subject: Re: [PATCH v3] kvm tools: Support multiple net devices
Date: Tue, 27 Sep 2011 08:41:33 +0200 [thread overview]
Message-ID: <20110927064133.GC18519@elte.hu> (raw)
In-Reply-To: <1317059073-19576-1-git-send-email-levinsasha928@gmail.com>
* Sasha Levin <levinsasha928@gmail.com> wrote:
> --- a/tools/kvm/builtin-run.c
> +++ b/tools/kvm/builtin-run.c
> @@ -87,9 +87,12 @@ static bool sdl;
> static bool balloon;
> static bool using_rootfs;
> static bool custom_rootfs;
> +static bool no_net;
> extern bool ioport_debug;
> extern int active_console;
> extern int debug_iodelay;
> +struct virtio_net_parameters *net_params;
> +int num_net_devices;
Just a stylistic nit-pick: this variable definition section looks
pretty ugly. Those externs should be in a header and in any case
different types of lines should generally not be mixed without at
least a newline between them.
> +static int set_net_param(struct virtio_net_parameters *p, const char *param,
> + const char *val)
Naming nit: 'struct virtio_net_params' is shorter by 4 chars and just
as expressive.
> + char *buf, *cmd = NULL, *cur = NULL;
> + bool on_cmd = true;
> +
> + if (arg) {
> + buf = strdup(arg);
> + if (buf == NULL)
> + die("Failed allocating new net buffer");
> + cur = strtok(buf, ",=");
> + }
> +
> + p = (struct virtio_net_parameters) {
> + .guest_ip = DEFAULT_GUEST_ADDR,
> + .host_ip = DEFAULT_HOST_ADDR,
> + .script = DEFAULT_SCRIPT,
> + .mode = NET_MODE_TAP,
> + };
> +
> + str_to_mac(DEFAULT_GUEST_MAC, p.guest_mac);
> + p.guest_mac[5] += num_net_devices;
> +
> + while (cur) {
> + if (on_cmd) {
> + cmd = cur;
> + } else {
> + if (set_net_param(&p, cmd, cur) < 0)
> + goto done;
> + }
> + on_cmd = !on_cmd;
> +
> + cur = strtok(NULL, ",=");
> + };
> +
> + num_net_devices++;
> +
> + net_params = realloc(net_params, num_net_devices * sizeof(*net_params));
> + if (net_params == NULL)
> + die("Failed adding new network device");
> +
> + net_params[num_net_devices - 1] = p;
> +
> +done:
> + return 0;
> +}
Isn't 'buf' leaked here?
Patch looks good otherwise.
Thanks,
Ingo
prev parent reply other threads:[~2011-09-27 7:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-26 17:44 [PATCH v3] kvm tools: Support multiple net devices Sasha Levin
2011-09-27 2:38 ` Asias He
2011-09-27 6:41 ` Ingo Molnar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110927064133.GC18519@elte.hu \
--to=mingo@elte.hu \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=penberg@cs.helsinki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox