[PATCH] drm/vboxvideo: Unmap iomem on probe-failure and remove

Daniel Vetter daniel at ffwll.ch
Tue Oct 27 15:23:02 UTC 2020


On Tue, Oct 27, 2020 at 2:52 PM Hans de Goede <hdegoede at redhat.com> wrote:
>
> Add missing pci_iounmap() calls to properly unmap the memory on
> probe-failure and remove.
>
> Reported-by: kernel test robot <lkp at intel.com>
> Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>

I think switching over to devm would be really nice. And for pci all
you need to do is use pcim_enable_device and delete all the cleanup
code, and it's all done. Hand rolling device cleanup code really isn't
a great idea and way too error-prone. Plus you're using lots of devm_
already.
-Daniel

> ---
>  drivers/gpu/drm/vboxvideo/vbox_main.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/vboxvideo/vbox_main.c b/drivers/gpu/drm/vboxvideo/vbox_main.c
> index d68d9bad7674..2eeb1d3be54a 100644
> --- a/drivers/gpu/drm/vboxvideo/vbox_main.c
> +++ b/drivers/gpu/drm/vboxvideo/vbox_main.c
> @@ -71,6 +71,8 @@ static void vbox_accel_fini(struct vbox_private *vbox)
>
>         for (i = 0; i < vbox->num_crtcs; ++i)
>                 vbva_disable(&vbox->vbva_info[i], vbox->guest_pool, i);
> +
> +       pci_iounmap(vbox->ddev.pdev, vbox->vbva_buffers);
>  }
>
>  /* Do we support the 4.3 plus mode hint reporting interface? */
> @@ -124,19 +126,19 @@ int vbox_hw_init(struct vbox_private *vbox)
>         vbox->guest_pool = devm_gen_pool_create(vbox->ddev.dev, 4, -1,
>                                                 "vboxvideo-accel");
>         if (!vbox->guest_pool)
> -               return -ENOMEM;
> +               goto out_unmap_guest_heap;
>
>         ret = gen_pool_add_virt(vbox->guest_pool,
>                                 (unsigned long)vbox->guest_heap,
>                                 GUEST_HEAP_OFFSET(vbox),
>                                 GUEST_HEAP_USABLE_SIZE, -1);
>         if (ret)
> -               return ret;
> +               goto out_unmap_guest_heap;
>
>         ret = hgsmi_test_query_conf(vbox->guest_pool);
>         if (ret) {
>                 DRM_ERROR("vboxvideo: hgsmi_test_query_conf failed\n");
> -               return ret;
> +               goto out_unmap_guest_heap;
>         }
>
>         /* Reduce available VRAM size to reflect the guest heap. */
> @@ -148,23 +150,30 @@ int vbox_hw_init(struct vbox_private *vbox)
>
>         if (!have_hgsmi_mode_hints(vbox)) {
>                 ret = -ENOTSUPP;
> -               return ret;
> +               goto out_unmap_guest_heap;
>         }
>
>         vbox->last_mode_hints = devm_kcalloc(vbox->ddev.dev, vbox->num_crtcs,
>                                              sizeof(struct vbva_modehint),
>                                              GFP_KERNEL);
> -       if (!vbox->last_mode_hints)
> -               return -ENOMEM;
> +       if (!vbox->last_mode_hints) {
> +               ret = -ENOMEM;
> +               goto out_unmap_guest_heap;
> +       }
>
>         ret = vbox_accel_init(vbox);
>         if (ret)
> -               return ret;
> +               goto out_unmap_guest_heap;
>
>         return 0;
> +
> +out_unmap_guest_heap:
> +       pci_iounmap(vbox->ddev.pdev, vbox->guest_pool);
> +       return ret;
>  }
>
>  void vbox_hw_fini(struct vbox_private *vbox)
>  {
>         vbox_accel_fini(vbox);
> +       pci_iounmap(vbox->ddev.pdev, vbox->guest_pool);
>  }
> --
> 2.28.0
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list