Skip to content

Commit 84d7d47

Browse files
committed
drm/vc4: Use devm_drm_dev_alloc
We can simplify a bit the bind code, its error path and unbind by using the managed devm_drm_dev_alloc function. Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://patchwork.freedesktop.org/patch/msgid/20201029190104.2181730-5-maxime@cerno.tech
1 parent 88e0858 commit 84d7d47

5 files changed

Lines changed: 25 additions & 32 deletions

File tree

drivers/gpu/drm/vc4/vc4_bo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t unaligned_size,
449449
}
450450

451451
if (IS_ERR(cma_obj)) {
452-
struct drm_printer p = drm_info_printer(vc4->dev->dev);
452+
struct drm_printer p = drm_info_printer(vc4->base.dev);
453453
DRM_ERROR("Failed to allocate from CMA:\n");
454454
vc4_bo_stats_print(&p, vc4);
455455
return ERR_PTR(-ENOMEM);
@@ -590,7 +590,7 @@ static void vc4_bo_cache_time_work(struct work_struct *work)
590590
{
591591
struct vc4_dev *vc4 =
592592
container_of(work, struct vc4_dev, bo_cache.time_work);
593-
struct drm_device *dev = vc4->dev;
593+
struct drm_device *dev = &vc4->base;
594594

595595
mutex_lock(&vc4->bo_lock);
596596
vc4_bo_cache_free_old(dev);

drivers/gpu/drm/vc4/vc4_drv.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,41 +257,37 @@ static int vc4_drm_bind(struct device *dev)
257257

258258
dev->coherent_dma_mask = DMA_BIT_MASK(32);
259259

260-
vc4 = devm_kzalloc(dev, sizeof(*vc4), GFP_KERNEL);
261-
if (!vc4)
262-
return -ENOMEM;
263-
264260
/* If VC4 V3D is missing, don't advertise render nodes. */
265261
node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
266262
if (!node || !of_device_is_available(node))
267263
vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
268264
of_node_put(node);
269265

270-
drm = drm_dev_alloc(&vc4_drm_driver, dev);
271-
if (IS_ERR(drm))
272-
return PTR_ERR(drm);
266+
vc4 = devm_drm_dev_alloc(dev, &vc4_drm_driver, struct vc4_dev, base);
267+
if (IS_ERR(vc4))
268+
return PTR_ERR(vc4);
269+
270+
drm = &vc4->base;
273271
platform_set_drvdata(pdev, drm);
274-
vc4->dev = drm;
275-
drm->dev_private = vc4;
276272
INIT_LIST_HEAD(&vc4->debugfs_list);
277273

278274
mutex_init(&vc4->bin_bo_lock);
279275

280276
ret = vc4_bo_cache_init(drm);
281277
if (ret)
282-
goto dev_put;
278+
return ret;
283279

284280
ret = drmm_mode_config_init(drm);
285281
if (ret)
286-
goto dev_put;
282+
return ret;
287283

288284
ret = vc4_gem_init(drm);
289285
if (ret)
290-
goto dev_put;
286+
return ret;
291287

292288
ret = component_bind_all(dev, drm);
293289
if (ret)
294-
goto dev_put;
290+
return ret;
295291

296292
ret = vc4_plane_create_additional_planes(drm);
297293
if (ret)
@@ -316,8 +312,7 @@ static int vc4_drm_bind(struct device *dev)
316312

317313
unbind_all:
318314
component_unbind_all(dev, drm);
319-
dev_put:
320-
drm_dev_put(drm);
315+
321316
return ret;
322317
}
323318

@@ -332,8 +327,6 @@ static void vc4_drm_unbind(struct device *dev)
332327

333328
drm_atomic_private_obj_fini(&vc4->load_tracker);
334329
drm_atomic_private_obj_fini(&vc4->ctm_manager);
335-
336-
drm_dev_put(drm);
337330
}
338331

339332
static const struct component_master_ops vc4_drm_ops = {

drivers/gpu/drm/vc4/vc4_drv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct vc4_perfmon {
7272
};
7373

7474
struct vc4_dev {
75-
struct drm_device *dev;
75+
struct drm_device base;
7676

7777
struct vc4_hvs *hvs;
7878
struct vc4_v3d *v3d;
@@ -235,7 +235,7 @@ struct vc4_dev {
235235
static inline struct vc4_dev *
236236
to_vc4_dev(struct drm_device *dev)
237237
{
238-
return (struct vc4_dev *)dev->dev_private;
238+
return container_of(dev, struct vc4_dev, base);
239239
}
240240

241241
struct vc4_bo {

drivers/gpu/drm/vc4/vc4_gem.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,16 @@ vc4_reset_work(struct work_struct *work)
314314
struct vc4_dev *vc4 =
315315
container_of(work, struct vc4_dev, hangcheck.reset_work);
316316

317-
vc4_save_hang_state(vc4->dev);
317+
vc4_save_hang_state(&vc4->base);
318318

319-
vc4_reset(vc4->dev);
319+
vc4_reset(&vc4->base);
320320
}
321321

322322
static void
323323
vc4_hangcheck_elapsed(struct timer_list *t)
324324
{
325325
struct vc4_dev *vc4 = from_timer(vc4, t, hangcheck.timer);
326-
struct drm_device *dev = vc4->dev;
326+
struct drm_device *dev = &vc4->base;
327327
uint32_t ct0ca, ct1ca;
328328
unsigned long irqflags;
329329
struct vc4_exec_info *bin_exec, *render_exec;
@@ -1000,7 +1000,7 @@ vc4_job_handle_completed(struct vc4_dev *vc4)
10001000
list_del(&exec->head);
10011001

10021002
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
1003-
vc4_complete_exec(vc4->dev, exec);
1003+
vc4_complete_exec(&vc4->base, exec);
10041004
spin_lock_irqsave(&vc4->job_lock, irqflags);
10051005
}
10061006

@@ -1258,7 +1258,7 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
12581258
return 0;
12591259

12601260
fail:
1261-
vc4_complete_exec(vc4->dev, exec);
1261+
vc4_complete_exec(&vc4->base, exec);
12621262

12631263
return ret;
12641264
}

drivers/gpu/drm/vc4/vc4_v3d.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void vc4_v3d_init_hw(struct drm_device *dev)
168168

169169
int vc4_v3d_get_bin_slot(struct vc4_dev *vc4)
170170
{
171-
struct drm_device *dev = vc4->dev;
171+
struct drm_device *dev = &vc4->base;
172172
unsigned long irqflags;
173173
int slot;
174174
uint64_t seqno = 0;
@@ -246,7 +246,7 @@ static int bin_bo_alloc(struct vc4_dev *vc4)
246246
INIT_LIST_HEAD(&list);
247247

248248
while (true) {
249-
struct vc4_bo *bo = vc4_bo_create(vc4->dev, size, true,
249+
struct vc4_bo *bo = vc4_bo_create(&vc4->base, size, true,
250250
VC4_BO_TYPE_BIN);
251251

252252
if (IS_ERR(bo)) {
@@ -361,7 +361,7 @@ static int vc4_v3d_runtime_suspend(struct device *dev)
361361
struct vc4_v3d *v3d = dev_get_drvdata(dev);
362362
struct vc4_dev *vc4 = v3d->vc4;
363363

364-
vc4_irq_uninstall(vc4->dev);
364+
vc4_irq_uninstall(&vc4->base);
365365

366366
clk_disable_unprepare(v3d->clk);
367367

@@ -378,11 +378,11 @@ static int vc4_v3d_runtime_resume(struct device *dev)
378378
if (ret != 0)
379379
return ret;
380380

381-
vc4_v3d_init_hw(vc4->dev);
381+
vc4_v3d_init_hw(&vc4->base);
382382

383383
/* We disabled the IRQ as part of vc4_irq_uninstall in suspend. */
384-
enable_irq(vc4->dev->irq);
385-
vc4_irq_postinstall(vc4->dev);
384+
enable_irq(vc4->base.irq);
385+
vc4_irq_postinstall(&vc4->base);
386386

387387
return 0;
388388
}

0 commit comments

Comments
 (0)