aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/vivi.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2008-09-03 16:11:53 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-09-03 17:37:12 -0400
commit980d4f17345fe420fda2a84cd4a28d5d41d73cef (patch)
tree23a7abc26273cf6021f5e82b52e1d06f6d0b47f4 /drivers/media/video/vivi.c
parentf3b9f50ef771670b5d94c568241d6766691c6c18 (diff)
V4L/DVB (8751): vivi: Fix some issues at vivi register routine
This patch fixes several small issues at vivi register routines: 1) minor and n_devs should be unsigned; 2) n_devs = 0 were not properly handled; 3) if n_devs specify a high number, the driver would just roll back and won't register any device. The proper behaviour is to keep all succeded devices registered; 4) both n_devs and minor were using 0 as permissions. Better to have them with 0444. With the current patch, if n_devs specify a very large value, it will register all possible devices. For example, on a machine without any other V4L drivers loaded, with this patch, we will have something like: vivi: V4L2 device registered as /dev/video0 vivi: V4L2 device registered as /dev/video1 vivi: V4L2 device registered as /dev/video2 ... vivi: V4L2 device registered as /dev/video31 video_register_device_index: get_index failed Video Technology Magazine Virtual Video Capture Board ver 0.5.0 successfully loaded. 5) The number of allocated devices on success is now kept at n_devs: $ cat /sys/module/vivi/parameters/n_devs 32 Thanks to Henne <henne@nachtwindheim.de> for pointing that there were some issues at vivi. Cc: Henne <henne@nachtwindheim.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/vivi.c')
-rw-r--r--drivers/media/video/vivi.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 3518af071a2e..f55d77db1558 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -1104,19 +1104,29 @@ static struct video_device vivi_template = {
1104 Initialization and module stuff 1104 Initialization and module stuff
1105 ------------------------------------------------------------------*/ 1105 ------------------------------------------------------------------*/
1106 1106
1107/* This routine allocates from 1 to n_devs virtual drivers.
1108
1109 The real maximum number of virtual drivers will depend on how many drivers
1110 will succeed. This is limited to the maximum number of devices that
1111 videodev supports. Since there are 64 minors for video grabbers, this is
1112 currently the theoretical maximum limit. However, a further limit does
1113 exist at videodev that forbids any driver to register more than 32 video
1114 grabbers.
1115 */
1107static int __init vivi_init(void) 1116static int __init vivi_init(void)
1108{ 1117{
1109 int ret = -ENOMEM, i; 1118 int ret = -ENOMEM, i;
1110 struct vivi_dev *dev; 1119 struct vivi_dev *dev;
1111 struct video_device *vfd; 1120 struct video_device *vfd;
1112 1121
1122 if (n_devs <= 0)
1123 n_devs = 1;
1124
1113 for (i = 0; i < n_devs; i++) { 1125 for (i = 0; i < n_devs; i++) {
1114 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1126 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1115 if (NULL == dev) 1127 if (!dev)
1116 break; 1128 break;
1117 1129
1118 list_add_tail(&dev->vivi_devlist, &vivi_devlist);
1119
1120 /* init video dma queues */ 1130 /* init video dma queues */
1121 INIT_LIST_HEAD(&dev->vidq.active); 1131 INIT_LIST_HEAD(&dev->vidq.active);
1122 init_waitqueue_head(&dev->vidq.wq); 1132 init_waitqueue_head(&dev->vidq.wq);
@@ -1126,14 +1136,27 @@ static int __init vivi_init(void)
1126 mutex_init(&dev->mutex); 1136 mutex_init(&dev->mutex);
1127 1137
1128 vfd = video_device_alloc(); 1138 vfd = video_device_alloc();
1129 if (NULL == vfd) 1139 if (!vfd) {
1140 kfree(dev);
1130 break; 1141 break;
1142 }
1131 1143
1132 *vfd = vivi_template; 1144 *vfd = vivi_template;
1133 1145
1134 ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr); 1146 ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
1135 if (ret < 0) 1147 if (ret < 0) {
1148 video_device_release(vfd);
1149 kfree(dev);
1150
1151 /* If some registers succeeded, keep driver */
1152 if (i)
1153 ret = 0;
1154
1136 break; 1155 break;
1156 }
1157
1158 /* Now that everything is fine, let's add it to device list */
1159 list_add_tail(&dev->vivi_devlist, &vivi_devlist);
1137 1160
1138 snprintf(vfd->name, sizeof(vfd->name), "%s (%i)", 1161 snprintf(vfd->name, sizeof(vfd->name), "%s (%i)",
1139 vivi_template.name, vfd->minor); 1162 vivi_template.name, vfd->minor);
@@ -1149,11 +1172,16 @@ static int __init vivi_init(void)
1149 if (ret < 0) { 1172 if (ret < 0) {
1150 vivi_release(); 1173 vivi_release();
1151 printk(KERN_INFO "Error %d while loading vivi driver\n", ret); 1174 printk(KERN_INFO "Error %d while loading vivi driver\n", ret);
1152 } else 1175 } else {
1153 printk(KERN_INFO "Video Technology Magazine Virtual Video " 1176 printk(KERN_INFO "Video Technology Magazine Virtual Video "
1154 "Capture Board ver %u.%u.%u successfully loaded.\n", 1177 "Capture Board ver %u.%u.%u successfully loaded.\n",
1155 (VIVI_VERSION >> 16) & 0xFF, (VIVI_VERSION >> 8) & 0xFF, 1178 (VIVI_VERSION >> 16) & 0xFF, (VIVI_VERSION >> 8) & 0xFF,
1156 VIVI_VERSION & 0xFF); 1179 VIVI_VERSION & 0xFF);
1180
1181 /* n_devs will reflect the actual number of allocated devices */
1182 n_devs = i;
1183 }
1184
1157 return ret; 1185 return ret;
1158} 1186}
1159 1187
@@ -1169,10 +1197,10 @@ MODULE_DESCRIPTION("Video Technology Magazine Virtual Video Capture Board");
1169MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol"); 1197MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
1170MODULE_LICENSE("Dual BSD/GPL"); 1198MODULE_LICENSE("Dual BSD/GPL");
1171 1199
1172module_param(video_nr, int, 0); 1200module_param(video_nr, uint, 0444);
1173MODULE_PARM_DESC(video_nr, "video iminor start number"); 1201MODULE_PARM_DESC(video_nr, "video iminor start number");
1174 1202
1175module_param(n_devs, int, 0); 1203module_param(n_devs, uint, 0444);
1176MODULE_PARM_DESC(n_devs, "number of video devices to create"); 1204MODULE_PARM_DESC(n_devs, "number of video devices to create");
1177 1205
1178module_param_named(debug, vivi_template.debug, int, 0444); 1206module_param_named(debug, vivi_template.debug, int, 0444);