Skip to content

Commit 0226ba3

Browse files
committed
drm: extract closefb logic in separate function
drm_mode_rmfb performs two operations: drop the FB from the file_priv->fbs list, and make sure the FB is no longer used on a plane. In the next commit an IOCTL which only does so former will be introduced, so let's split it into a separate function. No functional change, only refactoring. v2: no change Signed-off-by: Simon Ser <[email protected]> Cc: Hans de Goede <[email protected]> Cc: Dennis Filder <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: Pekka Paalanen <[email protected]> Cc: Rob Clark <[email protected]> Cc: Sean Paul <[email protected]> Reviewed-by: Daniel Stone <[email protected]> Reviewed-by: Ville Syrjälä <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 80683bf commit 0226ba3

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

drivers/gpu/drm/drm_framebuffer.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,31 @@ static void drm_mode_rmfb_work_fn(struct work_struct *w)
394394
}
395395
}
396396

397+
static int drm_mode_closefb(struct drm_framebuffer *fb,
398+
struct drm_file *file_priv)
399+
{
400+
struct drm_framebuffer *fbl;
401+
bool found = false;
402+
403+
mutex_lock(&file_priv->fbs_lock);
404+
list_for_each_entry(fbl, &file_priv->fbs, filp_head)
405+
if (fb == fbl)
406+
found = true;
407+
408+
if (!found) {
409+
mutex_unlock(&file_priv->fbs_lock);
410+
return -ENOENT;
411+
}
412+
413+
list_del_init(&fb->filp_head);
414+
mutex_unlock(&file_priv->fbs_lock);
415+
416+
/* Drop the reference that was stored in the fbs list */
417+
drm_framebuffer_put(fb);
418+
419+
return 0;
420+
}
421+
397422
/**
398423
* drm_mode_rmfb - remove an FB from the configuration
399424
* @dev: drm device
@@ -410,9 +435,8 @@ static void drm_mode_rmfb_work_fn(struct work_struct *w)
410435
int drm_mode_rmfb(struct drm_device *dev, u32 fb_id,
411436
struct drm_file *file_priv)
412437
{
413-
struct drm_framebuffer *fb = NULL;
414-
struct drm_framebuffer *fbl = NULL;
415-
int found = 0;
438+
struct drm_framebuffer *fb;
439+
int ret;
416440

417441
if (!drm_core_check_feature(dev, DRIVER_MODESET))
418442
return -EOPNOTSUPP;
@@ -421,24 +445,13 @@ int drm_mode_rmfb(struct drm_device *dev, u32 fb_id,
421445
if (!fb)
422446
return -ENOENT;
423447

424-
mutex_lock(&file_priv->fbs_lock);
425-
list_for_each_entry(fbl, &file_priv->fbs, filp_head)
426-
if (fb == fbl)
427-
found = 1;
428-
if (!found) {
429-
mutex_unlock(&file_priv->fbs_lock);
430-
goto fail_unref;
448+
ret = drm_mode_closefb(fb, file_priv);
449+
if (ret != 0) {
450+
drm_framebuffer_put(fb);
451+
return ret;
431452
}
432453

433-
list_del_init(&fb->filp_head);
434-
mutex_unlock(&file_priv->fbs_lock);
435-
436-
/* drop the reference we picked up in framebuffer lookup */
437-
drm_framebuffer_put(fb);
438-
439454
/*
440-
* we now own the reference that was stored in the fbs list
441-
*
442455
* drm_framebuffer_remove may fail with -EINTR on pending signals,
443456
* so run this in a separate stack as there's no way to correctly
444457
* handle this after the fb is already removed from the lookup table.
@@ -457,10 +470,6 @@ int drm_mode_rmfb(struct drm_device *dev, u32 fb_id,
457470
drm_framebuffer_put(fb);
458471

459472
return 0;
460-
461-
fail_unref:
462-
drm_framebuffer_put(fb);
463-
return -ENOENT;
464473
}
465474

466475
int drm_mode_rmfb_ioctl(struct drm_device *dev,

0 commit comments

Comments
 (0)