[PATCH 0/4] HDPVR series of patches to replace Apr 25 series
Hi Hans, This series of patches replace the previous series sent on Apr 25. This adds the check you requested for ret byte count in get_video_info(). Thank you, -Leo. Leonid Kegulskiy (4): [media] hdpvr: Removed unnecessary get_video_info() call from hdpvr_device_init() [media] hdpvr: Removed unnecessary use of kzalloc() in get_video_info() [media] hdpvr: Added some error handling in hdpvr_start_streaming() [media] hdpvr: Cleaned up error handling drivers/media/usb/hdpvr/hdpvr-control.c | 22 +++--- drivers/media/usb/hdpvr/hdpvr-core.c|8 drivers/media/usb/hdpvr/hdpvr-video.c | 70 +-- drivers/media/usb/hdpvr/hdpvr.h |2 +- 4 files changed, 46 insertions(+), 56 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/4] [media] hdpvr: Removed unnecessary use of kzalloc() in get_video_info()
Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-control.c | 25 ++ drivers/media/usb/hdpvr/hdpvr-video.c | 54 +++ drivers/media/usb/hdpvr/hdpvr.h |2 +- 3 files changed, 37 insertions(+), 44 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c index ae8f229..7d1bfb3 100644 --- a/drivers/media/usb/hdpvr/hdpvr-control.c +++ b/drivers/media/usb/hdpvr/hdpvr-control.c @@ -45,20 +45,10 @@ int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf) return ret 0 ? ret : 0; } -struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) +int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf) { - struct hdpvr_video_info *vidinf = NULL; -#ifdef HDPVR_DEBUG - char print_buf[15]; -#endif int ret; - vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL); - if (!vidinf) { - v4l2_err(dev-v4l2_dev, out of memory\n); - goto err; - } - mutex_lock(dev-usbc_mutex); ret = usb_control_msg(dev-udev, usb_rcvctrlpipe(dev-udev, 0), @@ -74,6 +64,7 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #ifdef HDPVR_DEBUG if (hdpvr_debug MSG_INFO) { + char print_buf[15]; hex_dump_to_buffer(dev-usbc_buf, 5, 16, 1, print_buf, sizeof(print_buf), 0); v4l2_dbg(MSG_INFO, hdpvr_debug, dev-v4l2_dev, @@ -82,12 +73,14 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #endif mutex_unlock(dev-usbc_mutex); - if (!vidinf-width || !vidinf-height || !vidinf-fps) { - kfree(vidinf); - vidinf = NULL; + if ((ret0 ret!=5) ||/* fail if unexpected byte count returned */ + !vidinf-width || /* preserve original behavior - */ + !vidinf-height || /* fail if no signal is detected */ + !vidinf-fps) { + ret = -EFAULT; } -err: - return vidinf; + + return ret 0 ? ret : 0; } int get_input_lines_info(struct hdpvr_device *dev) diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index 774ba0e..d9eb8e1 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -277,20 +277,19 @@ error: static int hdpvr_start_streaming(struct hdpvr_device *dev) { int ret; - struct hdpvr_video_info *vidinf; + struct hdpvr_video_info vidinf; if (dev-status == STATUS_STREAMING) return 0; else if (dev-status != STATUS_IDLE) return -EAGAIN; - vidinf = get_video_info(dev); + ret = get_video_info(dev, vidinf); - if (vidinf) { + if (!ret) { v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, -video signal: %dx%d@%dhz\n, vidinf-width, -vidinf-height, vidinf-fps); - kfree(vidinf); +video signal: %dx%d@%dhz\n, vidinf.width, +vidinf.height, vidinf.fps); /* start streaming 2 request */ ret = usb_control_msg(dev-udev, @@ -606,21 +605,22 @@ static int vidioc_g_std(struct file *file, void *_fh, static int vidioc_querystd(struct file *file, void *_fh, v4l2_std_id *a) { struct hdpvr_device *dev = video_drvdata(file); - struct hdpvr_video_info *vid_info; + struct hdpvr_video_info vid_info; struct hdpvr_fh *fh = _fh; + int ret; *a = V4L2_STD_ALL; if (dev-options.video_input == HDPVR_COMPONENT) return fh-legacy_mode ? 0 : -ENODATA; - vid_info = get_video_info(dev); - if (vid_info == NULL) + ret = get_video_info(dev, vid_info); + if (ret) return 0; - if (vid_info-width == 720 - (vid_info-height == 480 || vid_info-height == 576)) { - *a = (vid_info-height == 480) ? + if (vid_info.width == 720 + (vid_info.height == 480 || vid_info.height == 576)) { + *a = (vid_info.height == 480) ? V4L2_STD_525_60 : V4L2_STD_625_50; } - kfree(vid_info); + return 0; } @@ -665,7 +665,7 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh, { struct hdpvr_device *dev = video_drvdata(file); struct hdpvr_fh *fh = _fh; - struct hdpvr_video_info *vid_info; + struct hdpvr_video_info vid_info; bool interlaced; int ret = 0; int i; @@ -673,10 +673,10 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh, fh-legacy_mode = false; if (dev-options.video_input) return -ENODATA; - vid_info = get_video_info(dev
[PATCH 1/4] [media] hdpvr: Removed unnecessary get_video_info() call from hdpvr_device_init()
Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-core.c |8 1 file changed, 8 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c index 8247c19..cb69405 100644 --- a/drivers/media/usb/hdpvr/hdpvr-core.c +++ b/drivers/media/usb/hdpvr/hdpvr-core.c @@ -220,7 +220,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev) { int ret; u8 *buf; - struct hdpvr_video_info *vidinf; if (device_authorization(dev)) return -EACCES; @@ -242,13 +241,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev) control request returned %d\n, ret); mutex_unlock(dev-usbc_mutex); - vidinf = get_video_info(dev); - if (!vidinf) - v4l2_dbg(MSG_INFO, hdpvr_debug, dev-v4l2_dev, - no valid video signal or device init failed\n); - else - kfree(vidinf); - /* enable fan and bling leds */ mutex_lock(dev-usbc_mutex); buf[0] = 0x1; -- 1.7.9.5 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/4] [media] hdpvr: Added some error handling in hdpvr_start_streaming()
Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-video.c |6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index d9eb8e1..2d02b49 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -297,8 +297,12 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev) 0xb8, 0x38, 0x1, 0, NULL, 0, 8000); v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, encoder start control request returned %d\n, ret); + if (ret 0) + return ret; - hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00); + ret = hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00); + if (ret) + return ret; dev-status = STATUS_STREAMING; -- 1.7.9.5 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/4] [media] hdpvr: Cleaned up error handling
Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-control.c |5 + drivers/media/usb/hdpvr/hdpvr-video.c | 10 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c index 7d1bfb3..583be15 100644 --- a/drivers/media/usb/hdpvr/hdpvr-control.c +++ b/drivers/media/usb/hdpvr/hdpvr-control.c @@ -73,10 +73,7 @@ int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf) #endif mutex_unlock(dev-usbc_mutex); - if ((ret0 ret!=5) ||/* fail if unexpected byte count returned */ - !vidinf-width || /* preserve original behavior - */ - !vidinf-height || /* fail if no signal is detected */ - !vidinf-fps) { + if (ret0 ret!=5) { /* fail if unexpected byte count returned */ ret = -EFAULT; } diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index 2d02b49..5e8d6c2 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -285,8 +285,10 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev) return -EAGAIN; ret = get_video_info(dev, vidinf); + if (ret)/* device is dead */ + return ret; /* let the caller know */ - if (!ret) { + if (vidinf.width vidinf.height) { v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, video signal: %dx%d@%dhz\n, vidinf.width, vidinf.height, vidinf.fps); @@ -618,7 +620,7 @@ static int vidioc_querystd(struct file *file, void *_fh, v4l2_std_id *a) return fh-legacy_mode ? 0 : -ENODATA; ret = get_video_info(dev, vid_info); if (ret) - return 0; + return ret; if (vid_info.width == 720 (vid_info.height == 480 || vid_info.height == 576)) { *a = (vid_info.height == 480) ? @@ -679,6 +681,8 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh, return -ENODATA; ret = get_video_info(dev, vid_info); if (ret) + return ret; + if (vid_info.fps == 0) return -ENOLCK; interlaced = vid_info.fps = 30; for (i = 0; i ARRAY_SIZE(hdpvr_dv_timings); i++) { @@ -1009,7 +1013,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *_fh, ret = get_video_info(dev, vid_info); if (ret) - return -EFAULT; + return ret; f-fmt.pix.width = vid_info.width; f-fmt.pix.height = vid_info.height; } else { -- 1.7.9.5 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/4] HDPVR series of patches to replace Apr 22 patch
Hi Hans, This series of patches replace the previous patch sent on Apr 22: [PATCH] [media] hdpvr_ error handling and alloc abuse cleanup. Thank you, -Leo. Leonid Kegulskiy (4): [media] hdpvr: Removed unnecessary get_video_info() call from hdpvr_device_init() [media] hdpvr: Removed unnecessary use of kzalloc() in get_video_info() [media] hdpvr: Added some error handling in hdpvr_start_streaming() [media] hdpvr: Cleaned up error handling drivers/media/usb/hdpvr/hdpvr-control.c | 20 ++--- drivers/media/usb/hdpvr/hdpvr-core.c|8 drivers/media/usb/hdpvr/hdpvr-video.c | 70 +-- drivers/media/usb/hdpvr/hdpvr.h |2 +- 4 files changed, 43 insertions(+), 57 deletions(-) -- 1.7.10.4 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/4] [media] hdpvr: Removed unnecessary get_video_info() call from hdpvr_device_init()
Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-core.c |8 1 file changed, 8 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c index 8247c19..cb69405 100644 --- a/drivers/media/usb/hdpvr/hdpvr-core.c +++ b/drivers/media/usb/hdpvr/hdpvr-core.c @@ -220,7 +220,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev) { int ret; u8 *buf; - struct hdpvr_video_info *vidinf; if (device_authorization(dev)) return -EACCES; @@ -242,13 +241,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev) control request returned %d\n, ret); mutex_unlock(dev-usbc_mutex); - vidinf = get_video_info(dev); - if (!vidinf) - v4l2_dbg(MSG_INFO, hdpvr_debug, dev-v4l2_dev, - no valid video signal or device init failed\n); - else - kfree(vidinf); - /* enable fan and bling leds */ mutex_lock(dev-usbc_mutex); buf[0] = 0x1; -- 1.7.10.4 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/4] [media] hdpvr: Removed unnecessary use of kzalloc() in get_video_info()
Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-control.c | 21 drivers/media/usb/hdpvr/hdpvr-video.c | 54 +++ drivers/media/usb/hdpvr/hdpvr.h |2 +- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c index ae8f229..5265b75 100644 --- a/drivers/media/usb/hdpvr/hdpvr-control.c +++ b/drivers/media/usb/hdpvr/hdpvr-control.c @@ -45,20 +45,10 @@ int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf) return ret 0 ? ret : 0; } -struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) +int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf) { - struct hdpvr_video_info *vidinf = NULL; -#ifdef HDPVR_DEBUG - char print_buf[15]; -#endif int ret; - vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL); - if (!vidinf) { - v4l2_err(dev-v4l2_dev, out of memory\n); - goto err; - } - mutex_lock(dev-usbc_mutex); ret = usb_control_msg(dev-udev, usb_rcvctrlpipe(dev-udev, 0), @@ -74,6 +64,7 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #ifdef HDPVR_DEBUG if (hdpvr_debug MSG_INFO) { + char print_buf[15]; hex_dump_to_buffer(dev-usbc_buf, 5, 16, 1, print_buf, sizeof(print_buf), 0); v4l2_dbg(MSG_INFO, hdpvr_debug, dev-v4l2_dev, @@ -82,12 +73,12 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #endif mutex_unlock(dev-usbc_mutex); + /* preserve original behavior - fail if no signal is detected */ if (!vidinf-width || !vidinf-height || !vidinf-fps) { - kfree(vidinf); - vidinf = NULL; + ret = -EFAULT; } -err: - return vidinf; + + return ret 0 ? ret : 0; } int get_input_lines_info(struct hdpvr_device *dev) diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index 774ba0e..d9eb8e1 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -277,20 +277,19 @@ error: static int hdpvr_start_streaming(struct hdpvr_device *dev) { int ret; - struct hdpvr_video_info *vidinf; + struct hdpvr_video_info vidinf; if (dev-status == STATUS_STREAMING) return 0; else if (dev-status != STATUS_IDLE) return -EAGAIN; - vidinf = get_video_info(dev); + ret = get_video_info(dev, vidinf); - if (vidinf) { + if (!ret) { v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, -video signal: %dx%d@%dhz\n, vidinf-width, -vidinf-height, vidinf-fps); - kfree(vidinf); +video signal: %dx%d@%dhz\n, vidinf.width, +vidinf.height, vidinf.fps); /* start streaming 2 request */ ret = usb_control_msg(dev-udev, @@ -606,21 +605,22 @@ static int vidioc_g_std(struct file *file, void *_fh, static int vidioc_querystd(struct file *file, void *_fh, v4l2_std_id *a) { struct hdpvr_device *dev = video_drvdata(file); - struct hdpvr_video_info *vid_info; + struct hdpvr_video_info vid_info; struct hdpvr_fh *fh = _fh; + int ret; *a = V4L2_STD_ALL; if (dev-options.video_input == HDPVR_COMPONENT) return fh-legacy_mode ? 0 : -ENODATA; - vid_info = get_video_info(dev); - if (vid_info == NULL) + ret = get_video_info(dev, vid_info); + if (ret) return 0; - if (vid_info-width == 720 - (vid_info-height == 480 || vid_info-height == 576)) { - *a = (vid_info-height == 480) ? + if (vid_info.width == 720 + (vid_info.height == 480 || vid_info.height == 576)) { + *a = (vid_info.height == 480) ? V4L2_STD_525_60 : V4L2_STD_625_50; } - kfree(vid_info); + return 0; } @@ -665,7 +665,7 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh, { struct hdpvr_device *dev = video_drvdata(file); struct hdpvr_fh *fh = _fh; - struct hdpvr_video_info *vid_info; + struct hdpvr_video_info vid_info; bool interlaced; int ret = 0; int i; @@ -673,10 +673,10 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh, fh-legacy_mode = false; if (dev-options.video_input) return -ENODATA; - vid_info = get_video_info(dev); - if (vid_info == NULL) + ret = get_video_info(dev, vid_info); + if (ret) return -ENOLCK; - interlaced = vid_info-fps = 30
[PATCH 3/4] [media] hdpvr: Added some error handling in hdpvr_start_streaming()
Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-video.c |6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index d9eb8e1..2d02b49 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -297,8 +297,12 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev) 0xb8, 0x38, 0x1, 0, NULL, 0, 8000); v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, encoder start control request returned %d\n, ret); + if (ret 0) + return ret; - hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00); + ret = hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00); + if (ret) + return ret; dev-status = STATUS_STREAMING; -- 1.7.10.4 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/4] [media] hdpvr: Cleaned up error handling
Changed vidioc_g_fmt_vid_cap() implementation not to return -EFAULT when video lock is not detected, but return empty width/height fields (legacy mode only). This new behavior is supported by MythTV. Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-control.c |5 - drivers/media/usb/hdpvr/hdpvr-video.c | 10 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c index 5265b75..16d2d64 100644 --- a/drivers/media/usb/hdpvr/hdpvr-control.c +++ b/drivers/media/usb/hdpvr/hdpvr-control.c @@ -73,11 +73,6 @@ int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf) #endif mutex_unlock(dev-usbc_mutex); - /* preserve original behavior - fail if no signal is detected */ - if (!vidinf-width || !vidinf-height || !vidinf-fps) { - ret = -EFAULT; - } - return ret 0 ? ret : 0; } diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index 2d02b49..5e8d6c2 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -285,8 +285,10 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev) return -EAGAIN; ret = get_video_info(dev, vidinf); + if (ret)/* device is dead */ + return ret; /* let the caller know */ - if (!ret) { + if (vidinf.width vidinf.height) { v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, video signal: %dx%d@%dhz\n, vidinf.width, vidinf.height, vidinf.fps); @@ -618,7 +620,7 @@ static int vidioc_querystd(struct file *file, void *_fh, v4l2_std_id *a) return fh-legacy_mode ? 0 : -ENODATA; ret = get_video_info(dev, vid_info); if (ret) - return 0; + return ret; if (vid_info.width == 720 (vid_info.height == 480 || vid_info.height == 576)) { *a = (vid_info.height == 480) ? @@ -679,6 +681,8 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh, return -ENODATA; ret = get_video_info(dev, vid_info); if (ret) + return ret; + if (vid_info.fps == 0) return -ENOLCK; interlaced = vid_info.fps = 30; for (i = 0; i ARRAY_SIZE(hdpvr_dv_timings); i++) { @@ -1009,7 +1013,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *_fh, ret = get_video_info(dev, vid_info); if (ret) - return -EFAULT; + return ret; f-fmt.pix.width = vid_info.width; f-fmt.pix.height = vid_info.height; } else { -- 1.7.10.4 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] [media] hdpvr: error handling and alloc abuse cleanup.
Removed unnecessary use of kzalloc() in get_video_info(). Removed unnecessary get_video_info() call from hdpvr_device_init(). Cleaned up error handling in hdpvr_start_streaming() to ensure caller gets a failure status if device is not functioning properly. Cleaned up error handling in vidioc_querystd(), vidioc_query_dv_timings() and vidioc_g_fmt_vid_cap(). This change also causes vidioc_g_fmt_vid_cap() not to return -EFAULT when video lock is not detected, but return empty width/height fields (legacy mode only). This new behavior is supported by MythTV. Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-control.c | 20 ++--- drivers/media/usb/hdpvr/hdpvr-core.c|8 drivers/media/usb/hdpvr/hdpvr-video.c | 70 +-- drivers/media/usb/hdpvr/hdpvr.h |2 +- 4 files changed, 43 insertions(+), 57 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c index ae8f229..16d2d64 100644 --- a/drivers/media/usb/hdpvr/hdpvr-control.c +++ b/drivers/media/usb/hdpvr/hdpvr-control.c @@ -45,20 +45,10 @@ int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf) return ret 0 ? ret : 0; } -struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) +int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf) { - struct hdpvr_video_info *vidinf = NULL; -#ifdef HDPVR_DEBUG - char print_buf[15]; -#endif int ret; - vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL); - if (!vidinf) { - v4l2_err(dev-v4l2_dev, out of memory\n); - goto err; - } - mutex_lock(dev-usbc_mutex); ret = usb_control_msg(dev-udev, usb_rcvctrlpipe(dev-udev, 0), @@ -74,6 +64,7 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #ifdef HDPVR_DEBUG if (hdpvr_debug MSG_INFO) { + char print_buf[15]; hex_dump_to_buffer(dev-usbc_buf, 5, 16, 1, print_buf, sizeof(print_buf), 0); v4l2_dbg(MSG_INFO, hdpvr_debug, dev-v4l2_dev, @@ -82,12 +73,7 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #endif mutex_unlock(dev-usbc_mutex); - if (!vidinf-width || !vidinf-height || !vidinf-fps) { - kfree(vidinf); - vidinf = NULL; - } -err: - return vidinf; + return ret 0 ? ret : 0; } int get_input_lines_info(struct hdpvr_device *dev) diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c index 8247c19..cb69405 100644 --- a/drivers/media/usb/hdpvr/hdpvr-core.c +++ b/drivers/media/usb/hdpvr/hdpvr-core.c @@ -220,7 +220,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev) { int ret; u8 *buf; - struct hdpvr_video_info *vidinf; if (device_authorization(dev)) return -EACCES; @@ -242,13 +241,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev) control request returned %d\n, ret); mutex_unlock(dev-usbc_mutex); - vidinf = get_video_info(dev); - if (!vidinf) - v4l2_dbg(MSG_INFO, hdpvr_debug, dev-v4l2_dev, - no valid video signal or device init failed\n); - else - kfree(vidinf); - /* enable fan and bling leds */ mutex_lock(dev-usbc_mutex); buf[0] = 0x1; diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index 774ba0e..5e8d6c2 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -277,20 +277,21 @@ error: static int hdpvr_start_streaming(struct hdpvr_device *dev) { int ret; - struct hdpvr_video_info *vidinf; + struct hdpvr_video_info vidinf; if (dev-status == STATUS_STREAMING) return 0; else if (dev-status != STATUS_IDLE) return -EAGAIN; - vidinf = get_video_info(dev); + ret = get_video_info(dev, vidinf); + if (ret)/* device is dead */ + return ret; /* let the caller know */ - if (vidinf) { + if (vidinf.width vidinf.height) { v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, -video signal: %dx%d@%dhz\n, vidinf-width, -vidinf-height, vidinf-fps); - kfree(vidinf); +video signal: %dx%d@%dhz\n, vidinf.width, +vidinf.height, vidinf.fps); /* start streaming 2 request */ ret = usb_control_msg(dev-udev, @@ -298,8 +299,12 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev) 0xb8, 0x38, 0x1, 0, NULL, 0, 8000); v4l2_dbg(MSG_BUFFER, hdpvr_debug
[PATCH] [media] hdpvr: vidioc_g_fmt_vid_cap should not fail
Fixed get_video_info() function that used to return NULL if video source is not present, subsequently causing vidioc_g_fmt_vid_cap to fail. Originally issue reported here: http://www.spinics.net/lists/linux-media/msg54246.html Signed-off-by: Leonid Kegulskiy l...@lumanate.com --- drivers/media/usb/hdpvr/hdpvr-control.c | 29 + drivers/media/usb/hdpvr/hdpvr-video.c |5 - 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c index ae8f229..ed12159 100644 --- a/drivers/media/usb/hdpvr/hdpvr-control.c +++ b/drivers/media/usb/hdpvr/hdpvr-control.c @@ -53,12 +53,6 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #endif int ret; - vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL); - if (!vidinf) { - v4l2_err(dev-v4l2_dev, out of memory\n); - goto err; - } - mutex_lock(dev-usbc_mutex); ret = usb_control_msg(dev-udev, usb_rcvctrlpipe(dev-udev, 0), @@ -66,12 +60,6 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) 0x1400, 0x0003, dev-usbc_buf, 5, 1000); - if (ret == 5) { - vidinf-width = dev-usbc_buf[1] 8 | dev-usbc_buf[0]; - vidinf-height = dev-usbc_buf[3] 8 | dev-usbc_buf[2]; - vidinf-fps = dev-usbc_buf[4]; - } - #ifdef HDPVR_DEBUG if (hdpvr_debug MSG_INFO) { hex_dump_to_buffer(dev-usbc_buf, 5, 16, 1, print_buf, @@ -82,11 +70,20 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) #endif mutex_unlock(dev-usbc_mutex); - if (!vidinf-width || !vidinf-height || !vidinf-fps) { - kfree(vidinf); - vidinf = NULL; + if (ret == 5) + { + vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL); + if (vidinf) + { + vidinf-width = dev-usbc_buf[1] 8 | dev-usbc_buf[0]; + vidinf-height = dev-usbc_buf[3] 8 | dev-usbc_buf[2]; + vidinf-fps = dev-usbc_buf[4]; + } + else + { + v4l2_err(dev-v4l2_dev, out of memory\n); + } } -err: return vidinf; } diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c index da6b779..fb14012 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -268,7 +268,7 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev) vidinf = get_video_info(dev); - if (vidinf) { + if (vidinf vidinf-width vidinf-height vidinf-fps) { v4l2_dbg(MSG_BUFFER, hdpvr_debug, dev-v4l2_dev, video signal: %dx%d@%dhz\n, vidinf-width, vidinf-height, vidinf-fps); @@ -293,6 +293,9 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev) return 0; } + + if (vidinf) + kfree(vidinf); msleep(250); v4l2_dbg(MSG_INFO, hdpvr_debug, dev-v4l2_dev, no video signal at input %d\n, dev-options.video_input); -- 1.7.10.4 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html