Re: [PATCH 1/3 V2] kvm tools: Add memory gap for larger RAM sizes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Sasha Levin <levinsasha928@xxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux