1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright © 2017 Keith Packard <keithp@keithp.com> 4 */ 5 6 #include <drm/drmP.h> 7 #include "drm_internal.h" 8 #include "drm_legacy.h" 9 #include "drm_crtc_internal.h" 10 #include <drm/drm_lease.h> 11 #include <drm/drm_auth.h> 12 #include <drm/drm_crtc_helper.h> 13 14 #define drm_for_each_lessee(lessee, lessor) \ 15 list_for_each_entry((lessee), &(lessor)->lessees, lessee_list) 16 17 static uint64_t drm_lease_idr_object; 18 19 /** 20 * drm_lease_owner - return ancestor owner drm_master 21 * @master: drm_master somewhere within tree of lessees and lessors 22 * 23 * RETURN: 24 * 25 * drm_master at the top of the tree (i.e, with lessor NULL 26 */ 27 struct drm_master *drm_lease_owner(struct drm_master *master) 28 { 29 while (master->lessor != NULL) 30 master = master->lessor; 31 return master; 32 } 33 34 /** 35 * _drm_find_lessee - find lessee by id (idr_mutex held) 36 * @master: drm_master of lessor 37 * @lessee_id: id 38 * 39 * RETURN: 40 * 41 * drm_master of the lessee if valid, NULL otherwise 42 */ 43 44 static struct drm_master* 45 _drm_find_lessee(struct drm_master *master, int lessee_id) 46 { 47 lockdep_assert_held(&master->dev->mode_config.idr_mutex); 48 return idr_find(&drm_lease_owner(master)->lessee_idr, lessee_id); 49 } 50 51 /** 52 * _drm_lease_held_master - check to see if an object is leased (or owned) by master (idr_mutex held) 53 * @master: the master to check the lease status of 54 * @id: the id to check 55 * 56 * Checks if the specified master holds a lease on the object. Return 57 * value: 58 * 59 * true 'master' holds a lease on (or owns) the object 60 * false 'master' does not hold a lease. 61 */ 62 static int _drm_lease_held_master(struct drm_master *master, int id) 63 { 64 lockdep_assert_held(&master->dev->mode_config.idr_mutex); 65 if (master->lessor) 66 return idr_find(&master->leases, id) != NULL; 67 return true; 68 } 69 70 /** 71 * _drm_has_leased - check to see if an object has been leased (idr_mutex held) 72 * @master: the master to check the lease status of 73 * @id: the id to check 74 * 75 * Checks if any lessee of 'master' holds a lease on 'id'. Return 76 * value: 77 * 78 * true Some lessee holds a lease on the object. 79 * false No lessee has a lease on the object. 80 */ 81 static bool _drm_has_leased(struct drm_master *master, int id) 82 { 83 struct drm_master *lessee; 84 85 lockdep_assert_held(&master->dev->mode_config.idr_mutex); 86 drm_for_each_lessee(lessee, master) 87 if (_drm_lease_held_master(lessee, id)) 88 return true; 89 return false; 90 } 91 92 /** 93 * _drm_lease_held - check drm_mode_object lease status (idr_mutex held) 94 * @file_priv: the master drm_file 95 * @id: the object id 96 * 97 * Checks if the specified master holds a lease on the object. Return 98 * value: 99 * 100 * true 'master' holds a lease on (or owns) the object 101 * false 'master' does not hold a lease. 102 */ 103 bool _drm_lease_held(struct drm_file *file_priv, int id) 104 { 105 if (!file_priv || !file_priv->master) 106 return true; 107 108 return _drm_lease_held_master(file_priv->master, id); 109 } 110 111 /** 112 * drm_lease_held - check drm_mode_object lease status (idr_mutex not held) 113 * @file_priv: the master drm_file 114 * @id: the object id 115 * 116 * Checks if the specified master holds a lease on the object. Return 117 * value: 118 * 119 * true 'master' holds a lease on (or owns) the object 120 * false 'master' does not hold a lease. 121 */ 122 bool drm_lease_held(struct drm_file *file_priv, int id) 123 { 124 struct drm_master *master; 125 bool ret; 126 127 if (!file_priv || !file_priv->master || !file_priv->master->lessor) 128 return true; 129 130 master = file_priv->master; 131 mutex_lock(&master->dev->mode_config.idr_mutex); 132 ret = _drm_lease_held_master(master, id); 133 mutex_unlock(&master->dev->mode_config.idr_mutex); 134 return ret; 135 } 136 137 /** 138 * drm_lease_filter_crtcs - restricted crtc set to leased values (idr_mutex not held) 139 * @file_priv: requestor file 140 * @crtcs_in: bitmask of crtcs to check 141 * 142 * Reconstructs a crtc mask based on the crtcs which are visible 143 * through the specified file. 144 */ 145 uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs_in) 146 { 147 struct drm_master *master; 148 struct drm_device *dev; 149 struct drm_crtc *crtc; 150 int count_in, count_out; 151 uint32_t crtcs_out = 0; 152 153 if (!file_priv || !file_priv->master || !file_priv->master->lessor) 154 return crtcs_in; 155 156 master = file_priv->master; 157 dev = master->dev; 158 159 count_in = count_out = 0; 160 mutex_lock(&master->dev->mode_config.idr_mutex); 161 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 162 if (_drm_lease_held_master(master, crtc->base.id)) { 163 uint32_t mask_in = 1ul << count_in; 164 if ((crtcs_in & mask_in) != 0) { 165 uint32_t mask_out = 1ul << count_out; 166 crtcs_out |= mask_out; 167 } 168 count_out++; 169 } 170 count_in++; 171 } 172 mutex_unlock(&master->dev->mode_config.idr_mutex); 173 return crtcs_out; 174 } 175 176 /* 177 * drm_lease_create - create a new drm_master with leased objects (idr_mutex not held) 178 * @lessor: lease holder (or owner) of objects 179 * @leases: objects to lease to the new drm_master 180 * 181 * Uses drm_master_create to allocate a new drm_master, then checks to 182 * make sure all of the desired objects can be leased, atomically 183 * leasing them to the new drmmaster. 184 * 185 * ERR_PTR(-EACCES) some other master holds the title to any object 186 * ERR_PTR(-ENOENT) some object is not a valid DRM object for this device 187 * ERR_PTR(-EBUSY) some other lessee holds title to this object 188 * ERR_PTR(-EEXIST) same object specified more than once in the provided list 189 * ERR_PTR(-ENOMEM) allocation failed 190 */ 191 static struct drm_master *drm_lease_create(struct drm_master *lessor, struct idr *leases) 192 { 193 struct drm_device *dev = lessor->dev; 194 int error; 195 struct drm_master *lessee; 196 int object; 197 int id; 198 void *entry; 199 200 DRM_DEBUG_LEASE("lessor %d\n", lessor->lessee_id); 201 202 lessee = drm_master_create(lessor->dev); 203 if (!lessee) { 204 DRM_DEBUG_LEASE("drm_master_create failed\n"); 205 return ERR_PTR(-ENOMEM); 206 } 207 208 mutex_lock(&dev->mode_config.idr_mutex); 209 210 idr_for_each_entry(leases, entry, object) { 211 error = 0; 212 if (!idr_find(&dev->mode_config.object_idr, object)) 213 error = -ENOENT; 214 else if (_drm_has_leased(lessor, object)) 215 error = -EBUSY; 216 217 if (error != 0) { 218 DRM_DEBUG_LEASE("object %d failed %d\n", object, error); 219 goto out_lessee; 220 } 221 } 222 223 /* Insert the new lessee into the tree */ 224 id = idr_alloc(&(drm_lease_owner(lessor)->lessee_idr), lessee, 1, 0, GFP_KERNEL); 225 if (id < 0) { 226 error = id; 227 goto out_lessee; 228 } 229 230 lessee->lessee_id = id; 231 lessee->lessor = drm_master_get(lessor); 232 list_add_tail(&lessee->lessee_list, &lessor->lessees); 233 234 /* Move the leases over */ 235 lessee->leases = *leases; 236 DRM_DEBUG_LEASE("new lessee %d %p, lessor %d %p\n", lessee->lessee_id, lessee, lessor->lessee_id, lessor); 237 238 mutex_unlock(&dev->mode_config.idr_mutex); 239 return lessee; 240 241 out_lessee: 242 mutex_unlock(&dev->mode_config.idr_mutex); 243 244 drm_master_put(&lessee); 245 246 return ERR_PTR(error); 247 } 248 249 /** 250 * drm_lease_destroy - a master is going away (idr_mutex not held) 251 * @master: the drm_master being destroyed 252 * 253 * All lessees will have been destroyed as they 254 * hold a reference on their lessor. Notify any 255 * lessor for this master so that it can check 256 * the list of lessees. 257 */ 258 void drm_lease_destroy(struct drm_master *master) 259 { 260 struct drm_device *dev = master->dev; 261 262 mutex_lock(&dev->mode_config.idr_mutex); 263 264 DRM_DEBUG_LEASE("drm_lease_destroy %d\n", master->lessee_id); 265 266 /* This master is referenced by all lessees, hence it cannot be destroyed 267 * until all of them have been 268 */ 269 WARN_ON(!list_empty(&master->lessees)); 270 271 /* Remove this master from the lessee idr in the owner */ 272 if (master->lessee_id != 0) { 273 DRM_DEBUG_LEASE("remove master %d from device list of lessees\n", master->lessee_id); 274 idr_remove(&(drm_lease_owner(master)->lessee_idr), master->lessee_id); 275 } 276 277 /* Remove this master from any lessee list it may be on */ 278 list_del(&master->lessee_list); 279 280 mutex_unlock(&dev->mode_config.idr_mutex); 281 282 if (master->lessor) { 283 /* Tell the master to check the lessee list */ 284 drm_sysfs_lease_event(dev); 285 drm_master_put(&master->lessor); 286 } 287 288 DRM_DEBUG_LEASE("drm_lease_destroy done %d\n", master->lessee_id); 289 } 290 291 /** 292 * _drm_lease_revoke - revoke access to all leased objects (idr_mutex held) 293 * @top: the master losing its lease 294 */ 295 static void _drm_lease_revoke(struct drm_master *top) 296 { 297 int object; 298 void *entry; 299 struct drm_master *master = top; 300 301 lockdep_assert_held(&top->dev->mode_config.idr_mutex); 302 303 /* 304 * Walk the tree starting at 'top' emptying all leases. Because 305 * the tree is fully connected, we can do this without recursing 306 */ 307 for (;;) { 308 DRM_DEBUG_LEASE("revoke leases for %p %d\n", master, master->lessee_id); 309 310 /* Evacuate the lease */ 311 idr_for_each_entry(&master->leases, entry, object) 312 idr_remove(&master->leases, object); 313 314 /* Depth-first list walk */ 315 316 /* Down */ 317 if (!list_empty(&master->lessees)) { 318 master = list_first_entry(&master->lessees, struct drm_master, lessee_list); 319 } else { 320 /* Up */ 321 while (master != top && master == list_last_entry(&master->lessor->lessees, struct drm_master, lessee_list)) 322 master = master->lessor; 323 324 if (master == top) 325 break; 326 327 /* Over */ 328 master = list_next_entry(master, lessee_list); 329 } 330 } 331 } 332 333 /** 334 * drm_lease_revoke - revoke access to all leased objects (idr_mutex not held) 335 * @top: the master losing its lease 336 */ 337 void drm_lease_revoke(struct drm_master *top) 338 { 339 mutex_lock(&top->dev->mode_config.idr_mutex); 340 _drm_lease_revoke(top); 341 mutex_unlock(&top->dev->mode_config.idr_mutex); 342 } 343 344 static int validate_lease(struct drm_device *dev, 345 int object_count, 346 struct drm_mode_object **objects, 347 bool universal_planes) 348 { 349 int o; 350 int has_crtc = -1; 351 int has_connector = -1; 352 int has_plane = -1; 353 354 /* we want to confirm that there is at least one crtc, plane 355 connector object. */ 356 357 for (o = 0; o < object_count; o++) { 358 if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) { 359 has_crtc = o; 360 } 361 if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1) 362 has_connector = o; 363 364 if (universal_planes) { 365 if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1) 366 has_plane = o; 367 } 368 } 369 if (has_crtc == -1 || has_connector == -1) 370 return -EINVAL; 371 if (universal_planes && has_plane == -1) 372 return -EINVAL; 373 return 0; 374 } 375 376 static int fill_object_idr(struct drm_device *dev, 377 struct drm_file *lessor_priv, 378 struct idr *leases, 379 int object_count, 380 u32 *object_ids) 381 { 382 struct drm_mode_object **objects; 383 u32 o; 384 int ret; 385 bool universal_planes = READ_ONCE(lessor_priv->universal_planes); 386 387 objects = kcalloc(object_count, sizeof(struct drm_mode_object *), 388 GFP_KERNEL); 389 if (!objects) 390 return -ENOMEM; 391 392 /* step one - get references to all the mode objects 393 and check for validity. */ 394 for (o = 0; o < object_count; o++) { 395 objects[o] = drm_mode_object_find(dev, lessor_priv, 396 object_ids[o], 397 DRM_MODE_OBJECT_ANY); 398 if (!objects[o]) { 399 ret = -ENOENT; 400 goto out_free_objects; 401 } 402 403 if (!drm_mode_object_lease_required(objects[o]->type)) { 404 DRM_DEBUG_KMS("invalid object for lease\n"); 405 ret = -EINVAL; 406 goto out_free_objects; 407 } 408 } 409 410 ret = validate_lease(dev, object_count, objects, universal_planes); 411 if (ret) { 412 DRM_DEBUG_LEASE("lease validation failed\n"); 413 goto out_free_objects; 414 } 415 416 /* add their IDs to the lease request - taking into account 417 universal planes */ 418 for (o = 0; o < object_count; o++) { 419 struct drm_mode_object *obj = objects[o]; 420 u32 object_id = objects[o]->id; 421 DRM_DEBUG_LEASE("Adding object %d to lease\n", object_id); 422 423 /* 424 * We're using an IDR to hold the set of leased 425 * objects, but we don't need to point at the object's 426 * data structure from the lease as the main object_idr 427 * will be used to actually find that. Instead, all we 428 * really want is a 'leased/not-leased' result, for 429 * which any non-NULL pointer will work fine. 430 */ 431 ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL); 432 if (ret < 0) { 433 DRM_DEBUG_LEASE("Object %d cannot be inserted into leases (%d)\n", 434 object_id, ret); 435 goto out_free_objects; 436 } 437 if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) { 438 struct drm_crtc *crtc = obj_to_crtc(obj); 439 ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL); 440 if (ret < 0) { 441 DRM_DEBUG_LEASE("Object primary plane %d cannot be inserted into leases (%d)\n", 442 object_id, ret); 443 goto out_free_objects; 444 } 445 if (crtc->cursor) { 446 ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL); 447 if (ret < 0) { 448 DRM_DEBUG_LEASE("Object cursor plane %d cannot be inserted into leases (%d)\n", 449 object_id, ret); 450 goto out_free_objects; 451 } 452 } 453 } 454 } 455 456 ret = 0; 457 out_free_objects: 458 for (o = 0; o < object_count; o++) { 459 if (objects[o]) 460 drm_mode_object_put(objects[o]); 461 } 462 kfree(objects); 463 return ret; 464 } 465 466 /** 467 * drm_mode_create_lease_ioctl - create a new lease 468 * @dev: the drm device 469 * @data: pointer to struct drm_mode_create_lease 470 * @lessor_priv: the file being manipulated 471 * 472 * The master associated with the specified file will have a lease 473 * created containing the objects specified in the ioctl structure. 474 * A file descriptor will be allocated for that and returned to the 475 * application. 476 */ 477 int drm_mode_create_lease_ioctl(struct drm_device *dev, 478 void *data, struct drm_file *lessor_priv) 479 { 480 struct drm_mode_create_lease *cl = data; 481 size_t object_count; 482 int ret = 0; 483 struct idr leases; 484 struct drm_master *lessor = lessor_priv->master; 485 struct drm_master *lessee = NULL; 486 struct file *lessee_file = NULL; 487 struct file *lessor_file = lessor_priv->filp; 488 struct drm_file *lessee_priv; 489 int fd = -1; 490 uint32_t *object_ids; 491 492 /* Can't lease without MODESET */ 493 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 494 return -EOPNOTSUPP; 495 496 /* Do not allow sub-leases */ 497 if (lessor->lessor) { 498 DRM_DEBUG_LEASE("recursive leasing not allowed\n"); 499 return -EINVAL; 500 } 501 502 /* need some objects */ 503 if (cl->object_count == 0) { 504 DRM_DEBUG_LEASE("no objects in lease\n"); 505 return -EINVAL; 506 } 507 508 if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) { 509 DRM_DEBUG_LEASE("invalid flags\n"); 510 return -EINVAL; 511 } 512 513 object_count = cl->object_count; 514 515 object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), 516 array_size(object_count, sizeof(__u32))); 517 if (IS_ERR(object_ids)) 518 return PTR_ERR(object_ids); 519 520 idr_init(&leases); 521 522 /* fill and validate the object idr */ 523 ret = fill_object_idr(dev, lessor_priv, &leases, 524 object_count, object_ids); 525 kfree(object_ids); 526 if (ret) { 527 DRM_DEBUG_LEASE("lease object lookup failed: %i\n", ret); 528 idr_destroy(&leases); 529 return ret; 530 } 531 532 /* Allocate a file descriptor for the lease */ 533 fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK)); 534 if (fd < 0) { 535 idr_destroy(&leases); 536 return fd; 537 } 538 539 DRM_DEBUG_LEASE("Creating lease\n"); 540 lessee = drm_lease_create(lessor, &leases); 541 542 if (IS_ERR(lessee)) { 543 ret = PTR_ERR(lessee); 544 goto out_leases; 545 } 546 547 /* Clone the lessor file to create a new file for us */ 548 DRM_DEBUG_LEASE("Allocating lease file\n"); 549 lessee_file = file_clone_open(lessor_file); 550 if (IS_ERR(lessee_file)) { 551 ret = PTR_ERR(lessee_file); 552 goto out_lessee; 553 } 554 555 lessee_priv = lessee_file->private_data; 556 /* Change the file to a master one */ 557 drm_master_put(&lessee_priv->master); 558 lessee_priv->master = lessee; 559 lessee_priv->is_master = 1; 560 lessee_priv->authenticated = 1; 561 562 /* Pass fd back to userspace */ 563 DRM_DEBUG_LEASE("Returning fd %d id %d\n", fd, lessee->lessee_id); 564 cl->fd = fd; 565 cl->lessee_id = lessee->lessee_id; 566 567 /* Hook up the fd */ 568 fd_install(fd, lessee_file); 569 570 DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl succeeded\n"); 571 return 0; 572 573 out_lessee: 574 drm_master_put(&lessee); 575 576 out_leases: 577 put_unused_fd(fd); 578 idr_destroy(&leases); 579 580 DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl failed: %d\n", ret); 581 return ret; 582 } 583 584 /** 585 * drm_mode_list_lessees_ioctl - list lessee ids 586 * @dev: the drm device 587 * @data: pointer to struct drm_mode_list_lessees 588 * @lessor_priv: the file being manipulated 589 * 590 * Starting from the master associated with the specified file, 591 * the master with the provided lessee_id is found, and then 592 * an array of lessee ids associated with leases from that master 593 * are returned. 594 */ 595 596 int drm_mode_list_lessees_ioctl(struct drm_device *dev, 597 void *data, struct drm_file *lessor_priv) 598 { 599 struct drm_mode_list_lessees *arg = data; 600 __u32 __user *lessee_ids = (__u32 __user *) (uintptr_t) (arg->lessees_ptr); 601 __u32 count_lessees = arg->count_lessees; 602 struct drm_master *lessor = lessor_priv->master, *lessee; 603 int count; 604 int ret = 0; 605 606 if (arg->pad) 607 return -EINVAL; 608 609 /* Can't lease without MODESET */ 610 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 611 return -EOPNOTSUPP; 612 613 DRM_DEBUG_LEASE("List lessees for %d\n", lessor->lessee_id); 614 615 mutex_lock(&dev->mode_config.idr_mutex); 616 617 count = 0; 618 drm_for_each_lessee(lessee, lessor) { 619 /* Only list un-revoked leases */ 620 if (!idr_is_empty(&lessee->leases)) { 621 if (count_lessees > count) { 622 DRM_DEBUG_LEASE("Add lessee %d\n", lessee->lessee_id); 623 ret = put_user(lessee->lessee_id, lessee_ids + count); 624 if (ret) 625 break; 626 } 627 count++; 628 } 629 } 630 631 DRM_DEBUG_LEASE("Lessor leases to %d\n", count); 632 if (ret == 0) 633 arg->count_lessees = count; 634 635 mutex_unlock(&dev->mode_config.idr_mutex); 636 637 return ret; 638 } 639 640 /** 641 * drm_mode_get_lease_ioctl - list leased objects 642 * @dev: the drm device 643 * @data: pointer to struct drm_mode_get_lease 644 * @lessee_priv: the file being manipulated 645 * 646 * Return the list of leased objects for the specified lessee 647 */ 648 649 int drm_mode_get_lease_ioctl(struct drm_device *dev, 650 void *data, struct drm_file *lessee_priv) 651 { 652 struct drm_mode_get_lease *arg = data; 653 __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr); 654 __u32 count_objects = arg->count_objects; 655 struct drm_master *lessee = lessee_priv->master; 656 struct idr *object_idr; 657 int count; 658 void *entry; 659 int object; 660 int ret = 0; 661 662 if (arg->pad) 663 return -EINVAL; 664 665 /* Can't lease without MODESET */ 666 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 667 return -EOPNOTSUPP; 668 669 DRM_DEBUG_LEASE("get lease for %d\n", lessee->lessee_id); 670 671 mutex_lock(&dev->mode_config.idr_mutex); 672 673 if (lessee->lessor == NULL) 674 /* owner can use all objects */ 675 object_idr = &lessee->dev->mode_config.object_idr; 676 else 677 /* lessee can only use allowed object */ 678 object_idr = &lessee->leases; 679 680 count = 0; 681 idr_for_each_entry(object_idr, entry, object) { 682 if (count_objects > count) { 683 DRM_DEBUG_LEASE("adding object %d\n", object); 684 ret = put_user(object, object_ids + count); 685 if (ret) 686 break; 687 } 688 count++; 689 } 690 691 DRM_DEBUG("lease holds %d objects\n", count); 692 if (ret == 0) 693 arg->count_objects = count; 694 695 mutex_unlock(&dev->mode_config.idr_mutex); 696 697 return ret; 698 } 699 700 /** 701 * drm_mode_revoke_lease_ioctl - revoke lease 702 * @dev: the drm device 703 * @data: pointer to struct drm_mode_revoke_lease 704 * @lessor_priv: the file being manipulated 705 * 706 * This removes all of the objects from the lease without 707 * actually getting rid of the lease itself; that way all 708 * references to it still work correctly 709 */ 710 int drm_mode_revoke_lease_ioctl(struct drm_device *dev, 711 void *data, struct drm_file *lessor_priv) 712 { 713 struct drm_mode_revoke_lease *arg = data; 714 struct drm_master *lessor = lessor_priv->master; 715 struct drm_master *lessee; 716 int ret = 0; 717 718 DRM_DEBUG_LEASE("revoke lease for %d\n", arg->lessee_id); 719 720 /* Can't lease without MODESET */ 721 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 722 return -EOPNOTSUPP; 723 724 mutex_lock(&dev->mode_config.idr_mutex); 725 726 lessee = _drm_find_lessee(lessor, arg->lessee_id); 727 728 /* No such lessee */ 729 if (!lessee) { 730 ret = -ENOENT; 731 goto fail; 732 } 733 734 /* Lease is not held by lessor */ 735 if (lessee->lessor != lessor) { 736 ret = -EACCES; 737 goto fail; 738 } 739 740 _drm_lease_revoke(lessee); 741 742 fail: 743 mutex_unlock(&dev->mode_config.idr_mutex); 744 745 return ret; 746 } 747