mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-02-12 23:22:21 +00:00
V4L/DVB (10223): zoran: Remove global device array
The driver was keeping a global array with an entry for each zoran device probed. It was a leftover from when the driver didn't dynamically allocate the driver data for each device. There was only one use left, in the video device's ->open() method, looking up the struct zoran for the opened device from the minor number. This can be done better with video_get_drvdata(). Since zoran_num is now only used in the pci driver's ->probe() method, it doesn't need to be an atomic_t and be static. There is a race if multiple zoran cards could be probed at the same time, but currently the probe method for a given driver is single threaded. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Acked-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
45bdcefea2
commit
601139e083
@ -159,8 +159,7 @@ static struct pci_device_id zr36067_pci_tbl[] = {
|
|||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
|
MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
|
||||||
|
|
||||||
atomic_t zoran_num = ATOMIC_INIT(0); /* number of Buzs in use */
|
static unsigned int zoran_num; /* number of cards found */
|
||||||
struct zoran *zoran[BUZ_MAX];
|
|
||||||
|
|
||||||
/* videocodec bus functions ZR36060 */
|
/* videocodec bus functions ZR36060 */
|
||||||
static u32
|
static u32
|
||||||
@ -1144,6 +1143,7 @@ zr36057_init (struct zoran *zr)
|
|||||||
err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
|
err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto exit_free;
|
goto exit_free;
|
||||||
|
video_set_drvdata(zr->video_dev, zr);
|
||||||
|
|
||||||
zoran_init_hardware(zr);
|
zoran_init_hardware(zr);
|
||||||
if (zr36067_debug > 2)
|
if (zr36067_debug > 2)
|
||||||
@ -1275,7 +1275,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
|
|||||||
unsigned int nr;
|
unsigned int nr;
|
||||||
|
|
||||||
|
|
||||||
nr = atomic_inc_return(&zoran_num) - 1;
|
nr = zoran_num++;
|
||||||
if (nr >= BUZ_MAX) {
|
if (nr >= BUZ_MAX) {
|
||||||
dprintk(1,
|
dprintk(1,
|
||||||
KERN_ERR
|
KERN_ERR
|
||||||
@ -1291,7 +1291,6 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
|
|||||||
KERN_ERR
|
KERN_ERR
|
||||||
"%s: find_zr36057() - kzalloc failed\n",
|
"%s: find_zr36057() - kzalloc failed\n",
|
||||||
ZORAN_NAME);
|
ZORAN_NAME);
|
||||||
/* The entry in zoran[] gets leaked */
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
zr->pci_dev = pdev;
|
zr->pci_dev = pdev;
|
||||||
@ -1547,7 +1546,6 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
|
|||||||
goto zr_detach_vfe;
|
goto zr_detach_vfe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zoran[nr] = zr;
|
|
||||||
|
|
||||||
/* take care of Natoma chipset and a revision 1 zr36057 */
|
/* take care of Natoma chipset and a revision 1 zr36057 */
|
||||||
if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
|
if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
|
||||||
@ -1599,7 +1597,6 @@ static int __init zoran_init(void)
|
|||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
memset(zoran, 0, sizeof(zoran));
|
|
||||||
printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
|
printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
|
||||||
MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
|
MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
|
||||||
|
|
||||||
|
@ -40,8 +40,6 @@ extern int zr36067_debug;
|
|||||||
|
|
||||||
/* Anybody who uses more than four? */
|
/* Anybody who uses more than four? */
|
||||||
#define BUZ_MAX 4
|
#define BUZ_MAX 4
|
||||||
extern atomic_t zoran_num;
|
|
||||||
extern struct zoran *zoran[BUZ_MAX];
|
|
||||||
|
|
||||||
extern struct video_device zoran_template;
|
extern struct video_device zoran_template;
|
||||||
|
|
||||||
|
@ -1196,28 +1196,13 @@ zoran_close_end_session (struct file *file)
|
|||||||
* Open a zoran card. Right now the flags stuff is just playing
|
* Open a zoran card. Right now the flags stuff is just playing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int zoran_open(struct file *file)
|
||||||
zoran_open(struct file *file)
|
|
||||||
{
|
{
|
||||||
unsigned int minor = video_devdata(file)->minor;
|
struct zoran *zr = video_drvdata(file);
|
||||||
struct zoran *zr = NULL;
|
|
||||||
struct zoran_fh *fh;
|
struct zoran_fh *fh;
|
||||||
int i, res, first_open = 0, have_module_locks = 0;
|
int res, first_open = 0, have_module_locks = 0;
|
||||||
|
|
||||||
lock_kernel();
|
lock_kernel();
|
||||||
/* find the device */
|
|
||||||
for (i = 0; i < atomic_read(&zoran_num); i++) {
|
|
||||||
if (zoran[i]->video_dev->minor == minor) {
|
|
||||||
zr = zoran[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!zr) {
|
|
||||||
dprintk(1, KERN_ERR "%s: device not found!\n", ZORAN_NAME);
|
|
||||||
res = -ENODEV;
|
|
||||||
goto open_unlock_and_return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* see fs/device.c - the kernel already locks during open(),
|
/* see fs/device.c - the kernel already locks during open(),
|
||||||
* so locking ourselves only causes deadlocks */
|
* so locking ourselves only causes deadlocks */
|
||||||
@ -1329,10 +1314,6 @@ open_unlock_and_return:
|
|||||||
module_put(THIS_MODULE);
|
module_put(THIS_MODULE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if there's no device found, we didn't obtain the lock either */
|
|
||||||
if (zr) {
|
|
||||||
/*mutex_unlock(&zr->resource_lock);*/
|
|
||||||
}
|
|
||||||
unlock_kernel();
|
unlock_kernel();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user