diff options
author | Trent Piepho <xyzzy@speakeasy.org> | 2009-01-12 11:09:46 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-01-29 05:35:38 -0500 |
commit | 601139e08339b15997c6ae638dc5bf42c51ea204 (patch) | |
tree | 42e8e2b998b3f020ed7049ec9bc03f3439e79c0a /drivers | |
parent | 45bdcefea25cad2d7443f5b45a5319e2bd201048 (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/zoran/zoran_card.c | 9 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_card.h | 2 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_driver.c | 25 |
3 files changed, 6 insertions, 30 deletions
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c index ae96de08759d..117650fecd89 100644 --- a/drivers/media/video/zoran/zoran_card.c +++ b/drivers/media/video/zoran/zoran_card.c | |||
@@ -159,8 +159,7 @@ static struct pci_device_id zr36067_pci_tbl[] = { | |||
159 | }; | 159 | }; |
160 | MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); | 160 | MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); |
161 | 161 | ||
162 | atomic_t zoran_num = ATOMIC_INIT(0); /* number of Buzs in use */ | 162 | static unsigned int zoran_num; /* number of cards found */ |
163 | struct zoran *zoran[BUZ_MAX]; | ||
164 | 163 | ||
165 | /* videocodec bus functions ZR36060 */ | 164 | /* videocodec bus functions ZR36060 */ |
166 | static u32 | 165 | static u32 |
@@ -1144,6 +1143,7 @@ zr36057_init (struct zoran *zr) | |||
1144 | err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); | 1143 | err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); |
1145 | if (err < 0) | 1144 | if (err < 0) |
1146 | goto exit_free; | 1145 | goto exit_free; |
1146 | video_set_drvdata(zr->video_dev, zr); | ||
1147 | 1147 | ||
1148 | zoran_init_hardware(zr); | 1148 | zoran_init_hardware(zr); |
1149 | if (zr36067_debug > 2) | 1149 | if (zr36067_debug > 2) |
@@ -1275,7 +1275,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1275 | unsigned int nr; | 1275 | unsigned int nr; |
1276 | 1276 | ||
1277 | 1277 | ||
1278 | nr = atomic_inc_return(&zoran_num) - 1; | 1278 | nr = zoran_num++; |
1279 | if (nr >= BUZ_MAX) { | 1279 | if (nr >= BUZ_MAX) { |
1280 | dprintk(1, | 1280 | dprintk(1, |
1281 | KERN_ERR | 1281 | KERN_ERR |
@@ -1291,7 +1291,6 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1291 | KERN_ERR | 1291 | KERN_ERR |
1292 | "%s: find_zr36057() - kzalloc failed\n", | 1292 | "%s: find_zr36057() - kzalloc failed\n", |
1293 | ZORAN_NAME); | 1293 | ZORAN_NAME); |
1294 | /* The entry in zoran[] gets leaked */ | ||
1295 | return -ENOMEM; | 1294 | return -ENOMEM; |
1296 | } | 1295 | } |
1297 | zr->pci_dev = pdev; | 1296 | zr->pci_dev = pdev; |
@@ -1547,7 +1546,6 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1547 | goto zr_detach_vfe; | 1546 | goto zr_detach_vfe; |
1548 | } | 1547 | } |
1549 | } | 1548 | } |
1550 | zoran[nr] = zr; | ||
1551 | 1549 | ||
1552 | /* take care of Natoma chipset and a revision 1 zr36057 */ | 1550 | /* take care of Natoma chipset and a revision 1 zr36057 */ |
1553 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { | 1551 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { |
@@ -1599,7 +1597,6 @@ static int __init zoran_init(void) | |||
1599 | { | 1597 | { |
1600 | int res; | 1598 | int res; |
1601 | 1599 | ||
1602 | memset(zoran, 0, sizeof(zoran)); | ||
1603 | printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n", | 1600 | printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n", |
1604 | MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION); | 1601 | MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION); |
1605 | 1602 | ||
diff --git a/drivers/media/video/zoran/zoran_card.h b/drivers/media/video/zoran/zoran_card.h index c989448a77de..4507bdc5e338 100644 --- a/drivers/media/video/zoran/zoran_card.h +++ b/drivers/media/video/zoran/zoran_card.h | |||
@@ -40,8 +40,6 @@ extern int zr36067_debug; | |||
40 | 40 | ||
41 | /* Anybody who uses more than four? */ | 41 | /* Anybody who uses more than four? */ |
42 | #define BUZ_MAX 4 | 42 | #define BUZ_MAX 4 |
43 | extern atomic_t zoran_num; | ||
44 | extern struct zoran *zoran[BUZ_MAX]; | ||
45 | 43 | ||
46 | extern struct video_device zoran_template; | 44 | extern struct video_device zoran_template; |
47 | 45 | ||
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c index 5e667fd72725..21f37a68714b 100644 --- a/drivers/media/video/zoran/zoran_driver.c +++ b/drivers/media/video/zoran/zoran_driver.c | |||
@@ -1196,28 +1196,13 @@ zoran_close_end_session (struct file *file) | |||
1196 | * Open a zoran card. Right now the flags stuff is just playing | 1196 | * Open a zoran card. Right now the flags stuff is just playing |
1197 | */ | 1197 | */ |
1198 | 1198 | ||
1199 | static int | 1199 | static int zoran_open(struct file *file) |
1200 | zoran_open(struct file *file) | ||
1201 | { | 1200 | { |
1202 | unsigned int minor = video_devdata(file)->minor; | 1201 | struct zoran *zr = video_drvdata(file); |
1203 | struct zoran *zr = NULL; | ||
1204 | struct zoran_fh *fh; | 1202 | struct zoran_fh *fh; |
1205 | int i, res, first_open = 0, have_module_locks = 0; | 1203 | int res, first_open = 0, have_module_locks = 0; |
1206 | 1204 | ||
1207 | lock_kernel(); | 1205 | lock_kernel(); |
1208 | /* find the device */ | ||
1209 | for (i = 0; i < atomic_read(&zoran_num); i++) { | ||
1210 | if (zoran[i]->video_dev->minor == minor) { | ||
1211 | zr = zoran[i]; | ||
1212 | break; | ||
1213 | } | ||
1214 | } | ||
1215 | |||
1216 | if (!zr) { | ||
1217 | dprintk(1, KERN_ERR "%s: device not found!\n", ZORAN_NAME); | ||
1218 | res = -ENODEV; | ||
1219 | goto open_unlock_and_return; | ||
1220 | } | ||
1221 | 1206 | ||
1222 | /* see fs/device.c - the kernel already locks during open(), | 1207 | /* see fs/device.c - the kernel already locks during open(), |
1223 | * so locking ourselves only causes deadlocks */ | 1208 | * so locking ourselves only causes deadlocks */ |
@@ -1329,10 +1314,6 @@ open_unlock_and_return: | |||
1329 | module_put(THIS_MODULE); | 1314 | module_put(THIS_MODULE); |
1330 | } | 1315 | } |
1331 | 1316 | ||
1332 | /* if there's no device found, we didn't obtain the lock either */ | ||
1333 | if (zr) { | ||
1334 | /*mutex_unlock(&zr->resource_lock);*/ | ||
1335 | } | ||
1336 | unlock_kernel(); | 1317 | unlock_kernel(); |
1337 | 1318 | ||
1338 | return res; | 1319 | return res; |