@@ -51,6 +51,20 @@ struct drm_exec {
51
51
struct drm_gem_object * prelocked ;
52
52
};
53
53
54
+ /**
55
+ * drm_exec_obj() - Return the object for a give drm_exec index
56
+ * @exec: Pointer to the drm_exec context
57
+ * @index: The index.
58
+ *
59
+ * Return: Pointer to the locked object corresponding to @index if
60
+ * index is within the number of locked objects. NULL otherwise.
61
+ */
62
+ static inline struct drm_gem_object *
63
+ drm_exec_obj (struct drm_exec * exec , unsigned long index )
64
+ {
65
+ return index < exec -> num_objects ? exec -> objects [index ] : NULL ;
66
+ }
67
+
54
68
/**
55
69
* drm_exec_for_each_locked_object - iterate over all the locked objects
56
70
* @exec: drm_exec object
@@ -59,10 +73,23 @@ struct drm_exec {
59
73
*
60
74
* Iterate over all the locked GEM objects inside the drm_exec object.
61
75
*/
62
- #define drm_exec_for_each_locked_object (exec , index , obj ) \
63
- for (index = 0, obj = (exec)->objects[0]; \
64
- index < (exec)->num_objects; \
65
- ++index, obj = (exec)->objects[index])
76
+ #define drm_exec_for_each_locked_object (exec , index , obj ) \
77
+ for ((index) = 0; ((obj) = drm_exec_obj(exec, index)); ++(index))
78
+
79
+ /**
80
+ * drm_exec_for_each_locked_object_reverse - iterate over all the locked
81
+ * objects in reverse locking order
82
+ * @exec: drm_exec object
83
+ * @index: unsigned long index for the iteration
84
+ * @obj: the current GEM object
85
+ *
86
+ * Iterate over all the locked GEM objects inside the drm_exec object in
87
+ * reverse locking order. Note that @index may go below zero and wrap,
88
+ * but that will be caught by drm_exec_obj(), returning a NULL object.
89
+ */
90
+ #define drm_exec_for_each_locked_object_reverse (exec , index , obj ) \
91
+ for ((index) = (exec)->num_objects - 1; \
92
+ ((obj) = drm_exec_obj(exec, index)); --(index))
66
93
67
94
/**
68
95
* drm_exec_until_all_locked - loop until all GEM objects are locked
0 commit comments