Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: penberg@kernel.org, asias.hejun@gmail.com,
	prasadjoshi124@gmail.com, avi@redhat.com, gorcunov@gmail.com,
	kvm@vger.kernel.org
Subject: Re: [PATCH 1/3 V2] kvm tools: Add memory gap for larger RAM sizes
Date: Wed, 11 May 2011 09:39:00 +0200	[thread overview]
Message-ID: <20110511073900.GA26020@elte.hu> (raw)
In-Reply-To: <1305099257-7187-1-git-send-email-levinsasha928@gmail.com>


* Sasha Levin <levinsasha928@gmail.com> wrote:

> +void kvm__init_ram(struct kvm *self)
> +{
> +	if (self->ram_size < KVM_32BIT_GAP_START) {
> +		kvm_register_mem_slot(self, 0, 0, self->ram_size, (u64)self->ram_start);
> +	} else {
> +		kvm_register_mem_slot(self, 0, 0, KVM_32BIT_GAP_START, (u64)self->ram_start);
> +		kvm_register_mem_slot(self, 1, 0x100000000ULL, self->ram_size - KVM_32BIT_GAP_START, (u64)self->ram_start + 0x100000000ULL);

Why not change kvm_register_mem_slot() to have a void * parameter for the start 
address? This has two advantages:

 - the ugly and fragile (u64) casts above disappear, as ->ram_start is already void *

 - we get type checking protection: if someone accidentally calls this function with
   (start, size) instead of (size, start) we'll get a compiler warning

Basically every type you are forced to write a C type cast you should think 
hard to avoid it. They are almost always the wrong thing to do and are canaries 
of some other structural problem.

Thanks,

	Ingo

      reply	other threads:[~2011-05-11 15:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-11  7:34 [PATCH 1/3 V2] kvm tools: Add memory gap for larger RAM sizes Sasha Levin
2011-05-11  7:39 ` 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=20110511073900.GA26020@elte.hu \
    --to=mingo@elte.hu \
    --cc=asias.hejun@gmail.com \
    --cc=avi@redhat.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.com \
    /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