On Mon, Apr 6, 2020 at 7:29 PM Thomas Zimmermann <tzimmermann@xxxxxxx> wrote: > > > > Am 03.04.20 um 15:58 schrieb Daniel Vetter: > > Also need to remove the drm_dev_put from the remove hook. > > > > Signed-off-by: Daniel Vetter <daniel.vetter@xxxxxxxxx> > > Cc: Dave Airlie <airlied@xxxxxxxxxx> > > Cc: Gerd Hoffmann <kraxel@xxxxxxxxxx> > > Cc: virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx > > Cc: spice-devel@xxxxxxxxxxxxxxxxxxxxx > > --- > > drivers/gpu/drm/qxl/qxl_drv.c | 15 ++++++++------- > > drivers/gpu/drm/qxl/qxl_drv.h | 3 +-- > > drivers/gpu/drm/qxl/qxl_kms.c | 12 +----------- > > 3 files changed, 10 insertions(+), 20 deletions(-) > > > > diff --git a/drivers/gpu/drm/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c > > index 09102e2efabc..6b4ae4c5fb76 100644 > > --- a/drivers/gpu/drm/qxl/qxl_drv.c > > +++ b/drivers/gpu/drm/qxl/qxl_drv.c > > @@ -81,13 +81,16 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > > return -EINVAL; /* TODO: ENODEV ? */ > > } > > > > - qdev = kzalloc(sizeof(struct qxl_device), GFP_KERNEL); > > - if (!qdev) > > + qdev = devm_drm_dev_alloc(&pdev->dev, &qxl_driver, > > + struct qxl_device, ddev); > > + if (IS_ERR(qdev)) { > > + pr_err("Unable to init drm dev"); > > return -ENOMEM; > > + } > > My feeling is that it is too early to allocate. Wouldn't it be better to > first do the pdev and conflicting-fb stuff and allocate right before > qxl_device_init() ? It doesn't matter. I can reorder, or I can also not reorder, it'll have 0 effects on cleanup (all done automatically) or correctness (it's just a memory allocation, it doesn't do anything). -Daniel > Best regards > Thomas > > > > > ret = pci_enable_device(pdev); > > if (ret) > > - goto free_dev; > > + return ret; > > > > ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "qxl"); > > if (ret) > > @@ -101,7 +104,7 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > > } > > } > > > > - ret = qxl_device_init(qdev, &qxl_driver, pdev); > > + ret = qxl_device_init(qdev, pdev); > > if (ret) > > goto put_vga; > > > > @@ -128,8 +131,7 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) > > vga_put(pdev, VGA_RSRC_LEGACY_IO); > > disable_pci: > > pci_disable_device(pdev); > > -free_dev: > > - kfree(qdev); > > + > > return ret; > > } > > > > @@ -155,7 +157,6 @@ qxl_pci_remove(struct pci_dev *pdev) > > drm_atomic_helper_shutdown(dev); > > if (is_vga(pdev)) > > vga_put(pdev, VGA_RSRC_LEGACY_IO); > > - drm_dev_put(dev); > > } > > > > DEFINE_DRM_GEM_FOPS(qxl_fops); > > diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h > > index 435126facc9b..86ac191d9205 100644 > > --- a/drivers/gpu/drm/qxl/qxl_drv.h > > +++ b/drivers/gpu/drm/qxl/qxl_drv.h > > @@ -276,8 +276,7 @@ struct qxl_device { > > extern const struct drm_ioctl_desc qxl_ioctls[]; > > extern int qxl_max_ioctl; > > > > -int qxl_device_init(struct qxl_device *qdev, struct drm_driver *drv, > > - struct pci_dev *pdev); > > +int qxl_device_init(struct qxl_device *qdev, struct pci_dev *pdev); > > void qxl_device_fini(struct qxl_device *qdev); > > > > int qxl_modeset_init(struct qxl_device *qdev); > > diff --git a/drivers/gpu/drm/qxl/qxl_kms.c b/drivers/gpu/drm/qxl/qxl_kms.c > > index 9eed1a375f24..91a34dd835d7 100644 > > --- a/drivers/gpu/drm/qxl/qxl_kms.c > > +++ b/drivers/gpu/drm/qxl/qxl_kms.c > > @@ -108,21 +108,13 @@ static void qxl_gc_work(struct work_struct *work) > > } > > > > int qxl_device_init(struct qxl_device *qdev, > > - struct drm_driver *drv, > > struct pci_dev *pdev) > > { > > int r, sb; > > > > - r = drm_dev_init(&qdev->ddev, drv, &pdev->dev); > > - if (r) { > > - pr_err("Unable to init drm dev"); > > - goto error; > > - } > > - > > qdev->ddev.pdev = pdev; > > pci_set_drvdata(pdev, &qdev->ddev); > > qdev->ddev.dev_private = qdev; > > - drmm_add_final_kfree(&qdev->ddev, qdev); > > > > mutex_init(&qdev->gem.mutex); > > mutex_init(&qdev->update_area_mutex); > > @@ -138,8 +130,7 @@ int qxl_device_init(struct qxl_device *qdev, > > qdev->vram_mapping = io_mapping_create_wc(qdev->vram_base, pci_resource_len(pdev, 0)); > > if (!qdev->vram_mapping) { > > pr_err("Unable to create vram_mapping"); > > - r = -ENOMEM; > > - goto error; > > + return -ENOMEM; > > } > > > > if (pci_resource_len(pdev, 4) > 0) { > > @@ -293,7 +284,6 @@ int qxl_device_init(struct qxl_device *qdev, > > io_mapping_free(qdev->surface_mapping); > > vram_mapping_free: > > io_mapping_free(qdev->vram_mapping); > > -error: > > return r; > > } > > > > > > -- > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 Nürnberg, Germany > (HRB 36809, AG Nürnberg) > Geschäftsführer: Felix Imendörffer > -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization