Skip to content

Commit ec9f932

Browse files
mlankhorstdanvet
authored andcommitted
drm/atomic: Cleanup on error properly in the atomic ioctl.
It's probably allowed to leave old_fb set to garbage when unlocking, but to prevent undefined behavior unset it just in case. Also crtc_state->event could be NULL on memory allocation failure, in which case event_space is increased for no reason. Note: Contains some general simplification of the cleanup code too. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> [danvet: Add note about the other changes in here. And fix long line while at it.] Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 3cb43cc commit ec9f932

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

drivers/gpu/drm/drm_atomic.c

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,18 +1463,18 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
14631463

14641464
if (get_user(obj_id, objs_ptr + copied_objs)) {
14651465
ret = -EFAULT;
1466-
goto fail;
1466+
goto out;
14671467
}
14681468

14691469
obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_ANY);
14701470
if (!obj || !obj->properties) {
14711471
ret = -ENOENT;
1472-
goto fail;
1472+
goto out;
14731473
}
14741474

14751475
if (get_user(count_props, count_props_ptr + copied_objs)) {
14761476
ret = -EFAULT;
1477-
goto fail;
1477+
goto out;
14781478
}
14791479

14801480
copied_objs++;
@@ -1486,25 +1486,25 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
14861486

14871487
if (get_user(prop_id, props_ptr + copied_props)) {
14881488
ret = -EFAULT;
1489-
goto fail;
1489+
goto out;
14901490
}
14911491

14921492
prop = drm_property_find(dev, prop_id);
14931493
if (!prop) {
14941494
ret = -ENOENT;
1495-
goto fail;
1495+
goto out;
14961496
}
14971497

14981498
if (copy_from_user(&prop_value,
14991499
prop_values_ptr + copied_props,
15001500
sizeof(prop_value))) {
15011501
ret = -EFAULT;
1502-
goto fail;
1502+
goto out;
15031503
}
15041504

15051505
ret = atomic_set_prop(state, obj, prop, prop_value);
15061506
if (ret)
1507-
goto fail;
1507+
goto out;
15081508

15091509
copied_props++;
15101510
}
@@ -1523,7 +1523,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
15231523
e = create_vblank_event(dev, file_priv, arg->user_data);
15241524
if (!e) {
15251525
ret = -ENOMEM;
1526-
goto fail;
1526+
goto out;
15271527
}
15281528

15291529
crtc_state->event = e;
@@ -1533,13 +1533,15 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
15331533
if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) {
15341534
ret = drm_atomic_check_only(state);
15351535
/* _check_only() does not free state, unlike _commit() */
1536-
drm_atomic_state_free(state);
1536+
if (!ret)
1537+
drm_atomic_state_free(state);
15371538
} else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) {
15381539
ret = drm_atomic_async_commit(state);
15391540
} else {
15401541
ret = drm_atomic_commit(state);
15411542
}
15421543

1544+
out:
15431545
/* if succeeded, fixup legacy plane crtc/fb ptrs before dropping
15441546
* locks (ie. while it is still safe to deref plane->state). We
15451547
* need to do this here because the driver entry points cannot
@@ -1552,41 +1554,35 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
15521554
drm_framebuffer_reference(new_fb);
15531555
plane->fb = new_fb;
15541556
plane->crtc = plane->state->crtc;
1555-
} else {
1556-
plane->old_fb = NULL;
1557-
}
1558-
if (plane->old_fb) {
1559-
drm_framebuffer_unreference(plane->old_fb);
1560-
plane->old_fb = NULL;
1557+
1558+
if (plane->old_fb)
1559+
drm_framebuffer_unreference(plane->old_fb);
15611560
}
1561+
plane->old_fb = NULL;
15621562
}
15631563

1564-
drm_modeset_drop_locks(&ctx);
1565-
drm_modeset_acquire_fini(&ctx);
1566-
1567-
return ret;
1564+
if (ret == -EDEADLK) {
1565+
drm_atomic_state_clear(state);
1566+
drm_modeset_backoff(&ctx);
1567+
goto retry;
1568+
}
15681569

1569-
fail:
1570-
if (ret == -EDEADLK)
1571-
goto backoff;
1570+
if (ret) {
1571+
if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
1572+
for_each_crtc_in_state(state, crtc, crtc_state, i) {
1573+
if (!crtc_state->event)
1574+
continue;
15721575

1573-
if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
1574-
for_each_crtc_in_state(state, crtc, crtc_state, i) {
1575-
destroy_vblank_event(dev, file_priv, crtc_state->event);
1576-
crtc_state->event = NULL;
1576+
destroy_vblank_event(dev, file_priv,
1577+
crtc_state->event);
1578+
}
15771579
}
1578-
}
15791580

1580-
drm_atomic_state_free(state);
1581+
drm_atomic_state_free(state);
1582+
}
15811583

15821584
drm_modeset_drop_locks(&ctx);
15831585
drm_modeset_acquire_fini(&ctx);
15841586

15851587
return ret;
1586-
1587-
backoff:
1588-
drm_atomic_state_clear(state);
1589-
drm_modeset_backoff(&ctx);
1590-
1591-
goto retry;
15921588
}

0 commit comments

Comments
 (0)