Skip to content

Commit 146937e

Browse files
bwidawskdanvet
authored andcommitted
drm/i915: linuxify create_hw_context()
Daniel complained about this on initial review, but he graciously moved the patches forward. As promised, I am delivering the desired cleanup now. Hopefully I didn't screw the trivial patch up ;-) Signed-off-by: Ben Widawsky <ben@bwidawsk.net> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent e486fad commit 146937e

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

drivers/gpu/drm/i915/i915_gem_context.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -136,37 +136,36 @@ static void do_destroy(struct i915_hw_context *ctx)
136136
kfree(ctx);
137137
}
138138

139-
static int
139+
static struct i915_hw_context *
140140
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)
143142
{
144143
struct drm_i915_private *dev_priv = dev->dev_private;
144+
struct i915_hw_context *ctx;
145145
int ret, id;
146146

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);
150150

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);
155154
DRM_DEBUG_DRIVER("Context object allocated failed\n");
156-
return -ENOMEM;
155+
return ERR_PTR(-ENOMEM);
157156
}
158157

159158
/* The ring associated with the context object is handled by the normal
160159
* object tracking code. We give an initial ring value simple to pass an
161160
* assertion in the context switch code.
162161
*/
163-
(*ctx_out)->ring = &dev_priv->ring[RCS];
162+
ctx->ring = &dev_priv->ring[RCS];
164163

165164
/* Default context will never have a file_priv */
166165
if (file_priv == NULL)
167-
return 0;
166+
return ctx;
168167

169-
(*ctx_out)->file_priv = file_priv;
168+
ctx->file_priv = file_priv;
170169

171170
again:
172171
if (idr_pre_get(&file_priv->context_idr, GFP_KERNEL) == 0) {
@@ -175,21 +174,21 @@ create_hw_context(struct drm_device *dev,
175174
goto err_out;
176175
}
177176

178-
ret = idr_get_new_above(&file_priv->context_idr, *ctx_out,
177+
ret = idr_get_new_above(&file_priv->context_idr, ctx,
179178
DEFAULT_CONTEXT_ID + 1, &id);
180179
if (ret == 0)
181-
(*ctx_out)->id = id;
180+
ctx->id = id;
182181

183182
if (ret == -EAGAIN)
184183
goto again;
185184
else if (ret)
186185
goto err_out;
187186

188-
return 0;
187+
return ctx;
189188

190189
err_out:
191-
do_destroy(*ctx_out);
192-
return ret;
190+
do_destroy(ctx);
191+
return ERR_PTR(ret);
193192
}
194193

195194
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)
209208

210209
BUG_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
211210

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);
216214

217215
/* We may need to do things with the shrinker which require us to
218216
* immediately switch back to the default context. This can cause a
219217
* problem as pinning the default context also requires GTT space which
220218
* may not be available. To avoid this we always pin the
221219
* default context.
222220
*/
223-
ctx = dev_priv->ring[RCS].default_context;
221+
dev_priv->ring[RCS].default_context = ctx;
224222
ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false);
225223
if (ret) {
226224
do_destroy(ctx);
@@ -496,13 +494,13 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
496494
if (ret)
497495
return ret;
498496

499-
ret = create_hw_context(dev, file_priv, &ctx);
497+
ctx = create_hw_context(dev, file_priv);
500498
mutex_unlock(&dev->struct_mutex);
501499

502500
args->ctx_id = ctx->id;
503501
DRM_DEBUG_DRIVER("HW context %d created\n", args->ctx_id);
504502

505-
return ret;
503+
return PTR_RET(ctx);
506504
}
507505

508506
int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,

0 commit comments

Comments
 (0)