diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-07-14 08:51:03 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-07-26 12:18:27 -0400 |
commit | 85b9b8a444413ea5706096df13012520ed6c5103 (patch) | |
tree | 00ec051e365b13c2c6937c29c1cb08f9571965d0 /drivers/media | |
parent | 54812c77bc830e2dbcb62b4c6d8a9c7f97cfdd1b (diff) |
V4L/DVB (8499): zr36067: Rework device memory allocation
Allocate zoran devices dynamically. Currently, the zr36067 driver
stores the device structures in a global array, with room for 4
devices. This makes the bss section very large (90 kB!), and given
that most users, I suspect, have only one zoran device, this is a
waste of kernel memory. Allocating the memory dynamically lets us use
only the amount of memory we need.
Before:
text data bss dec hex filename
64754 9230 90224 164208 28170 drivers/media/video/zr36067.o
After:
text data bss dec hex filename
64866 9230 112 74208 121e0 drivers/media/video/zr36067.o
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Ronald Bultje <rbultje@ronald.bitfreak.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/video/zoran_card.c | 36 | ||||
-rw-r--r-- | drivers/media/video/zoran_card.h | 2 | ||||
-rw-r--r-- | drivers/media/video/zoran_driver.c | 4 |
3 files changed, 26 insertions, 16 deletions
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c index 0929edb2d4f1..38d7ed858812 100644 --- a/drivers/media/video/zoran_card.c +++ b/drivers/media/video/zoran_card.c | |||
@@ -161,7 +161,7 @@ static struct pci_device_id zr36067_pci_tbl[] = { | |||
161 | MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); | 161 | MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); |
162 | 162 | ||
163 | int zoran_num; /* number of Buzs in use */ | 163 | int zoran_num; /* number of Buzs in use */ |
164 | struct zoran zoran[BUZ_MAX]; | 164 | struct zoran *zoran[BUZ_MAX]; |
165 | 165 | ||
166 | /* videocodec bus functions ZR36060 */ | 166 | /* videocodec bus functions ZR36060 */ |
167 | static u32 | 167 | static u32 |
@@ -1164,7 +1164,7 @@ static void | |||
1164 | zoran_release (struct zoran *zr) | 1164 | zoran_release (struct zoran *zr) |
1165 | { | 1165 | { |
1166 | if (!zr->initialized) | 1166 | if (!zr->initialized) |
1167 | return; | 1167 | goto exit_free; |
1168 | /* unregister videocodec bus */ | 1168 | /* unregister videocodec bus */ |
1169 | if (zr->codec) { | 1169 | if (zr->codec) { |
1170 | struct videocodec_master *master = zr->codec->master_data; | 1170 | struct videocodec_master *master = zr->codec->master_data; |
@@ -1192,6 +1192,8 @@ zoran_release (struct zoran *zr) | |||
1192 | iounmap(zr->zr36057_mem); | 1192 | iounmap(zr->zr36057_mem); |
1193 | pci_disable_device(zr->pci_dev); | 1193 | pci_disable_device(zr->pci_dev); |
1194 | video_unregister_device(zr->video_dev); | 1194 | video_unregister_device(zr->video_dev); |
1195 | exit_free: | ||
1196 | kfree(zr); | ||
1195 | } | 1197 | } |
1196 | 1198 | ||
1197 | void | 1199 | void |
@@ -1269,8 +1271,14 @@ find_zr36057 (void) | |||
1269 | while (zoran_num < BUZ_MAX && | 1271 | while (zoran_num < BUZ_MAX && |
1270 | (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) { | 1272 | (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) { |
1271 | card_num = card[zoran_num]; | 1273 | card_num = card[zoran_num]; |
1272 | zr = &zoran[zoran_num]; | 1274 | zr = kzalloc(sizeof(struct zoran), GFP_KERNEL); |
1273 | memset(zr, 0, sizeof(struct zoran)); // Just in case if previous cycle failed | 1275 | if (!zr) { |
1276 | dprintk(1, | ||
1277 | KERN_ERR | ||
1278 | "%s: find_zr36057() - kzalloc failed\n", | ||
1279 | ZORAN_NAME); | ||
1280 | continue; | ||
1281 | } | ||
1274 | zr->pci_dev = dev; | 1282 | zr->pci_dev = dev; |
1275 | //zr->zr36057_mem = NULL; | 1283 | //zr->zr36057_mem = NULL; |
1276 | zr->id = zoran_num; | 1284 | zr->id = zoran_num; |
@@ -1278,7 +1286,7 @@ find_zr36057 (void) | |||
1278 | spin_lock_init(&zr->spinlock); | 1286 | spin_lock_init(&zr->spinlock); |
1279 | mutex_init(&zr->resource_lock); | 1287 | mutex_init(&zr->resource_lock); |
1280 | if (pci_enable_device(dev)) | 1288 | if (pci_enable_device(dev)) |
1281 | continue; | 1289 | goto zr_free_mem; |
1282 | zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0); | 1290 | zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0); |
1283 | pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, | 1291 | pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, |
1284 | &zr->revision); | 1292 | &zr->revision); |
@@ -1294,7 +1302,7 @@ find_zr36057 (void) | |||
1294 | KERN_ERR | 1302 | KERN_ERR |
1295 | "%s: find_zr36057() - no card specified, please use the card=X insmod option\n", | 1303 | "%s: find_zr36057() - no card specified, please use the card=X insmod option\n", |
1296 | ZR_DEVNAME(zr)); | 1304 | ZR_DEVNAME(zr)); |
1297 | continue; | 1305 | goto zr_free_mem; |
1298 | } | 1306 | } |
1299 | } else { | 1307 | } else { |
1300 | int i; | 1308 | int i; |
@@ -1333,7 +1341,7 @@ find_zr36057 (void) | |||
1333 | KERN_ERR | 1341 | KERN_ERR |
1334 | "%s: find_zr36057() - unknown card\n", | 1342 | "%s: find_zr36057() - unknown card\n", |
1335 | ZR_DEVNAME(zr)); | 1343 | ZR_DEVNAME(zr)); |
1336 | continue; | 1344 | goto zr_free_mem; |
1337 | } | 1345 | } |
1338 | } | 1346 | } |
1339 | } | 1347 | } |
@@ -1343,7 +1351,7 @@ find_zr36057 (void) | |||
1343 | KERN_ERR | 1351 | KERN_ERR |
1344 | "%s: find_zr36057() - invalid cardnum %d\n", | 1352 | "%s: find_zr36057() - invalid cardnum %d\n", |
1345 | ZR_DEVNAME(zr), card_num); | 1353 | ZR_DEVNAME(zr), card_num); |
1346 | continue; | 1354 | goto zr_free_mem; |
1347 | } | 1355 | } |
1348 | 1356 | ||
1349 | /* even though we make this a non pointer and thus | 1357 | /* even though we make this a non pointer and thus |
@@ -1361,7 +1369,7 @@ find_zr36057 (void) | |||
1361 | KERN_ERR | 1369 | KERN_ERR |
1362 | "%s: find_zr36057() - ioremap failed\n", | 1370 | "%s: find_zr36057() - ioremap failed\n", |
1363 | ZR_DEVNAME(zr)); | 1371 | ZR_DEVNAME(zr)); |
1364 | continue; | 1372 | goto zr_free_mem; |
1365 | } | 1373 | } |
1366 | 1374 | ||
1367 | result = request_irq(zr->pci_dev->irq, | 1375 | result = request_irq(zr->pci_dev->irq, |
@@ -1530,7 +1538,7 @@ find_zr36057 (void) | |||
1530 | } | 1538 | } |
1531 | /* Success so keep the pci_dev referenced */ | 1539 | /* Success so keep the pci_dev referenced */ |
1532 | pci_dev_get(zr->pci_dev); | 1540 | pci_dev_get(zr->pci_dev); |
1533 | zoran_num++; | 1541 | zoran[zoran_num++] = zr; |
1534 | continue; | 1542 | continue; |
1535 | 1543 | ||
1536 | // Init errors | 1544 | // Init errors |
@@ -1549,6 +1557,8 @@ find_zr36057 (void) | |||
1549 | free_irq(zr->pci_dev->irq, zr); | 1557 | free_irq(zr->pci_dev->irq, zr); |
1550 | zr_unmap: | 1558 | zr_unmap: |
1551 | iounmap(zr->zr36057_mem); | 1559 | iounmap(zr->zr36057_mem); |
1560 | zr_free_mem: | ||
1561 | kfree(zr); | ||
1552 | continue; | 1562 | continue; |
1553 | } | 1563 | } |
1554 | if (dev) /* Clean up ref count on early exit */ | 1564 | if (dev) /* Clean up ref count on early exit */ |
@@ -1620,7 +1630,7 @@ init_dc10_cards (void) | |||
1620 | 1630 | ||
1621 | /* take care of Natoma chipset and a revision 1 zr36057 */ | 1631 | /* take care of Natoma chipset and a revision 1 zr36057 */ |
1622 | for (i = 0; i < zoran_num; i++) { | 1632 | for (i = 0; i < zoran_num; i++) { |
1623 | struct zoran *zr = &zoran[i]; | 1633 | struct zoran *zr = zoran[i]; |
1624 | 1634 | ||
1625 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { | 1635 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { |
1626 | zr->jpg_buffers.need_contiguous = 1; | 1636 | zr->jpg_buffers.need_contiguous = 1; |
@@ -1632,7 +1642,7 @@ init_dc10_cards (void) | |||
1632 | 1642 | ||
1633 | if (zr36057_init(zr) < 0) { | 1643 | if (zr36057_init(zr) < 0) { |
1634 | for (i = 0; i < zoran_num; i++) | 1644 | for (i = 0; i < zoran_num; i++) |
1635 | zoran_release(&zoran[i]); | 1645 | zoran_release(zoran[i]); |
1636 | return -EIO; | 1646 | return -EIO; |
1637 | } | 1647 | } |
1638 | zoran_proc_init(zr); | 1648 | zoran_proc_init(zr); |
@@ -1647,7 +1657,7 @@ unload_dc10_cards (void) | |||
1647 | int i; | 1657 | int i; |
1648 | 1658 | ||
1649 | for (i = 0; i < zoran_num; i++) | 1659 | for (i = 0; i < zoran_num; i++) |
1650 | zoran_release(&zoran[i]); | 1660 | zoran_release(zoran[i]); |
1651 | } | 1661 | } |
1652 | 1662 | ||
1653 | module_init(init_dc10_cards); | 1663 | module_init(init_dc10_cards); |
diff --git a/drivers/media/video/zoran_card.h b/drivers/media/video/zoran_card.h index 1b5c4171cf9c..e4dc9d29b404 100644 --- a/drivers/media/video/zoran_card.h +++ b/drivers/media/video/zoran_card.h | |||
@@ -41,7 +41,7 @@ extern int zr36067_debug; | |||
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 int zoran_num; | 43 | extern int zoran_num; |
44 | extern struct zoran zoran[BUZ_MAX]; | 44 | extern struct zoran *zoran[BUZ_MAX]; |
45 | 45 | ||
46 | extern struct video_device zoran_template; | 46 | extern struct video_device zoran_template; |
47 | 47 | ||
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c index e1e1b19a0aed..3ca58221d5a9 100644 --- a/drivers/media/video/zoran_driver.c +++ b/drivers/media/video/zoran_driver.c | |||
@@ -1213,8 +1213,8 @@ zoran_open (struct inode *inode, | |||
1213 | 1213 | ||
1214 | /* find the device */ | 1214 | /* find the device */ |
1215 | for (i = 0; i < zoran_num; i++) { | 1215 | for (i = 0; i < zoran_num; i++) { |
1216 | if (zoran[i].video_dev->minor == minor) { | 1216 | if (zoran[i]->video_dev->minor == minor) { |
1217 | zr = &zoran[i]; | 1217 | zr = zoran[i]; |
1218 | break; | 1218 | break; |
1219 | } | 1219 | } |
1220 | } | 1220 | } |