diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2005-11-07 06:31:45 -0500 |
---|---|---|
committer | Jody McIntyre <scjody@modernduck.com> | 2005-11-07 06:31:45 -0500 |
commit | 8551158abc8ef45a7f473a87e69624d05ebfd684 (patch) | |
tree | 47cd79c5f5444c7cac812d797764f203207345a7 /drivers/ieee1394/video1394.c | |
parent | 7afa1467761f06bd9649efd66a4a6b3ff9f29a1f (diff) |
kmalloc/kzalloc changes:
dv1394, eth1394, ieee1394, ohci1394, pcilynx, raw1394, sbp2c, video1394:
- use kzalloc
- provide safer size arguments to kmalloc and kzalloc
- omit some casts
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Jody McIntyre <scjody@modernduck.com>
Diffstat (limited to 'drivers/ieee1394/video1394.c')
-rw-r--r-- | drivers/ieee1394/video1394.c | 81 |
1 files changed, 26 insertions, 55 deletions
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c index 23911da50154..2ad30cd7c5aa 100644 --- a/drivers/ieee1394/video1394.c +++ b/drivers/ieee1394/video1394.c | |||
@@ -206,14 +206,12 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
206 | struct dma_iso_ctx *d; | 206 | struct dma_iso_ctx *d; |
207 | int i; | 207 | int i; |
208 | 208 | ||
209 | d = kmalloc(sizeof(struct dma_iso_ctx), GFP_KERNEL); | 209 | d = kzalloc(sizeof(*d), GFP_KERNEL); |
210 | if (d == NULL) { | 210 | if (!d) { |
211 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma_iso_ctx"); | 211 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma_iso_ctx"); |
212 | return NULL; | 212 | return NULL; |
213 | } | 213 | } |
214 | 214 | ||
215 | memset(d, 0, sizeof *d); | ||
216 | |||
217 | d->ohci = ohci; | 215 | d->ohci = ohci; |
218 | d->type = type; | 216 | d->type = type; |
219 | d->channel = channel; | 217 | d->channel = channel; |
@@ -251,9 +249,8 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
251 | } | 249 | } |
252 | d->ctx = d->iso_tasklet.context; | 250 | d->ctx = d->iso_tasklet.context; |
253 | 251 | ||
254 | d->prg_reg = kmalloc(d->num_desc * sizeof(struct dma_prog_region), | 252 | d->prg_reg = kmalloc(d->num_desc * sizeof(*d->prg_reg), GFP_KERNEL); |
255 | GFP_KERNEL); | 253 | if (!d->prg_reg) { |
256 | if (d->prg_reg == NULL) { | ||
257 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate ir prg regs"); | 254 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate ir prg regs"); |
258 | free_dma_iso_ctx(d); | 255 | free_dma_iso_ctx(d); |
259 | return NULL; | 256 | return NULL; |
@@ -268,15 +265,14 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
268 | d->cmdPtr = OHCI1394_IsoRcvCommandPtr+32*d->ctx; | 265 | d->cmdPtr = OHCI1394_IsoRcvCommandPtr+32*d->ctx; |
269 | d->ctxMatch = OHCI1394_IsoRcvContextMatch+32*d->ctx; | 266 | d->ctxMatch = OHCI1394_IsoRcvContextMatch+32*d->ctx; |
270 | 267 | ||
271 | d->ir_prg = kmalloc(d->num_desc * sizeof(struct dma_cmd *), | 268 | d->ir_prg = kzalloc(d->num_desc * sizeof(*d->ir_prg), |
272 | GFP_KERNEL); | 269 | GFP_KERNEL); |
273 | 270 | ||
274 | if (d->ir_prg == NULL) { | 271 | if (!d->ir_prg) { |
275 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg"); | 272 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg"); |
276 | free_dma_iso_ctx(d); | 273 | free_dma_iso_ctx(d); |
277 | return NULL; | 274 | return NULL; |
278 | } | 275 | } |
279 | memset(d->ir_prg, 0, d->num_desc * sizeof(struct dma_cmd *)); | ||
280 | 276 | ||
281 | d->nb_cmd = d->buf_size / PAGE_SIZE + 1; | 277 | d->nb_cmd = d->buf_size / PAGE_SIZE + 1; |
282 | d->left_size = (d->frame_size % PAGE_SIZE) ? | 278 | d->left_size = (d->frame_size % PAGE_SIZE) ? |
@@ -297,16 +293,15 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
297 | d->ctrlClear = OHCI1394_IsoXmitContextControlClear+16*d->ctx; | 293 | d->ctrlClear = OHCI1394_IsoXmitContextControlClear+16*d->ctx; |
298 | d->cmdPtr = OHCI1394_IsoXmitCommandPtr+16*d->ctx; | 294 | d->cmdPtr = OHCI1394_IsoXmitCommandPtr+16*d->ctx; |
299 | 295 | ||
300 | d->it_prg = kmalloc(d->num_desc * sizeof(struct it_dma_prg *), | 296 | d->it_prg = kzalloc(d->num_desc * sizeof(*d->it_prg), |
301 | GFP_KERNEL); | 297 | GFP_KERNEL); |
302 | 298 | ||
303 | if (d->it_prg == NULL) { | 299 | if (!d->it_prg) { |
304 | PRINT(KERN_ERR, ohci->host->id, | 300 | PRINT(KERN_ERR, ohci->host->id, |
305 | "Failed to allocate dma it prg"); | 301 | "Failed to allocate dma it prg"); |
306 | free_dma_iso_ctx(d); | 302 | free_dma_iso_ctx(d); |
307 | return NULL; | 303 | return NULL; |
308 | } | 304 | } |
309 | memset(d->it_prg, 0, d->num_desc*sizeof(struct it_dma_prg *)); | ||
310 | 305 | ||
311 | d->packet_size = packet_size; | 306 | d->packet_size = packet_size; |
312 | 307 | ||
@@ -337,47 +332,24 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc, | |||
337 | } | 332 | } |
338 | } | 333 | } |
339 | 334 | ||
340 | d->buffer_status = kmalloc(d->num_desc * sizeof(unsigned int), | 335 | d->buffer_status = |
341 | GFP_KERNEL); | 336 | kzalloc(d->num_desc * sizeof(*d->buffer_status), GFP_KERNEL); |
342 | d->buffer_prg_assignment = kmalloc(d->num_desc * sizeof(unsigned int), | 337 | d->buffer_prg_assignment = |
343 | GFP_KERNEL); | 338 | kzalloc(d->num_desc * sizeof(*d->buffer_prg_assignment), GFP_KERNEL); |
344 | d->buffer_time = kmalloc(d->num_desc * sizeof(struct timeval), | 339 | d->buffer_time = |
345 | GFP_KERNEL); | 340 | kzalloc(d->num_desc * sizeof(*d->buffer_time), GFP_KERNEL); |
346 | d->last_used_cmd = kmalloc(d->num_desc * sizeof(unsigned int), | 341 | d->last_used_cmd = |
347 | GFP_KERNEL); | 342 | kzalloc(d->num_desc * sizeof(*d->last_used_cmd), GFP_KERNEL); |
348 | d->next_buffer = kmalloc(d->num_desc * sizeof(int), | 343 | d->next_buffer = |
349 | GFP_KERNEL); | 344 | kzalloc(d->num_desc * sizeof(*d->next_buffer), GFP_KERNEL); |
350 | 345 | ||
351 | if (d->buffer_status == NULL) { | 346 | if (!d->buffer_status || !d->buffer_prg_assignment || !d->buffer_time || |
352 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_status"); | 347 | !d->last_used_cmd || !d->next_buffer) { |
353 | free_dma_iso_ctx(d); | 348 | PRINT(KERN_ERR, ohci->host->id, |
354 | return NULL; | 349 | "Failed to allocate dma_iso_ctx member"); |
355 | } | ||
356 | if (d->buffer_prg_assignment == NULL) { | ||
357 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_prg_assignment"); | ||
358 | free_dma_iso_ctx(d); | ||
359 | return NULL; | ||
360 | } | ||
361 | if (d->buffer_time == NULL) { | ||
362 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_time"); | ||
363 | free_dma_iso_ctx(d); | ||
364 | return NULL; | ||
365 | } | ||
366 | if (d->last_used_cmd == NULL) { | ||
367 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate last_used_cmd"); | ||
368 | free_dma_iso_ctx(d); | ||
369 | return NULL; | ||
370 | } | ||
371 | if (d->next_buffer == NULL) { | ||
372 | PRINT(KERN_ERR, ohci->host->id, "Failed to allocate next_buffer"); | ||
373 | free_dma_iso_ctx(d); | 350 | free_dma_iso_ctx(d); |
374 | return NULL; | 351 | return NULL; |
375 | } | 352 | } |
376 | memset(d->buffer_status, 0, d->num_desc * sizeof(unsigned int)); | ||
377 | memset(d->buffer_prg_assignment, 0, d->num_desc * sizeof(unsigned int)); | ||
378 | memset(d->buffer_time, 0, d->num_desc * sizeof(struct timeval)); | ||
379 | memset(d->last_used_cmd, 0, d->num_desc * sizeof(unsigned int)); | ||
380 | memset(d->next_buffer, -1, d->num_desc * sizeof(int)); | ||
381 | 353 | ||
382 | spin_lock_init(&d->lock); | 354 | spin_lock_init(&d->lock); |
383 | 355 | ||
@@ -1085,7 +1057,7 @@ static int __video1394_ioctl(struct file *file, | |||
1085 | } | 1057 | } |
1086 | 1058 | ||
1087 | if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) { | 1059 | if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) { |
1088 | int buf_size = d->nb_cmd * sizeof(unsigned int); | 1060 | int buf_size = d->nb_cmd * sizeof(*psizes); |
1089 | struct video1394_queue_variable __user *p = argp; | 1061 | struct video1394_queue_variable __user *p = argp; |
1090 | unsigned int __user *qv; | 1062 | unsigned int __user *qv; |
1091 | 1063 | ||
@@ -1251,13 +1223,12 @@ static int video1394_open(struct inode *inode, struct file *file) | |||
1251 | if (ohci == NULL) | 1223 | if (ohci == NULL) |
1252 | return -EIO; | 1224 | return -EIO; |
1253 | 1225 | ||
1254 | ctx = kmalloc(sizeof(struct file_ctx), GFP_KERNEL); | 1226 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
1255 | if (ctx == NULL) { | 1227 | if (!ctx) { |
1256 | PRINT(KERN_ERR, ohci->host->id, "Cannot malloc file_ctx"); | 1228 | PRINT(KERN_ERR, ohci->host->id, "Cannot malloc file_ctx"); |
1257 | return -ENOMEM; | 1229 | return -ENOMEM; |
1258 | } | 1230 | } |
1259 | 1231 | ||
1260 | memset(ctx, 0, sizeof(struct file_ctx)); | ||
1261 | ctx->ohci = ohci; | 1232 | ctx->ohci = ohci; |
1262 | INIT_LIST_HEAD(&ctx->context_list); | 1233 | INIT_LIST_HEAD(&ctx->context_list); |
1263 | ctx->current_ctx = NULL; | 1234 | ctx->current_ctx = NULL; |