@@ -136,37 +136,36 @@ static void do_destroy(struct i915_hw_context *ctx)
136
136
kfree (ctx );
137
137
}
138
138
139
- static int
139
+ static struct i915_hw_context *
140
140
create_hw_context (struct drm_device * dev ,
141
- struct drm_i915_file_private * file_priv ,
142
- struct i915_hw_context * * ctx_out )
141
+ struct drm_i915_file_private * file_priv )
143
142
{
144
143
struct drm_i915_private * dev_priv = dev -> dev_private ;
144
+ struct i915_hw_context * ctx ;
145
145
int ret , id ;
146
146
147
- * ctx_out = kzalloc (sizeof (struct drm_i915_file_private ), GFP_KERNEL );
148
- if (* ctx_out == NULL )
149
- return - ENOMEM ;
147
+ ctx = kzalloc (sizeof (struct drm_i915_file_private ), GFP_KERNEL );
148
+ if (ctx == NULL )
149
+ return ERR_PTR ( - ENOMEM ) ;
150
150
151
- (* ctx_out )-> obj = i915_gem_alloc_object (dev ,
152
- dev_priv -> hw_context_size );
153
- if ((* ctx_out )-> obj == NULL ) {
154
- kfree (* ctx_out );
151
+ ctx -> obj = i915_gem_alloc_object (dev , dev_priv -> hw_context_size );
152
+ if (ctx -> obj == NULL ) {
153
+ kfree (ctx );
155
154
DRM_DEBUG_DRIVER ("Context object allocated failed\n" );
156
- return - ENOMEM ;
155
+ return ERR_PTR ( - ENOMEM ) ;
157
156
}
158
157
159
158
/* The ring associated with the context object is handled by the normal
160
159
* object tracking code. We give an initial ring value simple to pass an
161
160
* assertion in the context switch code.
162
161
*/
163
- ( * ctx_out ) -> ring = & dev_priv -> ring [RCS ];
162
+ ctx -> ring = & dev_priv -> ring [RCS ];
164
163
165
164
/* Default context will never have a file_priv */
166
165
if (file_priv == NULL )
167
- return 0 ;
166
+ return ctx ;
168
167
169
- ( * ctx_out ) -> file_priv = file_priv ;
168
+ ctx -> file_priv = file_priv ;
170
169
171
170
again :
172
171
if (idr_pre_get (& file_priv -> context_idr , GFP_KERNEL ) == 0 ) {
@@ -175,21 +174,21 @@ create_hw_context(struct drm_device *dev,
175
174
goto err_out ;
176
175
}
177
176
178
- ret = idr_get_new_above (& file_priv -> context_idr , * ctx_out ,
177
+ ret = idr_get_new_above (& file_priv -> context_idr , ctx ,
179
178
DEFAULT_CONTEXT_ID + 1 , & id );
180
179
if (ret == 0 )
181
- ( * ctx_out ) -> id = id ;
180
+ ctx -> id = id ;
182
181
183
182
if (ret == - EAGAIN )
184
183
goto again ;
185
184
else if (ret )
186
185
goto err_out ;
187
186
188
- return 0 ;
187
+ return ctx ;
189
188
190
189
err_out :
191
- do_destroy (* ctx_out );
192
- return ret ;
190
+ do_destroy (ctx );
191
+ return ERR_PTR ( ret ) ;
193
192
}
194
193
195
194
static inline bool is_default_context (struct i915_hw_context * ctx )
@@ -209,18 +208,17 @@ static int create_default_context(struct drm_i915_private *dev_priv)
209
208
210
209
BUG_ON (!mutex_is_locked (& dev_priv -> dev -> struct_mutex ));
211
210
212
- ret = create_hw_context (dev_priv -> dev , NULL ,
213
- & dev_priv -> ring [RCS ].default_context );
214
- if (ret )
215
- return ret ;
211
+ ctx = create_hw_context (dev_priv -> dev , NULL );
212
+ if (IS_ERR (ctx ))
213
+ return PTR_ERR (ctx );
216
214
217
215
/* We may need to do things with the shrinker which require us to
218
216
* immediately switch back to the default context. This can cause a
219
217
* problem as pinning the default context also requires GTT space which
220
218
* may not be available. To avoid this we always pin the
221
219
* default context.
222
220
*/
223
- ctx = dev_priv -> ring [RCS ].default_context ;
221
+ dev_priv -> ring [RCS ].default_context = ctx ;
224
222
ret = i915_gem_object_pin (ctx -> obj , CONTEXT_ALIGN , false);
225
223
if (ret ) {
226
224
do_destroy (ctx );
@@ -496,13 +494,13 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
496
494
if (ret )
497
495
return ret ;
498
496
499
- ret = create_hw_context (dev , file_priv , & ctx );
497
+ ctx = create_hw_context (dev , file_priv );
500
498
mutex_unlock (& dev -> struct_mutex );
501
499
502
500
args -> ctx_id = ctx -> id ;
503
501
DRM_DEBUG_DRIVER ("HW context %d created\n" , args -> ctx_id );
504
502
505
- return ret ;
503
+ return PTR_RET ( ctx ) ;
506
504
}
507
505
508
506
int i915_gem_context_destroy_ioctl (struct drm_device * dev , void * data ,
0 commit comments