@@ -69,6 +69,46 @@ eb_add_object(struct eb_objects *eb, struct drm_i915_gem_object *obj)
6969 & eb -> buckets [obj -> exec_handle & eb -> and ]);
7070}
7171
72+ static int
73+ eb_lookup_objects (struct eb_objects * eb ,
74+ struct drm_i915_gem_exec_object2 * exec ,
75+ int count ,
76+ struct drm_file * file ,
77+ struct list_head * objects )
78+ {
79+ int i ;
80+
81+ spin_lock (& file -> table_lock );
82+ for (i = 0 ; i < count ; i ++ ) {
83+ struct drm_i915_gem_object * obj ;
84+
85+ obj = to_intel_bo (idr_find (& file -> object_idr , exec [i ].handle ));
86+ if (obj == NULL ) {
87+ spin_unlock (& file -> table_lock );
88+ DRM_DEBUG ("Invalid object handle %d at index %d\n" ,
89+ exec [i ].handle , i );
90+ return - ENOENT ;
91+ }
92+
93+ if (!list_empty (& obj -> exec_list )) {
94+ spin_unlock (& file -> table_lock );
95+ DRM_DEBUG ("Object %p [handle %d, index %d] appears more than once in object list\n" ,
96+ obj , exec [i ].handle , i );
97+ return - EINVAL ;
98+ }
99+
100+ drm_gem_object_reference (& obj -> base );
101+ list_add_tail (& obj -> exec_list , objects );
102+
103+ obj -> exec_handle = exec [i ].handle ;
104+ obj -> exec_entry = & exec [i ];
105+ eb_add_object (eb , obj );
106+ }
107+ spin_unlock (& file -> table_lock );
108+
109+ return 0 ;
110+ }
111+
72112static struct drm_i915_gem_object *
73113eb_get_object (struct eb_objects * eb , unsigned long handle )
74114{
@@ -550,21 +590,9 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
550590
551591 /* reacquire the objects */
552592 eb_reset (eb );
553- for (i = 0 ; i < count ; i ++ ) {
554- obj = to_intel_bo (drm_gem_object_lookup (dev , file ,
555- exec [i ].handle ));
556- if (& obj -> base == NULL ) {
557- DRM_DEBUG ("Invalid object handle %d at index %d\n" ,
558- exec [i ].handle , i );
559- ret = - ENOENT ;
560- goto err ;
561- }
562-
563- list_add_tail (& obj -> exec_list , objects );
564- obj -> exec_handle = exec [i ].handle ;
565- obj -> exec_entry = & exec [i ];
566- eb_add_object (eb , obj );
567- }
593+ ret = eb_lookup_objects (eb , exec , count , file , objects );
594+ if (ret )
595+ goto err ;
568596
569597 ret = i915_gem_execbuffer_reserve (ring , file , objects );
570598 if (ret )
@@ -872,31 +900,9 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
872900
873901 /* Look up object handles */
874902 INIT_LIST_HEAD (& objects );
875- for (i = 0 ; i < args -> buffer_count ; i ++ ) {
876- struct drm_i915_gem_object * obj ;
877-
878- obj = to_intel_bo (drm_gem_object_lookup (dev , file ,
879- exec [i ].handle ));
880- if (& obj -> base == NULL ) {
881- DRM_DEBUG ("Invalid object handle %d at index %d\n" ,
882- exec [i ].handle , i );
883- /* prevent error path from reading uninitialized data */
884- ret = - ENOENT ;
885- goto err ;
886- }
887-
888- if (!list_empty (& obj -> exec_list )) {
889- DRM_DEBUG ("Object %p [handle %d, index %d] appears more than once in object list\n" ,
890- obj , exec [i ].handle , i );
891- ret = - EINVAL ;
892- goto err ;
893- }
894-
895- list_add_tail (& obj -> exec_list , & objects );
896- obj -> exec_handle = exec [i ].handle ;
897- obj -> exec_entry = & exec [i ];
898- eb_add_object (eb , obj );
899- }
903+ ret = eb_lookup_objects (eb , exec , args -> buffer_count , file , & objects );
904+ if (ret )
905+ goto err ;
900906
901907 /* take note of the batch buffer before we might reorder the lists */
902908 batch_obj = list_entry (objects .prev ,
0 commit comments