Commit 4b10d3b6 authored by Trent Piepho's avatar Trent Piepho Committed by Mauro Carvalho Chehab

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: default avatarTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 6f98700a
......@@ -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 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
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];
if (btv->video_dev->minor == minor) {
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
break;
}
if (bttvs[i].vbi_dev &&
bttvs[i].vbi_dev->minor == minor) {
btv = &bttvs[i];
} else if (btv->vbi_dev->minor == minor) {
type = V4L2_BUF_TYPE_VBI_CAPTURE;
break;
}
}
if (NULL == btv) {
} 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;
}
......
......@@ -47,7 +47,10 @@ struct pci_dev* bttv_get_pcidev(unsigned int card)
{
if (card >= bttv_num)
return NULL;
return bttvs[card].c.pci;
if (!bttvs[card])
return NULL;
return bttvs[card]->c.pci;
}
......@@ -59,7 +62,10 @@ int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data)
return -EINVAL;
}
btv = &bttvs[card];
btv = bttvs[card];
if (!btv)
return -ENODEV;
gpio_inout(mask,data);
if (bttv_gpio)
bttv_gpio_tracking(btv,"extern enable");
......@@ -74,7 +80,9 @@ int bttv_read_gpio(unsigned int card, unsigned long *data)
return -EINVAL;
}
btv = &bttvs[card];
btv = bttvs[card];
if (!btv)
return -ENODEV;
if(btv->shutdown) {
return -ENODEV;
......@@ -94,7 +102,9 @@ int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
return -EINVAL;
}
btv = &bttvs[card];
btv = bttvs[card];
if (!btv)
return -ENODEV;
/* prior setting BT848_GPIO_REG_INP is (probably) not needed
because direct input is set on init */
......
......@@ -462,7 +462,7 @@ struct bttv {
/* our devices */
#define BTTV_MAX 32
extern unsigned int bttv_num;
extern struct bttv bttvs[BTTV_MAX];
extern struct bttv *bttvs[BTTV_MAX];
static inline unsigned int bttv_muxsel(const struct bttv *btv,
unsigned int input)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment