drm_lease_held() only answers whether a given object is part of a lease, and the answer can change from one call to the next. Code that needs to look at several objects in a row has no way to tell whether the lease it has been checking against is still around by the time it is done.
Add a helper reporting whether a lease has been revoked, so that such code can bail out instead of acting on a lease that went away. Signed-off-by: Maxime Ripard <[email protected]> --- drivers/gpu/drm/drm_lease.c | 26 ++++++++++++++++++++++++++ include/drm/drm_lease.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c index 5d2cf724cbd7..dd59df14dcc0 100644 --- a/drivers/gpu/drm/drm_lease.c +++ b/drivers/gpu/drm/drm_lease.c @@ -145,10 +145,36 @@ bool drm_lease_held(struct drm_file *file_priv, int id) out: drm_master_put(&master); return ret; } +/* + * Checks whether the file is a lessee whose lease has been revoked. A + * lease is always revoked as a whole, so an empty one has been revoked. + */ +bool drm_lease_revoked(struct drm_file *file_priv) +{ + struct drm_master *master; + bool ret = false; + + if (!file_priv) + return false; + + master = drm_file_get_master(file_priv); + if (!master) + return false; + + if (master->lessor) { + mutex_lock(&master->dev->mode_config.idr_mutex); + ret = idr_is_empty(&master->leases); + mutex_unlock(&master->dev->mode_config.idr_mutex); + } + + drm_master_put(&master); + return ret; +} + /* * Given a bitmask of crtcs to check, reconstructs a crtc mask based on the * crtcs which are visible through the specified file. */ uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs_in) diff --git a/include/drm/drm_lease.h b/include/drm/drm_lease.h index 53545b4ca9ef..03f7ea36c37c 100644 --- a/include/drm/drm_lease.h +++ b/include/drm/drm_lease.h @@ -18,10 +18,12 @@ void drm_lease_destroy(struct drm_master *lessee); bool drm_lease_held(struct drm_file *file_priv, int id); bool _drm_lease_held(struct drm_file *file_priv, int id); +bool drm_lease_revoked(struct drm_file *file_priv); + void drm_lease_revoke(struct drm_master *master); uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs); int drm_mode_create_lease_ioctl(struct drm_device *dev, -- 2.56.1
