Home | History | Annotate | Line # | Download | only in drm
drm_auth.c revision 1.3
      1 /*	$NetBSD: drm_auth.c,v 1.3 2018/08/27 04:58:19 riastradh Exp $	*/
      2 
      3 /*
      4  * Created: Tue Feb  2 08:37:54 1999 by faith (at) valinux.com
      5  *
      6  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
      7  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
      8  * All Rights Reserved.
      9  *
     10  * Author Rickard E. (Rik) Faith <faith (at) valinux.com>
     11  * Author Gareth Hughes <gareth (at) valinux.com>
     12  *
     13  * Permission is hereby granted, free of charge, to any person obtaining a
     14  * copy of this software and associated documentation files (the "Software"),
     15  * to deal in the Software without restriction, including without limitation
     16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     17  * and/or sell copies of the Software, and to permit persons to whom the
     18  * Software is furnished to do so, subject to the following conditions:
     19  *
     20  * The above copyright notice and this permission notice (including the next
     21  * paragraph) shall be included in all copies or substantial portions of the
     22  * Software.
     23  *
     24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     27  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     28  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     29  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     30  * OTHER DEALINGS IN THE SOFTWARE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: drm_auth.c,v 1.3 2018/08/27 04:58:19 riastradh Exp $");
     35 
     36 #include <drm/drmP.h>
     37 #include "drm_internal.h"
     38 
     39 /**
     40  * drm_getmagic - Get unique magic of a client
     41  * @dev: DRM device to operate on
     42  * @data: ioctl data containing the drm_auth object
     43  * @file_priv: DRM file that performs the operation
     44  *
     45  * This looks up the unique magic of the passed client and returns it. If the
     46  * client did not have a magic assigned, yet, a new one is registered. The magic
     47  * is stored in the passed drm_auth object.
     48  *
     49  * Returns: 0 on success, negative error code on failure.
     50  */
     51 int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
     52 {
     53 	struct drm_auth *auth = data;
     54 	int ret = 0;
     55 
     56 	mutex_lock(&dev->struct_mutex);
     57 	if (!file_priv->magic) {
     58 		ret = idr_alloc(&file_priv->master->magic_map, file_priv,
     59 				1, 0, GFP_KERNEL);
     60 		if (ret >= 0)
     61 			file_priv->magic = ret;
     62 	}
     63 	auth->magic = file_priv->magic;
     64 	mutex_unlock(&dev->struct_mutex);
     65 
     66 	DRM_DEBUG("%u\n", auth->magic);
     67 
     68 	return ret < 0 ? ret : 0;
     69 }
     70 
     71 /**
     72  * drm_authmagic - Authenticate client with a magic
     73  * @dev: DRM device to operate on
     74  * @data: ioctl data containing the drm_auth object
     75  * @file_priv: DRM file that performs the operation
     76  *
     77  * This looks up a DRM client by the passed magic and authenticates it.
     78  *
     79  * Returns: 0 on success, negative error code on failure.
     80  */
     81 int drm_authmagic(struct drm_device *dev, void *data,
     82 		  struct drm_file *file_priv)
     83 {
     84 	struct drm_auth *auth = data;
     85 	struct drm_file *file;
     86 
     87 	DRM_DEBUG("%u\n", auth->magic);
     88 
     89 	mutex_lock(&dev->struct_mutex);
     90 	file = idr_find(&file_priv->master->magic_map, auth->magic);
     91 	if (file) {
     92 		file->authenticated = 1;
     93 		idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
     94 	}
     95 	mutex_unlock(&dev->struct_mutex);
     96 
     97 	return file ? 0 : -EINVAL;
     98 }
     99