@@ -394,6 +394,31 @@ static void drm_mode_rmfb_work_fn(struct work_struct *w)
394
394
}
395
395
}
396
396
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
+
397
422
/**
398
423
* drm_mode_rmfb - remove an FB from the configuration
399
424
* @dev: drm device
@@ -410,9 +435,8 @@ static void drm_mode_rmfb_work_fn(struct work_struct *w)
410
435
int drm_mode_rmfb (struct drm_device * dev , u32 fb_id ,
411
436
struct drm_file * file_priv )
412
437
{
413
- struct drm_framebuffer * fb = NULL ;
414
- struct drm_framebuffer * fbl = NULL ;
415
- int found = 0 ;
438
+ struct drm_framebuffer * fb ;
439
+ int ret ;
416
440
417
441
if (!drm_core_check_feature (dev , DRIVER_MODESET ))
418
442
return - EOPNOTSUPP ;
@@ -421,24 +445,13 @@ int drm_mode_rmfb(struct drm_device *dev, u32 fb_id,
421
445
if (!fb )
422
446
return - ENOENT ;
423
447
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 ;
431
452
}
432
453
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
-
439
454
/*
440
- * we now own the reference that was stored in the fbs list
441
- *
442
455
* drm_framebuffer_remove may fail with -EINTR on pending signals,
443
456
* so run this in a separate stack as there's no way to correctly
444
457
* 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,
457
470
drm_framebuffer_put (fb );
458
471
459
472
return 0 ;
460
-
461
- fail_unref :
462
- drm_framebuffer_put (fb );
463
- return - ENOENT ;
464
473
}
465
474
466
475
int drm_mode_rmfb_ioctl (struct drm_device * dev ,
0 commit comments