Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3470297imu; Sun, 11 Nov 2018 15:50:58 -0800 (PST) X-Google-Smtp-Source: AJdET5eozZOUM7ofm5ZQE0FaqSqC6VPqNMCfBfsOUBgxmHaMp0lTcxglUFa6hIWYTCzuKBXiUesy X-Received: by 2002:a17:902:292b:: with SMTP id g40-v6mr16886885plb.279.1541980258904; Sun, 11 Nov 2018 15:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980258; cv=none; d=google.com; s=arc-20160816; b=hGOW7FkamiCNsvxML+DY5N4Pkk8gIIlwsXr3U9+1V48uFPb6XPB/xXCTSKq1GzUN8Q IwxRz8iq6scReuP9/r6j/KQ4rjQCWJqL5eDsjuivrT9w71nyZbG7zve3Toji6RSzZLrh vB6vowPRSBhT4b7Vsjrz1BjN8DDnE/D4JstDQxmjw356R6Osn/2z4qPZWXl59+6UygGQ yfcgHE8ueZAo23T8J0UQjb3j64GWt98FFS5dQW/G4Zg3hzt/Vav1+afuHcmFVyDDLX32 d5mW/xG02V/AbETD4tAR4a8B6CgpLZ8tzNaPlDmCHzJCTDE1TJoJl2o6Tdx38vc3djaa 2kzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=suP20N6jyCqREiyfzj5lx1lh9e2syxGApzixirWpsvY=; b=piJ+U2s+u7iFQv9CuCSd76MU12R49bNr6pEhoseix1dpv1YNyXfApZjFEYLKnhOrGJ unPTigGQo9bkewhynCL55+W+bnPeVLzb+Z5Zr74WJmPTGvGUMu5ORJLFMZZrkqQQv3DQ vVwr1vG+C7+WALz4HEcqJxV8UlK3dI9/S83kU9KpdMUF5Y5atE3gJ7LG4u7p5Z6v3bAV cBuntldPZ7tywd94VT+xn0yCBthgt4sz/luBeEKDCawM24h7CyE76fZh+D2Bams/3irW jTOTtZk3zH6EwStHyncE3uswD3JtPOIkcqY1xWgdmIRH0FkvelD5WIlJ2RjJoA6QXNkL Kq0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SYQsThur; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91-v6si8419316ply.335.2018.11.11.15.50.43; Sun, 11 Nov 2018 15:50:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SYQsThur; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732958AbeKLISg (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:37518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732914AbeKLISd (ORCPT ); Mon, 12 Nov 2018 03:18:33 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A35482154B; Sun, 11 Nov 2018 22:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975317; bh=dSK0nL0PV6EiJTvTP7FfL7f0/mHw304eTkofo8rqWHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYQsThurM6sHlOtcsGVFTVtTwlvq+lzs6KoACm13lnXFC/jJieBV08wwB7ZO1nQxO KnXioDs9cASE+AKmi0Cx7QgvVi3jG0lkaP2LRfIlkEqHW1Np5nyUTRC9aBTeKdc69u 8X/Oaa0e2r09wZ62y1xxNIXcGySjy3GtX7HA7PIs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mauro Carvalho Chehab Subject: [PATCH 4.19 309/361] media: em28xx: fix handler for vidioc_s_input() Date: Sun, 11 Nov 2018 14:20:56 -0800 Message-Id: <20181111221658.117155504@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mauro Carvalho Chehab commit 258c430456ba5f0005043762e14fc3be35983aaf upstream. The a->index is not the name of the internal amux entry, but, instead a value from zero to the maximum number of audio inputs. As the actual available inputs depend on each board, build it dynamically. This is broken for a really long time. On a quick check, since at least commit 195a4ef627e1 ("V4L/DVB (6585): Convert em28xx to video_ioctl2") this was not implemented right. Fixes: 195a4ef627e1 ("V4L/DVB (6585): Convert em28xx to video_ioctl2") Cc: stable@vger.kernel.org Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/em28xx/em28xx-cards.c | 29 ++++++++++ drivers/media/usb/em28xx/em28xx-video.c | 86 ++++++++++++++++++++++++++++---- drivers/media/usb/em28xx/em28xx.h | 8 ++ 3 files changed, 113 insertions(+), 10 deletions(-) --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -3039,6 +3039,9 @@ static int em28xx_hint_board(struct em28 static void em28xx_card_setup(struct em28xx *dev) { + int i, j, idx; + bool duplicate_entry; + /* * If the device can be a webcam, seek for a sensor. * If sensor is not found, then it isn't a webcam. @@ -3195,6 +3198,32 @@ static void em28xx_card_setup(struct em2 /* Allow override tuner type by a module parameter */ if (tuner >= 0) dev->tuner_type = tuner; + + /* + * Dynamically generate a list of valid audio inputs for this + * specific board, mapping them via enum em28xx_amux. + */ + + idx = 0; + for (i = 0; i < MAX_EM28XX_INPUT; i++) { + if (!INPUT(i)->type) + continue; + + /* Skip already mapped audio inputs */ + duplicate_entry = false; + for (j = 0; j < idx; j++) { + if (INPUT(i)->amux == dev->amux_map[j]) { + duplicate_entry = true; + break; + } + } + if (duplicate_entry) + continue; + + dev->amux_map[idx++] = INPUT(i)->amux; + } + for (; idx < MAX_EM28XX_INPUT; idx++) + dev->amux_map[idx] = EM28XX_AMUX_UNUSED; } void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl) --- a/drivers/media/usb/em28xx/em28xx-video.c +++ b/drivers/media/usb/em28xx/em28xx-video.c @@ -1668,6 +1668,7 @@ static int vidioc_enum_input(struct file { struct em28xx *dev = video_drvdata(file); unsigned int n; + int j; n = i->index; if (n >= MAX_EM28XX_INPUT) @@ -1687,6 +1688,12 @@ static int vidioc_enum_input(struct file if (dev->is_webcam) i->capabilities = 0; + /* Dynamically generates an audioset bitmask */ + i->audioset = 0; + for (j = 0; j < MAX_EM28XX_INPUT; j++) + if (dev->amux_map[j] != EM28XX_AMUX_UNUSED) + i->audioset |= 1 << j; + return 0; } @@ -1712,11 +1719,24 @@ static int vidioc_s_input(struct file *f return 0; } -static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) -{ - struct em28xx *dev = video_drvdata(file); +static int em28xx_fill_audio_input(struct em28xx *dev, + const char *s, + struct v4l2_audio *a, + unsigned int index) +{ + unsigned int idx = dev->amux_map[index]; + + /* + * With msp3400, almost all mappings use the default (amux = 0). + * The only one may use a different value is WinTV USB2, where it + * can also be SCART1 input. + * As it is very doubtful that we would see new boards with msp3400, + * let's just reuse the existing switch. + */ + if (dev->has_msp34xx && idx != EM28XX_AMUX_UNUSED) + idx = EM28XX_AMUX_LINE_IN; - switch (a->index) { + switch (idx) { case EM28XX_AMUX_VIDEO: strcpy(a->name, "Television"); break; @@ -1741,32 +1761,79 @@ static int vidioc_g_audio(struct file *f case EM28XX_AMUX_PCM_OUT: strcpy(a->name, "PCM"); break; + case EM28XX_AMUX_UNUSED: default: return -EINVAL; } - - a->index = dev->ctl_ainput; + a->index = index; a->capability = V4L2_AUDCAP_STEREO; + em28xx_videodbg("%s: audio input index %d is '%s'\n", + s, a->index, a->name); + return 0; } +static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a) +{ + struct em28xx *dev = video_drvdata(file); + + if (a->index >= MAX_EM28XX_INPUT) + return -EINVAL; + + return em28xx_fill_audio_input(dev, __func__, a, a->index); +} + +static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) +{ + struct em28xx *dev = video_drvdata(file); + int i; + + for (i = 0; i < MAX_EM28XX_INPUT; i++) + if (dev->ctl_ainput == dev->amux_map[i]) + return em28xx_fill_audio_input(dev, __func__, a, i); + + /* Should never happen! */ + return -EINVAL; +} + static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a) { struct em28xx *dev = video_drvdata(file); + int idx, i; if (a->index >= MAX_EM28XX_INPUT) return -EINVAL; - if (!INPUT(a->index)->type) + + idx = dev->amux_map[a->index]; + + if (idx == EM28XX_AMUX_UNUSED) + return -EINVAL; + + dev->ctl_ainput = idx; + + /* + * FIXME: This is wrong, as different inputs at em28xx_cards + * may have different audio outputs. So, the right thing + * to do is to implement VIDIOC_G_AUDOUT/VIDIOC_S_AUDOUT. + * With the current board definitions, this would work fine, + * as, currently, all boards fit. + */ + for (i = 0; i < MAX_EM28XX_INPUT; i++) + if (idx == dev->amux_map[i]) + break; + if (i == MAX_EM28XX_INPUT) return -EINVAL; - dev->ctl_ainput = INPUT(a->index)->amux; - dev->ctl_aoutput = INPUT(a->index)->aout; + dev->ctl_aoutput = INPUT(i)->aout; if (!dev->ctl_aoutput) dev->ctl_aoutput = EM28XX_AOUT_MASTER; + em28xx_videodbg("%s: set audio input to %d\n", __func__, + dev->ctl_ainput); + return 0; } @@ -2304,6 +2371,7 @@ static const struct v4l2_ioctl_ops video .vidioc_try_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, .vidioc_s_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, .vidioc_enum_framesizes = vidioc_enum_framesizes, + .vidioc_enumaudio = vidioc_enumaudio, .vidioc_g_audio = vidioc_g_audio, .vidioc_s_audio = vidioc_s_audio, --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h @@ -335,6 +335,9 @@ enum em28xx_usb_audio_type { /** * em28xx_amux - describes the type of audio input used by em28xx * + * @EM28XX_AMUX_UNUSED: + * Used only on em28xx dev->map field, in order to mark an entry + * as unused. * @EM28XX_AMUX_VIDEO: * On devices without AC97, this is the only value that it is currently * allowed. @@ -369,7 +372,8 @@ enum em28xx_usb_audio_type { * same time, via the alsa mux. */ enum em28xx_amux { - EM28XX_AMUX_VIDEO, + EM28XX_AMUX_UNUSED = -1, + EM28XX_AMUX_VIDEO = 0, EM28XX_AMUX_LINE_IN, /* Some less-common mixer setups */ @@ -692,6 +696,8 @@ struct em28xx { unsigned int ctl_input; // selected input unsigned int ctl_ainput;// selected audio input unsigned int ctl_aoutput;// selected audio output + enum em28xx_amux amux_map[MAX_EM28XX_INPUT]; + int mute; int volume;