[PATCH 06/16] drm: cleanup render node ioctls
Ilija Hadzic
ihadzic at research.bell-labs.com
Thu Mar 29 09:41:28 PDT 2012
Fix a few bugs in render node create and destroy ioctl
(mostly handling of error cases). Also separate some
common code into a new function for destroying
the render node.
Signed-off-by: Ilija Hadzic <ihadzic at research.bell-labs.com>
---
drivers/gpu/drm/drm_stub.c | 80 +++++++++++++++++++++++++++----------------
1 files changed, 50 insertions(+), 30 deletions(-)
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index ba6cb52..12260f0 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -420,17 +420,30 @@ int drm_create_render_node(struct drm_device *dev, struct drm_minor **minor_p)
return 0;
}
-int drm_destroy_all_render_nodes(struct drm_device *dev)
+int drm_destroy_render_node(struct drm_device *dev, int index)
{
- struct drm_render_node *render_node, *tmp;
+ struct drm_render_node *node, *tmp;
+
+ list_for_each_entry_safe(node, tmp, &dev->render_node_list, list) {
+ if (node->minor->index == index) {
+ list_del(&node->list);
+ drm_put_minor(&node->minor);
+ kfree(node);
+ return 0;
+ }
+ }
+ return -ENODEV;
+}
- list_for_each_entry_safe(render_node, tmp,
- &dev->render_node_list, list) {
- list_del(&render_node->list);
- drm_put_minor(&render_node->minor);
- kfree(render_node);
+void drm_destroy_all_render_nodes(struct drm_device *dev)
+{
+ struct drm_render_node *node, *tmp;
+
+ list_for_each_entry_safe(node, tmp, &dev->render_node_list, list) {
+ list_del(&node->list);
+ drm_put_minor(&node->minor);
+ kfree(node);
}
- return 0;
}
/**
@@ -538,38 +551,48 @@ int drm_render_node_create_ioctl(struct drm_device *dev, void *data,
struct drm_minor *new_minor;
int total_ids, i;
uint32_t __user *ids_ptr;
- ret = drm_create_render_node(dev, &new_minor);
- if (ret)
- goto out;
-
- args->node_minor_id = new_minor->index;
+ /* trivial case: render node with no display resources */
if (args->num_crtc == 0 &&
args->num_encoder == 0 &&
- args->num_connector == 0)
- goto out;
- if (args->num_crtc == 0 ||
- args->num_encoder == 0 ||
args->num_connector == 0) {
- ret = -EINVAL;
- goto out;
+ ret = drm_create_render_node(dev, &new_minor);
+ if (!ret)
+ args->node_minor_id = new_minor->index;
+ return ret;
}
+ /* if we have display resources, then we need at least
+ * one CRTC, one encoder and one connector */
+ if (args->num_crtc == 0 ||
+ args->num_encoder == 0 ||
+ args->num_connector == 0)
+ return -EINVAL;
+
+ ret = drm_create_render_node(dev, &new_minor);
+ if (ret)
+ return ret;
+
ret = drm_mode_group_init(dev, &new_minor->mode_group);
if (ret)
- goto out;
+ goto out_del;
ids_ptr = (uint32_t __user *)(unsigned long)args->id_list_ptr;
total_ids = args->num_crtc + args->num_encoder + args->num_connector;
for (i = 0; i < total_ids; i++) {
if (get_user(new_minor->mode_group.id_list[i], &ids_ptr[i])) {
ret = -EFAULT;
- goto out_put;
+ goto out_del;
}
}
-out_put:
- drm_put_minor(&new_minor);
-out:
+ new_minor->mode_group.num_crtcs = args->num_crtc;
+ new_minor->mode_group.num_encoders = args->num_encoder;
+ new_minor->mode_group.num_connectors = args->num_connector;
+
+ args->node_minor_id = new_minor->index;
+ return 0;
+out_del:
+ drm_destroy_render_node(dev, new_minor->index);
return ret;
}
@@ -577,11 +600,8 @@ int drm_render_node_remove_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_render_node_remove *args = data;
- struct drm_render_node *del_node, *tmp;
+ int ret;
- list_for_each_entry_safe(del_node, tmp, &dev->render_node_list, list) {
- if (del_node->minor->index == args->node_minor_id)
- drm_put_minor(&del_node->minor);
- }
- return 0;
+ ret = drm_destroy_render_node(dev, args->node_minor_id);
+ return ret;
}
--
1.7.8.5
More information about the dri-devel
mailing list