From patchwork Mon May 27 12:04:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 2619451 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 08828DF215 for ; Mon, 27 May 2013 12:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932124Ab3E0MEh (ORCPT ); Mon, 27 May 2013 08:04:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43489 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932072Ab3E0MEf (ORCPT ); Mon, 27 May 2013 08:04:35 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4RC4Zr4020968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 27 May 2013 08:04:35 -0400 Received: from pedra (vpn1-5-18.gru2.redhat.com [10.97.5.18]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4RC4XF4014916 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 27 May 2013 08:04:34 -0400 Received: from v4l by pedra with local (Exim 4.80.1) (envelope-from ) id 1UgwAC-00030D-3l; Mon, 27 May 2013 09:04:32 -0300 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List Subject: [PATCH] [media] hdpvr: Simplify the logic that checks for error Date: Mon, 27 May 2013 09:04:29 -0300 Message-Id: <1369656269-11444-1-git-send-email-mchehab@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org At get_video_info, there's a somewhat complex logic that checks for error. That logic can be highly simplified, as usb_control_msg will only return a negative value, or the buffer length, as it does the transfers via DMA. While here, document why this particular driver is returning -EFAULT, instead of the USB error code. Signed-off-by: Mauro Carvalho Chehab Nacked-by: Hans Verkuil --- drivers/media/usb/hdpvr/hdpvr-control.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c index d1a3d84..a015a24 100644 --- a/drivers/media/usb/hdpvr/hdpvr-control.c +++ b/drivers/media/usb/hdpvr/hdpvr-control.c @@ -56,12 +56,6 @@ int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf) 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) { char print_buf[15]; @@ -73,11 +67,20 @@ int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf) #endif mutex_unlock(&dev->usbc_mutex); - if (ret > 0 && ret != 5) { /* fail if unexpected byte count returned */ - ret = -EFAULT; - } + /* + * Returning EFAULT is wrong. Unfortunately, MythTV hdpvr + * handling code was written to expect this specific error, + * instead of accepting any error code. So, we can't fix it + * in Kernel without breaking userspace. + */ + if (ret < 0) + return -EFAULT; - return ret < 0 ? ret : 0; + 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]; + + return 0; } int get_input_lines_info(struct hdpvr_device *dev)