Re: [v4l-dvb-maintainer] Re: [PATCH] V4L: struct video_devicecorruption

From: Trent Piepho
Date: Sun Jul 23 2006 - 22:14:04 EST


On Sun, 23 Jul 2006, Mauro Carvalho Chehab wrote:
> Ok, I had some time to fix the broken dependencies. Please look at the
> two commits I did today.

Two things I noticed. bttv didn't use to _require_ V4L1. I use bttv and have
V4L1 turned off. I guess this is just because bttv ignored the V4L1 setting?

Second, the fix for class_device_create_file() doesn't roll-back properly
on failure. I already posted a patch which does this correctly. Attached
is the patch against the current Hg, go ahead and import it.

Also attached is patch to bttv-driver.c that has it use
class_device_create_file(), with an error message and handling of failure.


> One patch removes HAVE_V4L1 check at drivers. It also include some checks for
> V4L1_COMPAT on some core files that should implement both calls to provide
> support for V4L1 drivers.
>
> The other fixes the broken dependencies for drivers that still need V4L1
> to work properly.
>
> Cheers,
> Mauro.
>
> Em Sex, 2006-07-21 ās 15:55 -0700, Trent Piepho escreveu:
> > On Fri, 21 Jul 2006, Mauro Carvalho Chehab wrote:
> > > config VIDEO_BT848
> > > tristate "BT848 Video For Linux"
> > > depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2
> > >
> > > Argh! it should be V4L1 instead!
> >
> > You can compile and use bt848 without V4L1 turned on. It still has some
> > V4L1 functions defined.
> >
> > > > All these files include v4l2-dev.h and have HAVE_V4L1 defined when V4L1 is
> > > > not turned on in Kconfig. There files are all buildable when V4L1 is off;
> > > > they don't depend on it in Kconfig.
> > > Some of the above drivers are V4L2, like tda9887, tuner-core,
> > > tuner-simple, msp3400, cs53l32a, tveeprom, wm87xx. Maybe they are just
> > > including the wrong headers. We should try to change to videodev2.h and
> > > see what happens with all those drivers. The ones that break should me
> > > marked with the proper requirement on Kconfig.
> > >
> > > Some of they need some #ifdef inside. For example, compat_ioctl32 should
> > > handle both APIs, since it is a generic code to fix 32 bit calls to 64
> > > bit kernel.
> >
> > I think this is pretty much what I've been saying. Drivers should:
> > A. Not include videodev.h, but use videodev2.h
> > B. Include videodev.h, but be marked V4L1 in Kconfig
> > C. #ifdef around videodev.h (and code that needs videodev.h), so it
> > is not included or needed when V4L1 is turned off.
> Cheers,
> Mauro.
>
># HG changeset patch
# User Trent Piepho <xyzzy@xxxxxxxxxxxxx>
# Node ID b900796fdfb4bc87642c470515f88ed7ae92ced3
# Parent e33331856212e707150dc85fda486240eb7feae0
Handle class_device_create_file errors

From: Trent Piepho <xyzzy@xxxxxxxxxxxxx>

Add proper error checking and roll-back for failure of
class_device_create_file() in videodev.c. Print error messages and
unroll partially created sysfs entries.

Also, failure of class_device_register() in video_register_device() is
handled correctly. It was failing to de-allocate the minor number. This
must be done in video_register_device(), since the caller has no way of
knowing if failure occurred before or after the class device was
registered.

Also added an error message if video_register_device() is called with
an unknown type, which should never happen.

Signed-off-by: Trent Piepho <xyzzy@xxxxxxxxxxxxx>

diff -r e33331856212 -r b900796fdfb4 linux/drivers/media/video/videodev.c
--- a/linux/drivers/media/video/videodev.c Sun Jul 23 18:36:01 2006 -0700
+++ b/linux/drivers/media/video/videodev.c Sun Jul 23 19:08:21 2006 -0700
@@ -1557,6 +1557,8 @@ int video_register_device(struct video_d
name_base = "radio";
break;
default:
+ printk(KERN_ERR "%s called with unknown type: %d\n",
+ __FUNCTION__, type);
return -1;
}

@@ -1597,18 +1599,20 @@ int video_register_device(struct video_d
if (ret) {
printk(KERN_ERR "%s: class_device_register failed\n",
__FUNCTION__);
- return ret;
- }
- ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
- if (ret < 0) {
- printk(KERN_WARNING "%s error: %d\n", __FUNCTION__, ret);
- return ret;
+ goto fail_minor;
+ }
+ ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
+ if (ret) {
+ printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
+ __FUNCTION__);
+ goto fail_classdev;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
- ret = class_device_create_file(&vfd->class_dev, &class_device_attr_dev);
- if (ret < 0) {
- printk(KERN_WARNING "%s error: %d\n", __FUNCTION__, ret);
- return ret;
+ ret = class_device_create_file(&vfd->class_dev, &class_device_attr_dev);
+ if (ret) {
+ printk(KERN_ERR "%s: class_device_create_file 'dev' failed\n",
+ __FUNCTION__);
+ goto fail_classdev;
}
#endif

@@ -1620,6 +1624,15 @@ int video_register_device(struct video_d
"http://lwn.net/Articles/36850/\n";, vfd->name);
#endif
return 0;
+
+fail_classdev:
+ class_device_unregister(&vfd->class_dev);
+fail_minor:
+ mutex_lock(&videodev_lock);
+ video_device[vfd->minor] = NULL;
+ vfd->minor = -1;
+ mutex_unlock(&videodev_lock);
+ return ret;
}

/**
# HG changeset patch
# User Trent Piepho <xyzzy@xxxxxxxxxxxxx>
# Node ID 092b04007c0f1aa2d3f9b4467ea8ab3837723196
# Parent b900796fdfb4bc87642c470515f88ed7ae92ced3
bttv: use class_device_create_file and handle errors

From: Trent Piepho <xyzzy@xxxxxxxxxxxxx>

Revery bttv-driver.c from video_device_create_file() to use
class_device_create_file() again. video_device_create_file() is only
available when V4L1 is on.

Proper error checking is added for failure of class_device_create_file().
Will print error message and unroll partially created sysfs entries.

Signed-off-by: Trent Piepho <xyzzy@xxxxxxxxxxxxx>

diff -r b900796fdfb4 -r 092b04007c0f linux/drivers/media/video/bt8xx/bttv-driver.c
--- a/linux/drivers/media/video/bt8xx/bttv-driver.c Sun Jul 23 19:08:21 2006 -0700
+++ b/linux/drivers/media/video/bt8xx/bttv-driver.c Sun Jul 23 19:10:52 2006 -0700
@@ -3957,8 +3957,12 @@ static int __devinit bttv_register_video
printk(KERN_INFO "bttv%d: registered device video%d\n",
btv->c.nr,btv->video_dev->minor & 0x1f);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
-
- video_device_create_file(btv->video_dev, &class_device_attr_card);
+ if (class_device_create_file(&btv->video_dev->class_dev,
+ &class_device_attr_card)<0) {
+ printk(KERN_ERR "bttv%d: class_device_create_file 'card' "
+ "failed\n", btv->c.nr);
+ goto err;
+ }
#endif

/* vbi */