diff options
Diffstat (limited to 'drivers/media/video/zoran_card.c')
-rw-r--r-- | drivers/media/video/zoran_card.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c index 246e67cd8b51..b22dbb6d18f6 100644 --- a/drivers/media/video/zoran_card.c +++ b/drivers/media/video/zoran_card.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/interrupt.h> | 47 | #include <linux/interrupt.h> |
48 | #include <linux/video_decoder.h> | 48 | #include <linux/video_decoder.h> |
49 | #include <linux/video_encoder.h> | 49 | #include <linux/video_encoder.h> |
50 | #include <linux/mutex.h> | ||
50 | 51 | ||
51 | #include <asm/io.h> | 52 | #include <asm/io.h> |
52 | 53 | ||
@@ -673,7 +674,7 @@ zoran_i2c_client_register (struct i2c_client *client) | |||
673 | KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n", | 674 | KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n", |
674 | ZR_DEVNAME(zr), client->driver->id); | 675 | ZR_DEVNAME(zr), client->driver->id); |
675 | 676 | ||
676 | down(&zr->resource_lock); | 677 | mutex_lock(&zr->resource_lock); |
677 | 678 | ||
678 | if (zr->user > 0) { | 679 | if (zr->user > 0) { |
679 | /* we're already busy, so we keep a reference to | 680 | /* we're already busy, so we keep a reference to |
@@ -694,7 +695,7 @@ zoran_i2c_client_register (struct i2c_client *client) | |||
694 | } | 695 | } |
695 | 696 | ||
696 | clientreg_unlock_and_return: | 697 | clientreg_unlock_and_return: |
697 | up(&zr->resource_lock); | 698 | mutex_unlock(&zr->resource_lock); |
698 | 699 | ||
699 | return res; | 700 | return res; |
700 | } | 701 | } |
@@ -707,7 +708,7 @@ zoran_i2c_client_unregister (struct i2c_client *client) | |||
707 | 708 | ||
708 | dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr)); | 709 | dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr)); |
709 | 710 | ||
710 | down(&zr->resource_lock); | 711 | mutex_lock(&zr->resource_lock); |
711 | 712 | ||
712 | if (zr->user > 0) { | 713 | if (zr->user > 0) { |
713 | res = -EBUSY; | 714 | res = -EBUSY; |
@@ -722,7 +723,7 @@ zoran_i2c_client_unregister (struct i2c_client *client) | |||
722 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id); | 723 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id); |
723 | } | 724 | } |
724 | clientunreg_unlock_and_return: | 725 | clientunreg_unlock_and_return: |
725 | up(&zr->resource_lock); | 726 | mutex_unlock(&zr->resource_lock); |
726 | return res; | 727 | return res; |
727 | } | 728 | } |
728 | 729 | ||
@@ -995,10 +996,7 @@ test_interrupts (struct zoran *zr) | |||
995 | static int __devinit | 996 | static int __devinit |
996 | zr36057_init (struct zoran *zr) | 997 | zr36057_init (struct zoran *zr) |
997 | { | 998 | { |
998 | u32 *mem; | 999 | int j, err; |
999 | void *vdev; | ||
1000 | unsigned mem_needed; | ||
1001 | int j; | ||
1002 | int two = 2; | 1000 | int two = 2; |
1003 | int zero = 0; | 1001 | int zero = 0; |
1004 | 1002 | ||
@@ -1049,19 +1047,16 @@ zr36057_init (struct zoran *zr) | |||
1049 | 1047 | ||
1050 | /* allocate memory *before* doing anything to the hardware | 1048 | /* allocate memory *before* doing anything to the hardware |
1051 | * in case allocation fails */ | 1049 | * in case allocation fails */ |
1052 | mem_needed = BUZ_NUM_STAT_COM * 4; | 1050 | zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL); |
1053 | mem = kzalloc(mem_needed, GFP_KERNEL); | 1051 | zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL); |
1054 | vdev = (void *) kmalloc(sizeof(struct video_device), GFP_KERNEL); | 1052 | if (!zr->stat_com || !zr->video_dev) { |
1055 | if (!mem || !vdev) { | ||
1056 | dprintk(1, | 1053 | dprintk(1, |
1057 | KERN_ERR | 1054 | KERN_ERR |
1058 | "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", | 1055 | "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", |
1059 | ZR_DEVNAME(zr)); | 1056 | ZR_DEVNAME(zr)); |
1060 | kfree(vdev); | 1057 | err = -ENOMEM; |
1061 | kfree(mem); | 1058 | goto exit_free; |
1062 | return -ENOMEM; | ||
1063 | } | 1059 | } |
1064 | zr->stat_com = mem; | ||
1065 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) { | 1060 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) { |
1066 | zr->stat_com[j] = 1; /* mark as unavailable to zr36057 */ | 1061 | zr->stat_com[j] = 1; /* mark as unavailable to zr36057 */ |
1067 | } | 1062 | } |
@@ -1069,16 +1064,11 @@ zr36057_init (struct zoran *zr) | |||
1069 | /* | 1064 | /* |
1070 | * Now add the template and register the device unit. | 1065 | * Now add the template and register the device unit. |
1071 | */ | 1066 | */ |
1072 | zr->video_dev = vdev; | ||
1073 | memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); | 1067 | memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); |
1074 | strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); | 1068 | strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); |
1075 | if (video_register_device(zr->video_dev, VFL_TYPE_GRABBER, | 1069 | err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr); |
1076 | video_nr) < 0) { | 1070 | if (err < 0) |
1077 | zoran_unregister_i2c(zr); | 1071 | goto exit_unregister; |
1078 | kfree((void *) zr->stat_com); | ||
1079 | kfree(vdev); | ||
1080 | return -1; | ||
1081 | } | ||
1082 | 1072 | ||
1083 | zoran_init_hardware(zr); | 1073 | zoran_init_hardware(zr); |
1084 | if (*zr_debug > 2) | 1074 | if (*zr_debug > 2) |
@@ -1092,6 +1082,13 @@ zr36057_init (struct zoran *zr) | |||
1092 | zr->zoran_proc = NULL; | 1082 | zr->zoran_proc = NULL; |
1093 | zr->initialized = 1; | 1083 | zr->initialized = 1; |
1094 | return 0; | 1084 | return 0; |
1085 | |||
1086 | exit_unregister: | ||
1087 | zoran_unregister_i2c(zr); | ||
1088 | exit_free: | ||
1089 | kfree(zr->stat_com); | ||
1090 | kfree(zr->video_dev); | ||
1091 | return err; | ||
1095 | } | 1092 | } |
1096 | 1093 | ||
1097 | static void | 1094 | static void |
@@ -1121,7 +1118,7 @@ zoran_release (struct zoran *zr) | |||
1121 | btwrite(0, ZR36057_SPGPPCR); | 1118 | btwrite(0, ZR36057_SPGPPCR); |
1122 | free_irq(zr->pci_dev->irq, zr); | 1119 | free_irq(zr->pci_dev->irq, zr); |
1123 | /* unmap and free memory */ | 1120 | /* unmap and free memory */ |
1124 | kfree((void *) zr->stat_com); | 1121 | kfree(zr->stat_com); |
1125 | zoran_proc_cleanup(zr); | 1122 | zoran_proc_cleanup(zr); |
1126 | iounmap(zr->zr36057_mem); | 1123 | iounmap(zr->zr36057_mem); |
1127 | pci_disable_device(zr->pci_dev); | 1124 | pci_disable_device(zr->pci_dev); |
@@ -1206,7 +1203,7 @@ find_zr36057 (void) | |||
1206 | zr->id = zoran_num; | 1203 | zr->id = zoran_num; |
1207 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); | 1204 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); |
1208 | spin_lock_init(&zr->spinlock); | 1205 | spin_lock_init(&zr->spinlock); |
1209 | init_MUTEX(&zr->resource_lock); | 1206 | mutex_init(&zr->resource_lock); |
1210 | if (pci_enable_device(dev)) | 1207 | if (pci_enable_device(dev)) |
1211 | continue; | 1208 | continue; |
1212 | zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0); | 1209 | zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0); |