.llseek = noop_llseek,
  };
  
- static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file)
 +static int tegra_drm_context_cleanup(int id, void *p, void *data)
 +{
 +      struct tegra_drm_context *context = p;
 +
 +      tegra_drm_context_free(context);
 +
 +      return 0;
 +}
 +
+ static void tegra_drm_postclose(struct drm_device *drm, struct drm_file *file)
  {
        struct tegra_drm_file *fpriv = file->driver_priv;
 -      struct tegra_drm_context *context, *tmp;
  
 -      list_for_each_entry_safe(context, tmp, &fpriv->contexts, list)
 -              tegra_drm_context_free(context);
 +      mutex_lock(&fpriv->lock);
 +      idr_for_each(&fpriv->contexts, tegra_drm_context_cleanup, NULL);
 +      mutex_unlock(&fpriv->lock);
  
 +      idr_destroy(&fpriv->contexts);
 +      mutex_destroy(&fpriv->lock);
        kfree(fpriv);
  }