![]() |
|
|||
0001 // SPDX-License-Identifier: GPL-2.0 0002 0003 #ifndef _DRM_MANAGED_H_ 0004 #define _DRM_MANAGED_H_ 0005 0006 #include <linux/gfp.h> 0007 #include <linux/overflow.h> 0008 #include <linux/types.h> 0009 0010 struct drm_device; 0011 struct mutex; 0012 0013 typedef void (*drmres_release_t)(struct drm_device *dev, void *res); 0014 0015 /** 0016 * drmm_add_action - add a managed release action to a &drm_device 0017 * @dev: DRM device 0018 * @action: function which should be called when @dev is released 0019 * @data: opaque pointer, passed to @action 0020 * 0021 * This function adds the @release action with optional parameter @data to the 0022 * list of cleanup actions for @dev. The cleanup actions will be run in reverse 0023 * order in the final drm_dev_put() call for @dev. 0024 */ 0025 #define drmm_add_action(dev, action, data) \ 0026 __drmm_add_action(dev, action, data, #action) 0027 0028 int __must_check __drmm_add_action(struct drm_device *dev, 0029 drmres_release_t action, 0030 void *data, const char *name); 0031 0032 /** 0033 * drmm_add_action_or_reset - add a managed release action to a &drm_device 0034 * @dev: DRM device 0035 * @action: function which should be called when @dev is released 0036 * @data: opaque pointer, passed to @action 0037 * 0038 * Similar to drmm_add_action(), with the only difference that upon failure 0039 * @action is directly called for any cleanup work necessary on failures. 0040 */ 0041 #define drmm_add_action_or_reset(dev, action, data) \ 0042 __drmm_add_action_or_reset(dev, action, data, #action) 0043 0044 int __must_check __drmm_add_action_or_reset(struct drm_device *dev, 0045 drmres_release_t action, 0046 void *data, const char *name); 0047 0048 void *drmm_kmalloc(struct drm_device *dev, size_t size, gfp_t gfp) __malloc; 0049 0050 /** 0051 * drmm_kzalloc - &drm_device managed kzalloc() 0052 * @dev: DRM device 0053 * @size: size of the memory allocation 0054 * @gfp: GFP allocation flags 0055 * 0056 * This is a &drm_device managed version of kzalloc(). The allocated memory is 0057 * automatically freed on the final drm_dev_put(). Memory can also be freed 0058 * before the final drm_dev_put() by calling drmm_kfree(). 0059 */ 0060 static inline void *drmm_kzalloc(struct drm_device *dev, size_t size, gfp_t gfp) 0061 { 0062 return drmm_kmalloc(dev, size, gfp | __GFP_ZERO); 0063 } 0064 0065 /** 0066 * drmm_kmalloc_array - &drm_device managed kmalloc_array() 0067 * @dev: DRM device 0068 * @n: number of array elements to allocate 0069 * @size: size of array member 0070 * @flags: GFP allocation flags 0071 * 0072 * This is a &drm_device managed version of kmalloc_array(). The allocated 0073 * memory is automatically freed on the final drm_dev_put() and works exactly 0074 * like a memory allocation obtained by drmm_kmalloc(). 0075 */ 0076 static inline void *drmm_kmalloc_array(struct drm_device *dev, 0077 size_t n, size_t size, gfp_t flags) 0078 { 0079 size_t bytes; 0080 0081 if (unlikely(check_mul_overflow(n, size, &bytes))) 0082 return NULL; 0083 0084 return drmm_kmalloc(dev, bytes, flags); 0085 } 0086 0087 /** 0088 * drmm_kcalloc - &drm_device managed kcalloc() 0089 * @dev: DRM device 0090 * @n: number of array elements to allocate 0091 * @size: size of array member 0092 * @flags: GFP allocation flags 0093 * 0094 * This is a &drm_device managed version of kcalloc(). The allocated memory is 0095 * automatically freed on the final drm_dev_put() and works exactly like a 0096 * memory allocation obtained by drmm_kmalloc(). 0097 */ 0098 static inline void *drmm_kcalloc(struct drm_device *dev, 0099 size_t n, size_t size, gfp_t flags) 0100 { 0101 return drmm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); 0102 } 0103 0104 char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp); 0105 0106 void drmm_kfree(struct drm_device *dev, void *data); 0107 0108 int drmm_mutex_init(struct drm_device *dev, struct mutex *lock); 0109 0110 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |