diff options
author | Perceval Anichini <perceval.anichini@streamvision.fr> | 2005-11-09 00:35:19 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-09 10:56:02 -0500 |
commit | f630558dfbd47301c2ce30f7e4acd2817a7455ac (patch) | |
tree | a78a30ef0397ae3e48c32fb84b7a191c56f3c738 /drivers | |
parent | 174f80dfcba45677f12ba57479d03750dd9cad7b (diff) |
[PATCH] dvb: dst: fix memory leaks
fix memory leaks
Signed-off-by: Perceval Anichini <perceval.anichini@streamvision.fr>
Signed-off-by: Manu Abraham <manu@linuxtv.org>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Cc: Johannes Stezenbach <js@linuxtv.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/dvb/bt8xx/dst_ca.c | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c index 492e829fe021..f77fda77b638 100644 --- a/drivers/media/dvb/bt8xx/dst_ca.c +++ b/drivers/media/dvb/bt8xx/dst_ca.c | |||
@@ -407,6 +407,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, | |||
407 | 407 | ||
408 | u32 command = 0; | 408 | u32 command = 0; |
409 | struct ca_msg *hw_buffer; | 409 | struct ca_msg *hw_buffer; |
410 | int result = 0; | ||
410 | 411 | ||
411 | if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { | 412 | if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { |
412 | dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure"); | 413 | dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure"); |
@@ -414,8 +415,11 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, | |||
414 | } | 415 | } |
415 | dprintk(verbose, DST_CA_DEBUG, 1, " "); | 416 | dprintk(verbose, DST_CA_DEBUG, 1, " "); |
416 | 417 | ||
417 | if (copy_from_user(p_ca_message, arg, sizeof (struct ca_msg))) | 418 | if (copy_from_user(p_ca_message, (void *)arg, sizeof (struct ca_msg))) { |
418 | return -EFAULT; | 419 | result = -EFAULT; |
420 | goto free_mem_and_exit; | ||
421 | } | ||
422 | |||
419 | 423 | ||
420 | if (p_ca_message->msg) { | 424 | if (p_ca_message->msg) { |
421 | ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */ | 425 | ca_message_header_len = p_ca_message->length; /* Restore it back when you are done */ |
@@ -434,7 +438,8 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, | |||
434 | dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT"); | 438 | dprintk(verbose, DST_CA_DEBUG, 1, "Command = SEND_CA_PMT"); |
435 | if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started | 439 | if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started |
436 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !"); | 440 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT Failed !"); |
437 | return -1; | 441 | result = -1; |
442 | goto free_mem_and_exit; | ||
438 | } | 443 | } |
439 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !"); | 444 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT Success !"); |
440 | break; | 445 | break; |
@@ -443,7 +448,8 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, | |||
443 | /* Have to handle the 2 basic types of cards here */ | 448 | /* Have to handle the 2 basic types of cards here */ |
444 | if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) { | 449 | if ((dst_check_ca_pmt(state, p_ca_message, hw_buffer)) < 0) { |
445 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !"); | 450 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_PMT_REPLY Failed !"); |
446 | return -1; | 451 | result = -1; |
452 | goto free_mem_and_exit; | ||
447 | } | 453 | } |
448 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !"); | 454 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_PMT_REPLY Success !"); |
449 | break; | 455 | break; |
@@ -452,13 +458,17 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message, | |||
452 | 458 | ||
453 | if ((ca_get_app_info(state)) < 0) { | 459 | if ((ca_get_app_info(state)) < 0) { |
454 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !"); | 460 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_APP_INFO_ENQUIRY Failed !"); |
455 | return -1; | 461 | result = -1; |
462 | goto free_mem_and_exit; | ||
456 | } | 463 | } |
457 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !"); | 464 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_APP_INFO_ENQUIRY Success !"); |
458 | break; | 465 | break; |
459 | } | 466 | } |
460 | } | 467 | } |
461 | return 0; | 468 | free_mem_and_exit: |
469 | kfree (hw_buffer); | ||
470 | |||
471 | return result; | ||
462 | } | 472 | } |
463 | 473 | ||
464 | static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg) | 474 | static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg) |
@@ -469,6 +479,7 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
469 | struct ca_caps *p_ca_caps; | 479 | struct ca_caps *p_ca_caps; |
470 | struct ca_msg *p_ca_message; | 480 | struct ca_msg *p_ca_message; |
471 | void __user *arg = (void __user *)ioctl_arg; | 481 | void __user *arg = (void __user *)ioctl_arg; |
482 | int result = 0; | ||
472 | 483 | ||
473 | if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { | 484 | if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { |
474 | dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure"); | 485 | dprintk(verbose, DST_CA_ERROR, 1, " Memory allocation failure"); |
@@ -488,14 +499,16 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
488 | dprintk(verbose, DST_CA_INFO, 1, " Sending message"); | 499 | dprintk(verbose, DST_CA_INFO, 1, " Sending message"); |
489 | if ((ca_send_message(state, p_ca_message, arg)) < 0) { | 500 | if ((ca_send_message(state, p_ca_message, arg)) < 0) { |
490 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !"); | 501 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SEND_MSG Failed !"); |
491 | return -1; | 502 | result = -1; |
503 | goto free_mem_and_exit; | ||
492 | } | 504 | } |
493 | break; | 505 | break; |
494 | case CA_GET_MSG: | 506 | case CA_GET_MSG: |
495 | dprintk(verbose, DST_CA_INFO, 1, " Getting message"); | 507 | dprintk(verbose, DST_CA_INFO, 1, " Getting message"); |
496 | if ((ca_get_message(state, p_ca_message, arg)) < 0) { | 508 | if ((ca_get_message(state, p_ca_message, arg)) < 0) { |
497 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !"); | 509 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_MSG Failed !"); |
498 | return -1; | 510 | result = -1; |
511 | goto free_mem_and_exit; | ||
499 | } | 512 | } |
500 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !"); | 513 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_MSG Success !"); |
501 | break; | 514 | break; |
@@ -508,7 +521,8 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
508 | dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info"); | 521 | dprintk(verbose, DST_CA_INFO, 1, " Getting Slot info"); |
509 | if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) { | 522 | if ((ca_get_slot_info(state, p_ca_slot_info, arg)) < 0) { |
510 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !"); | 523 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_SLOT_INFO Failed !"); |
511 | return -1; | 524 | result = -1; |
525 | goto free_mem_and_exit; | ||
512 | } | 526 | } |
513 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !"); | 527 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_SLOT_INFO Success !"); |
514 | break; | 528 | break; |
@@ -516,7 +530,8 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
516 | dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities"); | 530 | dprintk(verbose, DST_CA_INFO, 1, " Getting Slot capabilities"); |
517 | if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) { | 531 | if ((ca_get_slot_caps(state, p_ca_caps, arg)) < 0) { |
518 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !"); | 532 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_CAP Failed !"); |
519 | return -1; | 533 | result = -1; |
534 | goto free_mem_and_exit; | ||
520 | } | 535 | } |
521 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !"); | 536 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_CAP Success !"); |
522 | break; | 537 | break; |
@@ -524,7 +539,8 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
524 | dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description"); | 539 | dprintk(verbose, DST_CA_INFO, 1, " Getting descrambler description"); |
525 | if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) { | 540 | if ((ca_get_slot_descr(state, p_ca_message, arg)) < 0) { |
526 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !"); | 541 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_GET_DESCR_INFO Failed !"); |
527 | return -1; | 542 | result = -1; |
543 | goto free_mem_and_exit; | ||
528 | } | 544 | } |
529 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !"); | 545 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_GET_DESCR_INFO Success !"); |
530 | break; | 546 | break; |
@@ -532,7 +548,8 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
532 | dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler"); | 548 | dprintk(verbose, DST_CA_INFO, 1, " Setting descrambler"); |
533 | if ((ca_set_slot_descr()) < 0) { | 549 | if ((ca_set_slot_descr()) < 0) { |
534 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !"); | 550 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_DESCR Failed !"); |
535 | return -1; | 551 | result = -1; |
552 | goto free_mem_and_exit; | ||
536 | } | 553 | } |
537 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !"); | 554 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_DESCR Success !"); |
538 | break; | 555 | break; |
@@ -540,14 +557,19 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
540 | dprintk(verbose, DST_CA_INFO, 1, " Setting PID"); | 557 | dprintk(verbose, DST_CA_INFO, 1, " Setting PID"); |
541 | if ((ca_set_pid()) < 0) { | 558 | if ((ca_set_pid()) < 0) { |
542 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !"); | 559 | dprintk(verbose, DST_CA_ERROR, 1, " -->CA_SET_PID Failed !"); |
543 | return -1; | 560 | result = -1; |
561 | goto free_mem_and_exit; | ||
544 | } | 562 | } |
545 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !"); | 563 | dprintk(verbose, DST_CA_INFO, 1, " -->CA_SET_PID Success !"); |
546 | default: | 564 | default: |
547 | return -EOPNOTSUPP; | 565 | result = -EOPNOTSUPP; |
548 | }; | 566 | }; |
567 | free_mem_and_exit: | ||
568 | kfree (p_ca_message); | ||
569 | kfree (p_ca_slot_info); | ||
570 | kfree (p_ca_caps); | ||
549 | 571 | ||
550 | return 0; | 572 | return result; |
551 | } | 573 | } |
552 | 574 | ||
553 | static int dst_ca_open(struct inode *inode, struct file *file) | 575 | static int dst_ca_open(struct inode *inode, struct file *file) |