From patchwork Thu Jan 18 21:00:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 125040 Delivered-To: patch@linaro.org Received: by 10.46.64.27 with SMTP id n27csp294796lja; Thu, 18 Jan 2018 13:01:29 -0800 (PST) X-Google-Smtp-Source: ACJfBotVERFYwXh8neMqaVZzx9U+VDVYZaUTC9c4jrrFwO8AXXGVET8F4+D+/sPXYUKsz44olnCo X-Received: by 2002:a17:902:5305:: with SMTP id b5-v6mr407773pli.325.1516309289357; Thu, 18 Jan 2018 13:01:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516309289; cv=none; d=google.com; s=arc-20160816; b=Uflb6V3qeZ3wrHoM/h5iIYQl3We4cIX1RDqNUGYcuMHYZi5zsYf3SxB1tOL2i9VTtr flIo9RKTiQHRH/k14W76TcUds/AGpNHTxGbKHptZn6qWHuBMtEtPriRQO+9bRPITW2aF FriaGDGzgY4Dz0WrQDfcs1gsuFlZegaMCYlUKRz2efxe4lLRgCbAOrpwBgCWUZW6qFoB jWFJMzK1pD1PwGp6ywEEtB39qXaryfB8OmSaS0t6bKSX90foAJqIvWCnd4eS1mYXYwu1 yLyhCqZc5jHWeZBPgldjMSIaT9RDXwZVVekB504Oup/F/s21IgJU4AJnR18ozOuOz5Ku WxXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=O4V/oNKvobDZg0splxU9qQYldvTH6TdQ2WC+eB1xcMc=; b=dYbvobWu+nZ8ur8y37/2x9Q0N7ZkBajeI4tB0rBtNMCC1MbtoSVRxItnXO9ETKlCrG 7xGLpUNh6GdGa/u0GwYuOoA4DW+72KcY9a1TKhGRLci9qKdzZwzcko3/xmYU9J5kYAuQ L/gYoMRDk4PIfJL1jb4oHe55mcofpWaoF8of6iCcnvDmrh5WlNHfScZo+l0vq+SEirFv +kaIr0mKMZaM0jRUKe4ZoAhDLF6UYyk8CZqM9CkaCmXiDr7+K/TO4e7geOatTOiF2Vrh lA4UoYL3SxPKfcGA9dEoawjdiF9Nk4L2dxv7DCIGt+7oEp56xWWQJ8xd9h9gvkQd9m3x XWpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=fMHsviZ5; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c16si4933770pgu.706.2018.01.18.13.01.28; Thu, 18 Jan 2018 13:01:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@microsoft.com header.s=selector1 header.b=fMHsviZ5; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755006AbeARVB1 (ORCPT + 10 others); Thu, 18 Jan 2018 16:01:27 -0500 Received: from mail-by2nam01on0104.outbound.protection.outlook.com ([104.47.34.104]:11884 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754876AbeARVBW (ORCPT ); Thu, 18 Jan 2018 16:01:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=O4V/oNKvobDZg0splxU9qQYldvTH6TdQ2WC+eB1xcMc=; b=fMHsviZ57i/CyAEyaD2fOP6D6t0Pl49biZfgrYqFURstJWrDatDhEjqosa47P/vnvn/7ML+AxWB9SinxzXLnpvc/njSpNjuR7t0HKiwKDJTPFvh9gFllc3IPfBXOpCgDK057/tP4CZg7yKWtqzOWhHFahX5NNTu/cTlaDhcvV4E= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0805.namprd21.prod.outlook.com (10.167.105.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.428.7; Thu, 18 Jan 2018 21:01:16 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0428.008; Thu, 18 Jan 2018 21:01:16 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Sumit Semwal , Henrik Ingo , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [added to the 4.1 stable tree] [media] uvcvideo: uvc_scan_fallback() for webcams with broken chain Thread-Topic: [added to the 4.1 stable tree] [media] uvcvideo: uvc_scan_fallback() for webcams with broken chain Thread-Index: AQHTkJ9Rt2dBKRM6I0mSsB2y2wciUg== Date: Thu, 18 Jan 2018 21:00:06 +0000 Message-ID: <20180118205908.3220-81-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [167.220.98.9] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0805; 7:IvNcTBcwoWwOzjGGwH6bTtlw7Ou5/RTQdKrSsOiNg6GtBmQzUZzfdruxVdwCHcDl4YELqQk1ztiYAUOhfIg6sRBix2mb13v4i4ijwYE0CQ7Gq6pxR2ERAowLHnwhWNu7aJiskRuo6GcqM7AiIgcQP7HoIxpMXga/a1LMCvnrUdnNlV0t6+GOIIvnipNCO/9zFXueMvzzk7TO5YM5wnCJt+ptY1iPJXB1K4lFx8n3HEbvn0pdXjbkTZQdevO1aHm7 x-ms-office365-filtering-correlation-id: c942f522-aa86-474b-86fe-08d55eb69d63 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020); SRVR:DM5PR2101MB0805; x-ms-traffictypediagnostic: DM5PR2101MB0805: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(21532816269658); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(6040495)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231046)(2400067)(944501161)(3002001)(6055026)(61426038)(61427038)(6041282)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011); SRVR:DM5PR2101MB0805; BCL:0; PCL:0; RULEID:(100000803126)(100110400120); SRVR:DM5PR2101MB0805; x-forefront-prvs: 05568D1FF7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(39380400002)(366004)(376002)(346002)(396003)(189003)(199004)(2906002)(2900100001)(6512007)(86362001)(305945005)(97736004)(68736007)(10090500001)(2501003)(6666003)(7736002)(105586002)(5250100002)(2950100002)(5660300001)(6116002)(36756003)(6486002)(26005)(86612001)(54906003)(4326008)(3280700002)(3846002)(6346003)(6436002)(3660700001)(10290500003)(478600001)(107886003)(76176011)(66066001)(1076002)(81156014)(99286004)(81166006)(106356001)(53936002)(102836004)(22452003)(110136005)(59450400001)(14454004)(316002)(72206003)(25786009)(6506007)(8676002)(8936002)(22906009); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0805; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: MIzhw5T7kPa58I2XMPE8CkF3yz8ZachSdiBANowyUw6YV9qkIwaVv/vtCQsDg9rIPFhZ7czqOZwwPrrdmzm08A== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: c942f522-aa86-474b-86fe-08d55eb69d63 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2018 21:00:06.0409 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0805 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sumit Semwal This patch has been added to the stable tree. If you have any objections, please let us know. -- 2.11.0 =============== [ Upstream commit e950267ab802c8558f1100eafd4087fd039ad634 ] Some devices have invalid baSourceID references, causing uvc_scan_chain() to fail, but if we just take the entities we can find and put them together in the most sensible chain we can think of, turns out they do work anyway. Note: This heuristic assumes there is a single chain. At the time of writing, devices known to have such a broken chain are - Acer Integrated Camera (5986:055a) - Realtek rtl157a7 (0bda:57a7) Signed-off-by: Henrik Ingo Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_driver.c | 118 +++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 5970dd6a1c1c..a41a4f6a51b2 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1574,6 +1574,114 @@ static const char *uvc_print_chain(struct uvc_video_chain *chain) return buffer; } +static struct uvc_video_chain *uvc_alloc_chain(struct uvc_device *dev) +{ + struct uvc_video_chain *chain; + + chain = kzalloc(sizeof(*chain), GFP_KERNEL); + if (chain == NULL) + return NULL; + + INIT_LIST_HEAD(&chain->entities); + mutex_init(&chain->ctrl_mutex); + chain->dev = dev; + v4l2_prio_init(&chain->prio); + + return chain; +} + +/* + * Fallback heuristic for devices that don't connect units and terminals in a + * valid chain. + * + * Some devices have invalid baSourceID references, causing uvc_scan_chain() + * to fail, but if we just take the entities we can find and put them together + * in the most sensible chain we can think of, turns out they do work anyway. + * Note: This heuristic assumes there is a single chain. + * + * At the time of writing, devices known to have such a broken chain are + * - Acer Integrated Camera (5986:055a) + * - Realtek rtl157a7 (0bda:57a7) + */ +static int uvc_scan_fallback(struct uvc_device *dev) +{ + struct uvc_video_chain *chain; + struct uvc_entity *iterm = NULL; + struct uvc_entity *oterm = NULL; + struct uvc_entity *entity; + struct uvc_entity *prev; + + /* + * Start by locating the input and output terminals. We only support + * devices with exactly one of each for now. + */ + list_for_each_entry(entity, &dev->entities, list) { + if (UVC_ENTITY_IS_ITERM(entity)) { + if (iterm) + return -EINVAL; + iterm = entity; + } + + if (UVC_ENTITY_IS_OTERM(entity)) { + if (oterm) + return -EINVAL; + oterm = entity; + } + } + + if (iterm == NULL || oterm == NULL) + return -EINVAL; + + /* Allocate the chain and fill it. */ + chain = uvc_alloc_chain(dev); + if (chain == NULL) + return -ENOMEM; + + if (uvc_scan_chain_entity(chain, oterm) < 0) + goto error; + + prev = oterm; + + /* + * Add all Processing and Extension Units with two pads. The order + * doesn't matter much, use reverse list traversal to connect units in + * UVC descriptor order as we build the chain from output to input. This + * leads to units appearing in the order meant by the manufacturer for + * the cameras known to require this heuristic. + */ + list_for_each_entry_reverse(entity, &dev->entities, list) { + if (entity->type != UVC_VC_PROCESSING_UNIT && + entity->type != UVC_VC_EXTENSION_UNIT) + continue; + + if (entity->num_pads != 2) + continue; + + if (uvc_scan_chain_entity(chain, entity) < 0) + goto error; + + prev->baSourceID[0] = entity->id; + prev = entity; + } + + if (uvc_scan_chain_entity(chain, iterm) < 0) + goto error; + + prev->baSourceID[0] = iterm->id; + + list_add_tail(&chain->list, &dev->chains); + + uvc_trace(UVC_TRACE_PROBE, + "Found a video chain by fallback heuristic (%s).\n", + uvc_print_chain(chain)); + + return 0; + +error: + kfree(chain); + return -EINVAL; +} + /* * Scan the device for video chains and register video devices. * @@ -1596,15 +1704,10 @@ static int uvc_scan_device(struct uvc_device *dev) if (term->chain.next || term->chain.prev) continue; - chain = kzalloc(sizeof(*chain), GFP_KERNEL); + chain = uvc_alloc_chain(dev); if (chain == NULL) return -ENOMEM; - INIT_LIST_HEAD(&chain->entities); - mutex_init(&chain->ctrl_mutex); - chain->dev = dev; - v4l2_prio_init(&chain->prio); - term->flags |= UVC_ENTITY_FLAG_DEFAULT; if (uvc_scan_chain(chain, term) < 0) { @@ -1618,6 +1721,9 @@ static int uvc_scan_device(struct uvc_device *dev) list_add_tail(&chain->list, &dev->chains); } + if (list_empty(&dev->chains)) + uvc_scan_fallback(dev); + if (list_empty(&dev->chains)) { uvc_printk(KERN_INFO, "No valid video chain found.\n"); return -1;