summaryrefslogtreecommitdiff
path: root/drivers/media/video/bt8xx/bttv-driver.c
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2009-01-28 21:32:59 -0300
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 12:42:47 -0300
commit4b10d3b626922ffa2387905a230b12450281a12d (patch)
treed65429e98adf29ba08b6ddbf09e6ac78fcaaeac3 /drivers/media/video/bt8xx/bttv-driver.c
parent6f98700a5bb8d218162b04db1b8a3921a0dcc7ce (diff)
V4L/DVB (10568): bttv: dynamically allocate device data
The bttv driver had static array of structures for up to 16 possible bttv devices, even though few users have more than one or two. The structures were quite large and this resulted in a huge BSS segment. Change the driver to allocate the bttv device data dynamically, which changes "struct bttv bttvs[BTTV_MAX]" to "struct bttv *bttvs[BTTV_MAX]". It would be nice to get ride of "bttvs" entirely but there are some complications with gpio access from the audio & mpeg drivers. To help bttvs removal along anyway, I changed the open() methods use the video device's drvdata to get the driver data instead of looking it up in the bttvs array. This is also more efficient. Some WARN_ON()s are added in cases the device node exists by the bttv device doesn't, which I don't think should be possible. The gpio access functions need to check if bttvs[card] is NULL now. Though calling them on a non-existent card in the first place is wrong, but hard to solve given the fundamental problems in how the gpio access code works. This patch reduces the bss size by 66560 bytes on ia32. Overall change is a reduction of 66398 bytes, as the WARN_ON()s add some 198 bytes. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/bt8xx/bttv-driver.c')
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c45
1 files changed, 16 insertions, 29 deletions
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index ccf6aa6a975b..826ca60b42e6 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -58,7 +58,7 @@
unsigned int bttv_num; /* number of Bt848s in use */
-struct bttv bttvs[BTTV_MAX];
+struct bttv *bttvs[BTTV_MAX];
unsigned int bttv_debug;
unsigned int bttv_verbose = 1;
@@ -3217,29 +3217,19 @@ err:
static int bttv_open(struct file *file)
{
int minor = video_devdata(file)->minor;
- struct bttv *btv = NULL;
+ struct bttv *btv = video_drvdata(file);
struct bttv_fh *fh;
enum v4l2_buf_type type = 0;
- unsigned int i;
dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor);
lock_kernel();
- for (i = 0; i < bttv_num; i++) {
- if (bttvs[i].video_dev &&
- bttvs[i].video_dev->minor == minor) {
- btv = &bttvs[i];
- type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- break;
- }
- if (bttvs[i].vbi_dev &&
- bttvs[i].vbi_dev->minor == minor) {
- btv = &bttvs[i];
- type = V4L2_BUF_TYPE_VBI_CAPTURE;
- break;
- }
- }
- if (NULL == btv) {
+ if (btv->video_dev->minor == minor) {
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ } else if (btv->vbi_dev->minor == minor) {
+ type = V4L2_BUF_TYPE_VBI_CAPTURE;
+ } else {
+ WARN_ON(1);
unlock_kernel();
return -ENODEV;
}
@@ -3429,20 +3419,14 @@ static struct video_device bttv_video_template = {
static int radio_open(struct file *file)
{
int minor = video_devdata(file)->minor;
- struct bttv *btv = NULL;
+ struct bttv *btv = video_drvdata(file);
struct bttv_fh *fh;
- unsigned int i;
dprintk("bttv: open minor=%d\n",minor);
lock_kernel();
- for (i = 0; i < bttv_num; i++) {
- if (bttvs[i].radio_dev && bttvs[i].radio_dev->minor == minor) {
- btv = &bttvs[i];
- break;
- }
- }
- if (NULL == btv) {
+ WARN_ON(btv->radio_dev && btv->radio_dev->minor != minor);
+ if (!btv->radio_dev || btv->radio_dev->minor != minor) {
unlock_kernel();
return -ENODEV;
}
@@ -4203,6 +4187,7 @@ static struct video_device *vdev_init(struct bttv *btv,
vfd->parent = &btv->c.pci->dev;
vfd->release = video_device_release;
vfd->debug = bttv_debug;
+ video_set_drvdata(vfd, btv);
snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
type_name, bttv_tvcards[btv->c.type].name);
@@ -4312,8 +4297,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
if (bttv_num == BTTV_MAX)
return -ENOMEM;
printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num);
- btv=&bttvs[bttv_num];
- memset(btv,0,sizeof(*btv));
+ bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
btv->c.nr = bttv_num;
sprintf(btv->c.name,"bttv%d",btv->c.nr);
@@ -4517,6 +4501,9 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
pci_resource_len(btv->c.pci,0));
pci_set_drvdata(pci_dev, NULL);
+ bttvs[btv->c.nr] = NULL;
+ kfree(btv);
+
return;
}