Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] ivtv: embed video_device

Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Andy Walls <awalls@md.metrocast.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
635d62f0 b3226f96

+61 -76
+1 -1
drivers/media/pci/ivtv/ivtv-alsa-main.c
··· 224 224 } 225 225 226 226 s = &itv->streams[IVTV_ENC_STREAM_TYPE_PCM]; 227 - if (s->vdev == NULL) { 227 + if (s->vdev.v4l2_dev == NULL) { 228 228 IVTV_DEBUG_ALSA_INFO("%s: PCM stream for card is disabled - " 229 229 "skipping\n", __func__); 230 230 return 0;
+1 -1
drivers/media/pci/ivtv/ivtv-alsa-pcm.c
··· 167 167 168 168 s = &itv->streams[IVTV_ENC_STREAM_TYPE_PCM]; 169 169 170 - v4l2_fh_init(&item.fh, s->vdev); 170 + v4l2_fh_init(&item.fh, &s->vdev); 171 171 item.itv = itv; 172 172 item.type = s->type; 173 173
+2 -2
drivers/media/pci/ivtv/ivtv-driver.c
··· 1284 1284 return 0; 1285 1285 1286 1286 free_streams: 1287 - ivtv_streams_cleanup(itv, 1); 1287 + ivtv_streams_cleanup(itv); 1288 1288 free_irq: 1289 1289 free_irq(itv->pdev->irq, (void *)itv); 1290 1290 free_i2c: ··· 1444 1444 flush_kthread_worker(&itv->irq_worker); 1445 1445 kthread_stop(itv->irq_worker_task); 1446 1446 1447 - ivtv_streams_cleanup(itv, 1); 1447 + ivtv_streams_cleanup(itv); 1448 1448 ivtv_udma_free(itv); 1449 1449 1450 1450 v4l2_ctrl_handler_free(&itv->cxhdl.hdl);
+1 -1
drivers/media/pci/ivtv/ivtv-driver.h
··· 327 327 struct ivtv_stream { 328 328 /* These first four fields are always set, even if the stream 329 329 is not actually created. */ 330 - struct video_device *vdev; /* NULL when stream not created */ 330 + struct video_device vdev; /* vdev.v4l2_dev is NULL if there is no device */ 331 331 struct ivtv *itv; /* for ease of use */ 332 332 const char *name; /* name of the stream */ 333 333 int type; /* stream type */
+1 -1
drivers/media/pci/ivtv/ivtv-fileops.c
··· 995 995 IVTV_DEBUG_WARN("nomem on v4l2 open\n"); 996 996 return -ENOMEM; 997 997 } 998 - v4l2_fh_init(&item->fh, s->vdev); 998 + v4l2_fh_init(&item->fh, &s->vdev); 999 999 item->itv = itv; 1000 1000 item->type = s->type; 1001 1001
+4 -4
drivers/media/pci/ivtv/ivtv-ioctl.c
··· 987 987 else 988 988 std = V4L2_STD_ALL; 989 989 for (i = 0; i <= IVTV_ENC_STREAM_TYPE_VBI; i++) 990 - itv->streams[i].vdev->tvnorms = std; 990 + itv->streams[i].vdev.tvnorms = std; 991 991 992 992 /* prevent others from messing with the streams until 993 993 we're finished changing inputs. */ ··· 1038 1038 struct ivtv *itv = fh2id(fh)->itv; 1039 1039 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type]; 1040 1040 1041 - if (s->vdev->vfl_dir) 1041 + if (s->vdev.vfl_dir) 1042 1042 return -ENOTTY; 1043 1043 if (vf->tuner != 0) 1044 1044 return -EINVAL; ··· 1052 1052 struct ivtv *itv = fh2id(fh)->itv; 1053 1053 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type]; 1054 1054 1055 - if (s->vdev->vfl_dir) 1055 + if (s->vdev.vfl_dir) 1056 1056 return -ENOTTY; 1057 1057 if (vf->tuner != 0) 1058 1058 return -EINVAL; ··· 1547 1547 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 1548 1548 struct ivtv_stream *s = &itv->streams[i]; 1549 1549 1550 - if (s->vdev == NULL || s->buffers == 0) 1550 + if (s->vdev.v4l2_dev == NULL || s->buffers == 0) 1551 1551 continue; 1552 1552 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->name, s->s_flags, 1553 1553 (s->buffers - s->q_free.buffers) * 100 / s->buffers,
+4 -4
drivers/media/pci/ivtv/ivtv-irq.c
··· 75 75 76 76 IVTV_DEBUG_HI_DMA("ivtv_pio_work_handler\n"); 77 77 if (itv->cur_pio_stream < 0 || itv->cur_pio_stream >= IVTV_MAX_STREAMS || 78 - s->vdev == NULL || !ivtv_use_pio(s)) { 78 + s->vdev.v4l2_dev == NULL || !ivtv_use_pio(s)) { 79 79 itv->cur_pio_stream = -1; 80 80 /* trigger PIO complete user interrupt */ 81 81 write_reg(IVTV_IRQ_ENC_PIO_COMPLETE, 0x44); ··· 132 132 int rc; 133 133 134 134 /* sanity checks */ 135 - if (s->vdev == NULL) { 135 + if (s->vdev.v4l2_dev == NULL) { 136 136 IVTV_DEBUG_WARN("Stream %s not started\n", s->name); 137 137 return -1; 138 138 } ··· 890 890 if (s) 891 891 wake_up(&s->waitq); 892 892 } 893 - if (s && s->vdev) 894 - v4l2_event_queue(s->vdev, frame ? &evtop : &evbottom); 893 + if (s && s->vdev.v4l2_dev) 894 + v4l2_event_queue(&s->vdev, frame ? &evtop : &evbottom); 895 895 wake_up(&itv->vsync_waitq); 896 896 897 897 /* Send VBI to saa7127 */
+46 -61
drivers/media/pci/ivtv/ivtv-streams.c
··· 159 159 static void ivtv_stream_init(struct ivtv *itv, int type) 160 160 { 161 161 struct ivtv_stream *s = &itv->streams[type]; 162 - struct video_device *vdev = s->vdev; 163 162 164 163 /* we need to keep vdev, so restore it afterwards */ 165 164 memset(s, 0, sizeof(*s)); 166 - s->vdev = vdev; 167 165 168 166 /* initialize ivtv_stream fields */ 169 167 s->itv = itv; ··· 192 194 int num_offset = ivtv_stream_info[type].num_offset; 193 195 int num = itv->instance + ivtv_first_minor + num_offset; 194 196 195 - /* These four fields are always initialized. If vdev == NULL, then 197 + /* These four fields are always initialized. If vdev.v4l2_dev == NULL, then 196 198 this stream is not in use. In that case no other fields but these 197 199 four can be used. */ 198 - s->vdev = NULL; 200 + s->vdev.v4l2_dev = NULL; 199 201 s->itv = itv; 200 202 s->type = type; 201 203 s->name = ivtv_stream_info[type].name; ··· 216 218 217 219 ivtv_stream_init(itv, type); 218 220 219 - /* allocate and initialize the v4l2 video device structure */ 220 - s->vdev = video_device_alloc(); 221 - if (s->vdev == NULL) { 222 - IVTV_ERR("Couldn't allocate v4l2 video_device for %s\n", s->name); 223 - return -ENOMEM; 224 - } 225 - 226 - snprintf(s->vdev->name, sizeof(s->vdev->name), "%s %s", 221 + snprintf(s->vdev.name, sizeof(s->vdev.name), "%s %s", 227 222 itv->v4l2_dev.name, s->name); 228 223 229 - s->vdev->num = num; 230 - s->vdev->v4l2_dev = &itv->v4l2_dev; 224 + s->vdev.num = num; 225 + s->vdev.v4l2_dev = &itv->v4l2_dev; 231 226 if (ivtv_stream_info[type].v4l2_caps & 232 227 (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_SLICED_VBI_OUTPUT)) 233 - s->vdev->vfl_dir = VFL_DIR_TX; 234 - s->vdev->fops = ivtv_stream_info[type].fops; 235 - s->vdev->ctrl_handler = itv->v4l2_dev.ctrl_handler; 236 - s->vdev->release = video_device_release; 237 - s->vdev->tvnorms = V4L2_STD_ALL; 238 - s->vdev->lock = &itv->serialize_lock; 228 + s->vdev.vfl_dir = VFL_DIR_TX; 229 + s->vdev.fops = ivtv_stream_info[type].fops; 230 + s->vdev.ctrl_handler = itv->v4l2_dev.ctrl_handler; 231 + s->vdev.release = video_device_release_empty; 232 + s->vdev.tvnorms = V4L2_STD_ALL; 233 + s->vdev.lock = &itv->serialize_lock; 239 234 if (s->type == IVTV_DEC_STREAM_TYPE_VBI) { 240 - v4l2_disable_ioctl(s->vdev, VIDIOC_S_AUDIO); 241 - v4l2_disable_ioctl(s->vdev, VIDIOC_G_AUDIO); 242 - v4l2_disable_ioctl(s->vdev, VIDIOC_ENUMAUDIO); 243 - v4l2_disable_ioctl(s->vdev, VIDIOC_ENUMINPUT); 244 - v4l2_disable_ioctl(s->vdev, VIDIOC_S_INPUT); 245 - v4l2_disable_ioctl(s->vdev, VIDIOC_G_INPUT); 246 - v4l2_disable_ioctl(s->vdev, VIDIOC_S_FREQUENCY); 247 - v4l2_disable_ioctl(s->vdev, VIDIOC_G_FREQUENCY); 248 - v4l2_disable_ioctl(s->vdev, VIDIOC_S_TUNER); 249 - v4l2_disable_ioctl(s->vdev, VIDIOC_G_TUNER); 250 - v4l2_disable_ioctl(s->vdev, VIDIOC_S_STD); 235 + v4l2_disable_ioctl(&s->vdev, VIDIOC_S_AUDIO); 236 + v4l2_disable_ioctl(&s->vdev, VIDIOC_G_AUDIO); 237 + v4l2_disable_ioctl(&s->vdev, VIDIOC_ENUMAUDIO); 238 + v4l2_disable_ioctl(&s->vdev, VIDIOC_ENUMINPUT); 239 + v4l2_disable_ioctl(&s->vdev, VIDIOC_S_INPUT); 240 + v4l2_disable_ioctl(&s->vdev, VIDIOC_G_INPUT); 241 + v4l2_disable_ioctl(&s->vdev, VIDIOC_S_FREQUENCY); 242 + v4l2_disable_ioctl(&s->vdev, VIDIOC_G_FREQUENCY); 243 + v4l2_disable_ioctl(&s->vdev, VIDIOC_S_TUNER); 244 + v4l2_disable_ioctl(&s->vdev, VIDIOC_G_TUNER); 245 + v4l2_disable_ioctl(&s->vdev, VIDIOC_S_STD); 251 246 } 252 - ivtv_set_funcs(s->vdev); 247 + ivtv_set_funcs(&s->vdev); 253 248 return 0; 254 249 } 255 250 ··· 257 266 if (ivtv_prep_dev(itv, type)) 258 267 break; 259 268 260 - if (itv->streams[type].vdev == NULL) 269 + if (itv->streams[type].vdev.v4l2_dev == NULL) 261 270 continue; 262 271 263 272 /* Allocate Stream */ ··· 268 277 return 0; 269 278 270 279 /* One or more streams could not be initialized. Clean 'em all up. */ 271 - ivtv_streams_cleanup(itv, 0); 280 + ivtv_streams_cleanup(itv); 272 281 return -ENOMEM; 273 282 } 274 283 ··· 279 288 const char *name; 280 289 int num; 281 290 282 - if (s->vdev == NULL) 291 + if (s->vdev.v4l2_dev == NULL) 283 292 return 0; 284 293 285 - num = s->vdev->num; 294 + num = s->vdev.num; 286 295 /* card number + user defined offset + device offset */ 287 296 if (type != IVTV_ENC_STREAM_TYPE_MPG) { 288 297 struct ivtv_stream *s_mpg = &itv->streams[IVTV_ENC_STREAM_TYPE_MPG]; 289 298 290 - if (s_mpg->vdev) 291 - num = s_mpg->vdev->num + ivtv_stream_info[type].num_offset; 299 + if (s_mpg->vdev.v4l2_dev) 300 + num = s_mpg->vdev.num + ivtv_stream_info[type].num_offset; 292 301 } 293 - video_set_drvdata(s->vdev, s); 302 + video_set_drvdata(&s->vdev, s); 294 303 295 304 /* Register device. First try the desired minor, then any free one. */ 296 - if (video_register_device_no_warn(s->vdev, vfl_type, num)) { 305 + if (video_register_device_no_warn(&s->vdev, vfl_type, num)) { 297 306 IVTV_ERR("Couldn't register v4l2 device for %s (device node number %d)\n", 298 307 s->name, num); 299 - video_device_release(s->vdev); 300 - s->vdev = NULL; 301 308 return -ENOMEM; 302 309 } 303 - name = video_device_node_name(s->vdev); 310 + name = video_device_node_name(&s->vdev); 304 311 305 312 switch (vfl_type) { 306 313 case VFL_TYPE_GRABBER: ··· 335 346 return 0; 336 347 337 348 /* One or more streams could not be initialized. Clean 'em all up. */ 338 - ivtv_streams_cleanup(itv, 1); 349 + ivtv_streams_cleanup(itv); 339 350 return -ENOMEM; 340 351 } 341 352 342 353 /* Unregister v4l2 devices */ 343 - void ivtv_streams_cleanup(struct ivtv *itv, int unregister) 354 + void ivtv_streams_cleanup(struct ivtv *itv) 344 355 { 345 356 int type; 346 357 347 358 /* Teardown all streams */ 348 359 for (type = 0; type < IVTV_MAX_STREAMS; type++) { 349 - struct video_device *vdev = itv->streams[type].vdev; 360 + struct video_device *vdev = &itv->streams[type].vdev; 350 361 351 - itv->streams[type].vdev = NULL; 352 - if (vdev == NULL) 362 + if (vdev->v4l2_dev == NULL) 353 363 continue; 354 364 365 + video_unregister_device(vdev); 355 366 ivtv_stream_free(&itv->streams[type]); 356 - /* Unregister or release device */ 357 - if (unregister) 358 - video_unregister_device(vdev); 359 - else 360 - video_device_release(vdev); 367 + itv->streams[type].vdev.v4l2_dev = NULL; 361 368 } 362 369 } 363 370 ··· 477 492 int captype = 0, subtype = 0; 478 493 int enable_passthrough = 0; 479 494 480 - if (s->vdev == NULL) 495 + if (s->vdev.v4l2_dev == NULL) 481 496 return -EINVAL; 482 497 483 498 IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name); ··· 646 661 u16 width; 647 662 u16 height; 648 663 649 - if (s->vdev == NULL) 664 + if (s->vdev.v4l2_dev == NULL) 650 665 return -EINVAL; 651 666 652 667 IVTV_DEBUG_INFO("Setting some initial decoder settings\n"); ··· 708 723 struct ivtv *itv = s->itv; 709 724 int rc; 710 725 711 - if (s->vdev == NULL) 726 + if (s->vdev.v4l2_dev == NULL) 712 727 return -EINVAL; 713 728 714 729 if (test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags)) ··· 763 778 for (i = IVTV_MAX_STREAMS - 1; i >= 0; i--) { 764 779 struct ivtv_stream *s = &itv->streams[i]; 765 780 766 - if (s->vdev == NULL) 781 + if (s->vdev.v4l2_dev == NULL) 767 782 continue; 768 783 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { 769 784 ivtv_stop_v4l2_encode_stream(s, 0); ··· 778 793 int cap_type; 779 794 int stopmode; 780 795 781 - if (s->vdev == NULL) 796 + if (s->vdev.v4l2_dev == NULL) 782 797 return -EINVAL; 783 798 784 799 /* This function assumes that you are allowed to stop the capture ··· 902 917 }; 903 918 struct ivtv *itv = s->itv; 904 919 905 - if (s->vdev == NULL) 920 + if (s->vdev.v4l2_dev == NULL) 906 921 return -EINVAL; 907 922 908 923 if (s->type != IVTV_DEC_STREAM_TYPE_YUV && s->type != IVTV_DEC_STREAM_TYPE_MPG) ··· 954 969 955 970 set_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags); 956 971 wake_up(&itv->event_waitq); 957 - v4l2_event_queue(s->vdev, &ev); 972 + v4l2_event_queue(&s->vdev, &ev); 958 973 959 974 /* wake up wait queues */ 960 975 wake_up(&s->waitq); ··· 967 982 struct ivtv_stream *yuv_stream = &itv->streams[IVTV_ENC_STREAM_TYPE_YUV]; 968 983 struct ivtv_stream *dec_stream = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV]; 969 984 970 - if (yuv_stream->vdev == NULL || dec_stream->vdev == NULL) 985 + if (yuv_stream->vdev.v4l2_dev == NULL || dec_stream->vdev.v4l2_dev == NULL) 971 986 return -EINVAL; 972 987 973 988 IVTV_DEBUG_INFO("ivtv ioctl: Select passthrough mode\n");
+1 -1
drivers/media/pci/ivtv/ivtv-streams.h
··· 23 23 24 24 int ivtv_streams_setup(struct ivtv *itv); 25 25 int ivtv_streams_register(struct ivtv *itv); 26 - void ivtv_streams_cleanup(struct ivtv *itv, int unregister); 26 + void ivtv_streams_cleanup(struct ivtv *itv); 27 27 28 28 /* Capture related */ 29 29 int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s);