X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fmedia%2Fvideo%2Fzoran_card.c;fp=drivers%2Fmedia%2Fvideo%2Fzoran_card.c;h=0a85c9e7fb4824803abdf0801268bfbb9ac695bd;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=25743085b2d5a97a1a800939aad63ba5eb5c20ca;hpb=cee37fe97739d85991964371c1f3a745c00dd236;p=linux-2.6.git diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c index 25743085b..0a85c9e7f 100644 --- a/drivers/media/video/zoran_card.c +++ b/drivers/media/video/zoran_card.c @@ -4,7 +4,7 @@ * Media Labs LML33/LML33R10. * * This part handles card-specific data and detection - * + * * Copyright (C) 2000 Serguei Miridonov * * Currently maintained by: @@ -47,6 +47,7 @@ #include #include #include +#include #include @@ -673,7 +674,7 @@ zoran_i2c_client_register (struct i2c_client *client) KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n", ZR_DEVNAME(zr), client->driver->id); - down(&zr->resource_lock); + mutex_lock(&zr->resource_lock); if (zr->user > 0) { /* we're already busy, so we keep a reference to @@ -694,7 +695,7 @@ zoran_i2c_client_register (struct i2c_client *client) } clientreg_unlock_and_return: - up(&zr->resource_lock); + mutex_unlock(&zr->resource_lock); return res; } @@ -707,7 +708,7 @@ zoran_i2c_client_unregister (struct i2c_client *client) dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr)); - down(&zr->resource_lock); + mutex_lock(&zr->resource_lock); if (zr->user > 0) { res = -EBUSY; @@ -722,7 +723,7 @@ zoran_i2c_client_unregister (struct i2c_client *client) snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id); } clientunreg_unlock_and_return: - up(&zr->resource_lock); + mutex_unlock(&zr->resource_lock); return res; } @@ -737,7 +738,7 @@ static struct i2c_algo_bit_data zoran_i2c_bit_data_template = { }; static struct i2c_adapter zoran_i2c_adapter_template = { - I2C_DEVNAME("zr36057"), + .name = "zr36057", .id = I2C_HW_B_ZR36067, .algo = NULL, .client_register = zoran_i2c_client_register, @@ -995,10 +996,7 @@ test_interrupts (struct zoran *zr) static int __devinit zr36057_init (struct zoran *zr) { - unsigned long mem; - void *vdev; - unsigned mem_needed; - int j; + int j, err; int two = 2; int zero = 0; @@ -1049,22 +1047,16 @@ zr36057_init (struct zoran *zr) /* allocate memory *before* doing anything to the hardware * in case allocation fails */ - mem_needed = BUZ_NUM_STAT_COM * 4; - mem = (unsigned long) kmalloc(mem_needed, GFP_KERNEL); - vdev = (void *) kmalloc(sizeof(struct video_device), GFP_KERNEL); - if (!mem || !vdev) { + zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL); + zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL); + if (!zr->stat_com || !zr->video_dev) { dprintk(1, KERN_ERR "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", ZR_DEVNAME(zr)); - if (vdev) - kfree(vdev); - if (mem) - kfree((void *)mem); - return -ENOMEM; + err = -ENOMEM; + goto exit_free; } - memset((void *) mem, 0, mem_needed); - zr->stat_com = (u32 *) mem; for (j = 0; j < BUZ_NUM_STAT_COM; j++) { zr->stat_com[j] = 1; /* mark as unavailable to zr36057 */ } @@ -1072,16 +1064,11 @@ zr36057_init (struct zoran *zr) /* * Now add the template and register the device unit. */ - zr->video_dev = vdev; memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); - if (video_register_device(zr->video_dev, VFL_TYPE_GRABBER, - video_nr) < 0) { - zoran_unregister_i2c(zr); - kfree((void *) zr->stat_com); - kfree(vdev); - return -1; - } + err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr); + if (err < 0) + goto exit_unregister; zoran_init_hardware(zr); if (*zr_debug > 2) @@ -1095,6 +1082,13 @@ zr36057_init (struct zoran *zr) zr->zoran_proc = NULL; zr->initialized = 1; return 0; + +exit_unregister: + zoran_unregister_i2c(zr); +exit_free: + kfree(zr->stat_com); + kfree(zr->video_dev); + return err; } static void @@ -1105,15 +1099,15 @@ zoran_release (struct zoran *zr) /* unregister videocodec bus */ if (zr->codec) { struct videocodec_master *master = zr->codec->master_data; + videocodec_detach(zr->codec); - if (master) - kfree(master); + kfree(master); } if (zr->vfe) { struct videocodec_master *master = zr->vfe->master_data; + videocodec_detach(zr->vfe); - if (master) - kfree(master); + kfree(master); } /* unregister i2c bus */ @@ -1124,7 +1118,7 @@ zoran_release (struct zoran *zr) btwrite(0, ZR36057_SPGPPCR); free_irq(zr->pci_dev->irq, zr); /* unmap and free memory */ - kfree((void *) zr->stat_com); + kfree(zr->stat_com); zoran_proc_cleanup(zr); iounmap(zr->zr36057_mem); pci_disable_device(zr->pci_dev); @@ -1209,7 +1203,7 @@ find_zr36057 (void) zr->id = zoran_num; snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); spin_lock_init(&zr->spinlock); - init_MUTEX(&zr->resource_lock); + mutex_init(&zr->resource_lock); if (pci_enable_device(dev)) continue; zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);