Re: [PATCH] kvm tool: rewrite kvm__init

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

 



On Thu, Feb 9, 2012 at 7:40 AM, Yang Bai <hamo.by@xxxxxxxxx> wrote:
> Since the different issues have been handled in the
> internal of kvm__init, it can only return NULL if error
> happened.
>
> Signed-off-by: Yang Bai <hamo.by@xxxxxxxxx>

Sorry, I don't understand what this patch is attempting to fix? Why do
you think it's better to drop the explicit error codes and always
return NULL upon error?

> ---
>  tools/kvm/builtin-run.c |    4 ++--
>  tools/kvm/kvm.c         |   20 +++++++-------------
>  2 files changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> index 466169e..b71816f 100644
> --- a/tools/kvm/builtin-run.c
> +++ b/tools/kvm/builtin-run.c
> @@ -997,8 +997,8 @@ static int kvm_cmd_run_init(int argc, const char **argv)
>        }
>
>        kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
> -       if (IS_ERR(kvm)) {
> -               r = PTR_ERR(kvm);
> +       if (!kvm) {
> +               r = -EFAULT;
>                goto fail;
>        }
>
> diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
> index 9a0bd67..e3280a8 100644
> --- a/tools/kvm/kvm.c
> +++ b/tools/kvm/kvm.c
> @@ -334,17 +334,17 @@ int kvm__max_cpus(struct kvm *kvm)
>
>  struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_size, const char *name)
>  {
> -       struct kvm *kvm;
> +       struct kvm *kvm = NULL;
>        int ret;
>
>        if (!kvm__arch_cpu_supports_vm()) {
>                pr_err("Your CPU does not support hardware virtualization");
> -               return ERR_PTR(-ENOSYS);
> +               return NULL;
>        }
>
>        kvm = kvm__new();
>        if (IS_ERR(kvm))
> -               return kvm;
> +               return NULL;
>
>        kvm->sys_fd = open(kvm_dev, O_RDWR);
>        if (kvm->sys_fd < 0) {
> @@ -358,32 +358,26 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s
>                else
>                        pr_err("Could not open %s: ", kvm_dev);
>
> -               ret = -errno;
>                goto err_free;
>        }
>
>        ret = ioctl(kvm->sys_fd, KVM_GET_API_VERSION, 0);
>        if (ret != KVM_API_VERSION) {
>                pr_err("KVM_API_VERSION ioctl");
> -               ret = -errno;
>                goto err_sys_fd;
>        }
>
>        kvm->vm_fd = ioctl(kvm->sys_fd, KVM_CREATE_VM, 0);
> -       if (kvm->vm_fd < 0) {
> -               ret = kvm->vm_fd;
> +       if (kvm->vm_fd < 0)
>                goto err_sys_fd;
> -       }
>
>        kvm->name = strdup(name);
> -       if (!kvm->name) {
> -               ret = -ENOMEM;
> +       if (!kvm->name)
>                goto err;
> -       }
>
>        if (kvm__check_extensions(kvm)) {
>                pr_err("A required KVM extention is not supported by OS");
> -               ret = -ENOSYS;
> +               goto err;
>        }
>
>        kvm__arch_init(kvm, hugetlbfs_path, ram_size);
> @@ -400,7 +394,7 @@ err_sys_fd:
>  err_free:
>        free(kvm);
>
> -       return ERR_PTR(ret);
> +       return NULL;
>  }
>
>  /* RFC 1952 */
> --
> 1.7.8.3
>
> --
> 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
--
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