diff options
author | Tejun Heo <tj@kernel.org> | 2013-03-13 17:59:41 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-03-13 18:21:47 -0400 |
commit | 8e467e855ca5ed2921f290655f96ac40d5dc571c (patch) | |
tree | 32a7e3f92cb0ca41732b0b7d66ffb03952254b53 | |
parent | a37c3010002322f40fe668162a237aa99aac42d1 (diff) |
tidspbridge: convert to idr_alloc()
idr_get_new*() and friends are about to be deprecated. Convert to the
new idr_alloc() interface.
There are some peculiarities and possible bugs in the converted
functions. This patch preserves those.
* drv_insert_node_res_element() returns -ENOMEM on alloc failure,
-EFAULT if id space is exhausted. -EFAULT is at best misleading.
* drv_proc_insert_strm_res_element() is even weirder. It returns
-EFAULT if kzalloc() fails, -ENOMEM if idr preloading fails and
-EPERM if id space is exhausted. What's going on here?
* drv_proc_insert_strm_res_element() doesn't free *pstrm_res after
failure.
Only compile tested.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
Cc: Rene Sapiens <rene.sapiens@ti.com>
Cc: Armando Uribe <x0095078@ti.com>
Cc: Omar Ramirez Luna <omar.ramirez@ti.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/staging/tidspbridge/rmgr/drv.c | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/drivers/staging/tidspbridge/rmgr/drv.c b/drivers/staging/tidspbridge/rmgr/drv.c index db1da28cecba..be26917a6896 100644 --- a/drivers/staging/tidspbridge/rmgr/drv.c +++ b/drivers/staging/tidspbridge/rmgr/drv.c | |||
@@ -76,37 +76,28 @@ int drv_insert_node_res_element(void *hnode, void *node_resource, | |||
76 | struct node_res_object **node_res_obj = | 76 | struct node_res_object **node_res_obj = |
77 | (struct node_res_object **)node_resource; | 77 | (struct node_res_object **)node_resource; |
78 | struct process_context *ctxt = (struct process_context *)process_ctxt; | 78 | struct process_context *ctxt = (struct process_context *)process_ctxt; |
79 | int status = 0; | ||
80 | int retval; | 79 | int retval; |
81 | 80 | ||
82 | *node_res_obj = kzalloc(sizeof(struct node_res_object), GFP_KERNEL); | 81 | *node_res_obj = kzalloc(sizeof(struct node_res_object), GFP_KERNEL); |
83 | if (!*node_res_obj) { | 82 | if (!*node_res_obj) |
84 | status = -ENOMEM; | 83 | return -ENOMEM; |
85 | goto func_end; | ||
86 | } | ||
87 | 84 | ||
88 | (*node_res_obj)->node = hnode; | 85 | (*node_res_obj)->node = hnode; |
89 | retval = idr_get_new(ctxt->node_id, *node_res_obj, | 86 | retval = idr_alloc(ctxt->node_id, *node_res_obj, 0, 0, GFP_KERNEL); |
90 | &(*node_res_obj)->id); | 87 | if (retval >= 0) { |
91 | if (retval == -EAGAIN) { | 88 | (*node_res_obj)->id = retval; |
92 | if (!idr_pre_get(ctxt->node_id, GFP_KERNEL)) { | 89 | return 0; |
93 | pr_err("%s: OUT OF MEMORY\n", __func__); | ||
94 | status = -ENOMEM; | ||
95 | goto func_end; | ||
96 | } | ||
97 | |||
98 | retval = idr_get_new(ctxt->node_id, *node_res_obj, | ||
99 | &(*node_res_obj)->id); | ||
100 | } | 90 | } |
101 | if (retval) { | 91 | |
92 | kfree(*node_res_obj); | ||
93 | |||
94 | if (retval == -ENOSPC) { | ||
102 | pr_err("%s: FAILED, IDR is FULL\n", __func__); | 95 | pr_err("%s: FAILED, IDR is FULL\n", __func__); |
103 | status = -EFAULT; | 96 | return -EFAULT; |
97 | } else { | ||
98 | pr_err("%s: OUT OF MEMORY\n", __func__); | ||
99 | return -ENOMEM; | ||
104 | } | 100 | } |
105 | func_end: | ||
106 | if (status) | ||
107 | kfree(*node_res_obj); | ||
108 | |||
109 | return status; | ||
110 | } | 101 | } |
111 | 102 | ||
112 | /* Release all Node resources and its context | 103 | /* Release all Node resources and its context |
@@ -201,35 +192,26 @@ int drv_proc_insert_strm_res_element(void *stream_obj, | |||
201 | struct strm_res_object **pstrm_res = | 192 | struct strm_res_object **pstrm_res = |
202 | (struct strm_res_object **)strm_res; | 193 | (struct strm_res_object **)strm_res; |
203 | struct process_context *ctxt = (struct process_context *)process_ctxt; | 194 | struct process_context *ctxt = (struct process_context *)process_ctxt; |
204 | int status = 0; | ||
205 | int retval; | 195 | int retval; |
206 | 196 | ||
207 | *pstrm_res = kzalloc(sizeof(struct strm_res_object), GFP_KERNEL); | 197 | *pstrm_res = kzalloc(sizeof(struct strm_res_object), GFP_KERNEL); |
208 | if (*pstrm_res == NULL) { | 198 | if (*pstrm_res == NULL) |
209 | status = -EFAULT; | 199 | return -EFAULT; |
210 | goto func_end; | ||
211 | } | ||
212 | 200 | ||
213 | (*pstrm_res)->stream = stream_obj; | 201 | (*pstrm_res)->stream = stream_obj; |
214 | retval = idr_get_new(ctxt->stream_id, *pstrm_res, | 202 | retval = idr_alloc(ctxt->stream_id, *pstrm_res, 0, 0, GFP_KERNEL); |
215 | &(*pstrm_res)->id); | 203 | if (retval >= 0) { |
216 | if (retval == -EAGAIN) { | 204 | (*pstrm_res)->id = retval; |
217 | if (!idr_pre_get(ctxt->stream_id, GFP_KERNEL)) { | 205 | return 0; |
218 | pr_err("%s: OUT OF MEMORY\n", __func__); | ||
219 | status = -ENOMEM; | ||
220 | goto func_end; | ||
221 | } | ||
222 | |||
223 | retval = idr_get_new(ctxt->stream_id, *pstrm_res, | ||
224 | &(*pstrm_res)->id); | ||
225 | } | 206 | } |
226 | if (retval) { | 207 | |
208 | if (retval == -ENOSPC) { | ||
227 | pr_err("%s: FAILED, IDR is FULL\n", __func__); | 209 | pr_err("%s: FAILED, IDR is FULL\n", __func__); |
228 | status = -EPERM; | 210 | return -EPERM; |
211 | } else { | ||
212 | pr_err("%s: OUT OF MEMORY\n", __func__); | ||
213 | return -ENOMEM; | ||
229 | } | 214 | } |
230 | |||
231 | func_end: | ||
232 | return status; | ||
233 | } | 215 | } |
234 | 216 | ||
235 | static int drv_proc_free_strm_res(int id, void *p, void *process_ctxt) | 217 | static int drv_proc_free_strm_res(int id, void *p, void *process_ctxt) |