From patchwork Mon Dec 21 16:48:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 346512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1CE8C433DB for ; Mon, 21 Dec 2020 18:32:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A03422D08 for ; Mon, 21 Dec 2020 18:32:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726973AbgLUSbl (ORCPT ); Mon, 21 Dec 2020 13:31:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbgLUSbl (ORCPT ); Mon, 21 Dec 2020 13:31:41 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E922BC0611CA for ; Mon, 21 Dec 2020 10:31:00 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id v14so10770853wml.1 for ; Mon, 21 Dec 2020 10:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JUU/kBHu4HGyyU4lEfHmeqtlxPdX9da5tT69I1KN5l0=; b=RWPF+0/oIbWQeDALXn2RpugXOROfawoQb+MqopV9BlmzeSpPAK2+HxXhIMisSBUoME hmKnuJ+QNwO5Aotg8ayGcrUi5hq5IeyW1sMKEzXYNW5QrTCvU+3jJpDoSxW7FZ81xZ4v S74ggY32Eyb+vTSXutpARpZ8Dy3fWFQ/g94oo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JUU/kBHu4HGyyU4lEfHmeqtlxPdX9da5tT69I1KN5l0=; b=RU0plL6vwSvYdKyPACwlJJAQRxvjZeWHBLoXftRN3YtuA0YjCX4aU9B4pSK2hkXpqJ FZ6ZwJPKia3G+uO7arLoWhjcyANoXEBCkbo5d2Pxa6DyxkETE0hNY68cNeDTmJZHMuQ6 rQ/aKQFDMxfal/g72/RJPj3BMIlVT/UywwksNIEweqedD1T0A0cApPedb7AavkrLkL7r QFW1P0O+dbTN3kzU8ccalF0pLA8SrSonoSj/mWJEiIF0sXIf1SpUK8egz6YdeRX5YZdH DrbCVIzSlJnmOvCAQKOQz2CrQMu/AsO3hK3g1I9SL7QR3r7r34luAwSynLpjznEtFfvu qwdw== X-Gm-Message-State: AOAM530kI39Z3VOvtpLQy5F+9OH7xaCI29j0V0xNioF0ituAuDEfdAt3 k7QqAXjMmBMD5YPqPBPNNggtlmquG8C7aERshdE= X-Google-Smtp-Source: ABdhPJzy9mh3U6pQMxNO/zWfgHQ0T3XCX+bncmTrEkG545InEDWoLdm0B+Cen1oUnpgSs/JWtU9OvA== X-Received: by 2002:a1c:6402:: with SMTP id y2mr17003057wmb.43.1608569303631; Mon, 21 Dec 2020 08:48:23 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id o125sm24581109wmo.30.2020.12.21.08.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 08:48:23 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v5 02/12] media: uvcvideo: Allow more that one asyc_ctrl Date: Mon, 21 Dec 2020 17:48:09 +0100 Message-Id: <20201221164819.792019-3-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201221164819.792019-1-ribalda@chromium.org> References: <20201221164819.792019-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The current implementation allocates memory for only one async_control. If we get a second event before we have processed the previous one, the old one gets lost. Introduce a dynamic memory allocation and a list to handle the async_controls. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 49 ++++++++++++++++++++++++++------ drivers/media/usb/uvc/uvcvideo.h | 19 ++++++++----- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index aa18dcdf8165..69b2fc6ce12c 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1275,11 +1275,9 @@ static void uvc_ctrl_send_slave_event(struct uvc_video_chain *chain, uvc_ctrl_send_event(chain, handle, ctrl, mapping, val, changes); } -static void uvc_ctrl_status_event_work(struct work_struct *work) +static void __uvc_ctrl_status_event_work(struct uvc_device *dev, + struct uvc_ctrl_work *w) { - struct uvc_device *dev = container_of(work, struct uvc_device, - async_ctrl.work); - struct uvc_ctrl_work *w = &dev->async_ctrl; struct uvc_video_chain *chain = w->chain; struct uvc_control_mapping *mapping; struct uvc_control *ctrl = w->ctrl; @@ -1321,23 +1319,54 @@ static void uvc_ctrl_status_event_work(struct work_struct *work) ret); } +static void uvc_ctrl_status_event_work(struct work_struct *work) +{ + struct uvc_device *dev = container_of(work, struct uvc_device, + async_ctrl_work); + struct uvc_ctrl_work *w; + + do { + mutex_lock(&dev->async_ctrl_lock); + w = list_first_entry_or_null(&dev->async_ctrl_list, + struct uvc_ctrl_work, + list); + if (w) + list_del(&w->list); + mutex_unlock(&dev->async_ctrl_lock); + + if (!w) + return; + + __uvc_ctrl_status_event_work(dev, w); + kfree(w); + } while (w); +} + bool uvc_ctrl_status_event(struct urb *urb, struct uvc_video_chain *chain, struct uvc_control *ctrl, const u8 *data) { struct uvc_device *dev = chain->dev; - struct uvc_ctrl_work *w = &dev->async_ctrl; + struct uvc_ctrl_work *w; if (list_empty(&ctrl->info.mappings)) { ctrl->handle = NULL; return false; } + w = kzalloc(sizeof(*w), GFP_KERNEL); + if (WARN(!w, "Not enough memory to trigger uvc event")) + return false; + memcpy(w->data, data, ctrl->info.size); w->urb = urb; w->chain = chain; w->ctrl = ctrl; - schedule_work(&w->work); + mutex_lock(&dev->async_ctrl_lock); + list_add_tail(&w->list, &dev->async_ctrl_list); + mutex_unlock(&dev->async_ctrl_lock); + + schedule_work(&dev->async_ctrl_work); return true; } @@ -2277,7 +2306,9 @@ int uvc_ctrl_init_device(struct uvc_device *dev) struct uvc_entity *entity; unsigned int i; - INIT_WORK(&dev->async_ctrl.work, uvc_ctrl_status_event_work); + INIT_WORK(&dev->async_ctrl_work, uvc_ctrl_status_event_work); + mutex_init(&dev->async_ctrl_lock); + INIT_LIST_HEAD(&dev->async_ctrl_list); /* Walk the entities list and instantiate controls */ list_for_each_entry(entity, &dev->entities, list) { @@ -2348,8 +2379,8 @@ void uvc_ctrl_cleanup_device(struct uvc_device *dev) unsigned int i; /* Can be uninitialized if we are aborting on probe error. */ - if (dev->async_ctrl.work.func) - cancel_work_sync(&dev->async_ctrl.work); + if (dev->async_ctrl_work.func) + cancel_work_sync(&dev->async_ctrl_work); /* Free controls and control mappings for all entities. */ list_for_each_entry(entity, &dev->entities, list) { diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 0db6c2e0bd98..afcaf49fad1a 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -637,6 +637,14 @@ struct uvc_device_info { u32 meta_format; }; +struct uvc_ctrl_work { + struct list_head list; + struct urb *urb; + struct uvc_video_chain *chain; + struct uvc_control *ctrl; + u8 data[UVC_MAX_STATUS_SIZE]; +}; + struct uvc_device { struct usb_device *udev; struct usb_interface *intf; @@ -673,13 +681,10 @@ struct uvc_device { struct input_dev *input; char input_phys[64]; - struct uvc_ctrl_work { - struct work_struct work; - struct urb *urb; - struct uvc_video_chain *chain; - struct uvc_control *ctrl; - u8 data[UVC_MAX_STATUS_SIZE]; - } async_ctrl; + /* Async control */ + struct work_struct async_ctrl_work; + struct list_head async_ctrl_list; + struct mutex async_ctrl_lock; }; enum uvc_handle_state { From patchwork Mon Dec 21 16:48:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 346510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADFFDC433DB for ; Mon, 21 Dec 2020 18:45:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F9A2229C4 for ; Mon, 21 Dec 2020 18:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726948AbgLUSow (ORCPT ); Mon, 21 Dec 2020 13:44:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726942AbgLUSow (ORCPT ); Mon, 21 Dec 2020 13:44:52 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEACCC0613D3 for ; Mon, 21 Dec 2020 10:44:11 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id a6so10819862wmc.2 for ; Mon, 21 Dec 2020 10:44:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GxBnprDCZ8ETALSrcjDqUFKJ+dolK5Q6ES1f8OyDC/c=; b=k47fzwJ+SznvdDchmWl8VBBQjY/aTV8bTbun1m6WOVRcSSDMMY2P4+QRjnsFQkKob9 8EUUMKsCYQybpMvywk2fqC8pkmFJ1mrN+DBAxlgWXWaxREYoiZrLbmXvhjjxi1ISJ3Au LL9yUVxkC2ZhDB0dXQrsfijaUc32zNJ/MSsUc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GxBnprDCZ8ETALSrcjDqUFKJ+dolK5Q6ES1f8OyDC/c=; b=EXxAVBf+5YXjAVs8LzkK9lZJ85HfwDCiOXPxpJZb5VFYmNVqcUtA/XX1xUEbr+GZou jEjmRQEbrsAvrV0/XEkTLvE9GtbcHnqyq+xz4LZkhKeGKkh/rxKBfKAZGwLHn4tglD1a H1zC/CWEYnbyzKQh8nIL2itiBN6+KBpb1jru5h59L223v8oqkFGRIs4euEK1T3Z63tn4 yZuehpeor6c9aLSG+Fxp/AOu5eJcQmQH76M3FJURMKfm9FTx2ZI7MgtEN3TaWyIGIqme x34PNpNPKYsJRH5G/Ft10MRGTFrjFooZMXtUZa7DfoAiJ9hAueJXyhLSVdpsJEEtCLKf GhJQ== X-Gm-Message-State: AOAM532DrsULoIU2yyQ4vq4QfUmqp/Kb4kKLEuTTjXc2KMqEr+0IQm/3 tTWSvwqygviY2ImkyFHmE9+YAzIYyJBLcn0vBgQ= X-Google-Smtp-Source: ABdhPJwt4yprCw7ncEO6VOVLMfCJOU0nOn068+ce9e6P21H7n6qS9VJJxAaHfvSf88dhnmcHVwQ4VA== X-Received: by 2002:a1c:8d:: with SMTP id 135mr17419177wma.177.1608569304346; Mon, 21 Dec 2020 08:48:24 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id o125sm24581109wmo.30.2020.12.21.08.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 08:48:23 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v5 03/12] media: uvcvideo: Move guid to entity Date: Mon, 21 Dec 2020 17:48:10 +0100 Message-Id: <20201221164819.792019-4-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201221164819.792019-1-ribalda@chromium.org> References: <20201221164819.792019-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Instead of having multiple copies of the entity guid on the code, move it to the entity structure. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 30 ++++-------------------------- drivers/media/usb/uvc/uvc_driver.c | 25 +++++++++++++++++++++++-- drivers/media/usb/uvc/uvcvideo.h | 2 +- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 69b2fc6ce12c..d7ccd0fcd88d 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -826,31 +826,10 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping, * Terminal and unit management */ -static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; -static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; -static const u8 uvc_media_transport_input_guid[16] = - UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; - static int uvc_entity_match_guid(const struct uvc_entity *entity, - const u8 guid[16]) + const u8 guid[16]) { - switch (UVC_ENTITY_TYPE(entity)) { - case UVC_ITT_CAMERA: - return memcmp(uvc_camera_guid, guid, 16) == 0; - - case UVC_ITT_MEDIA_TRANSPORT_INPUT: - return memcmp(uvc_media_transport_input_guid, guid, 16) == 0; - - case UVC_VC_PROCESSING_UNIT: - return memcmp(uvc_processing_guid, guid, 16) == 0; - - case UVC_VC_EXTENSION_UNIT: - return memcmp(entity->extension.guidExtensionCode, - guid, 16) == 0; - - default: - return 0; - } + return memcmp(entity->guid, guid, sizeof(entity->guid)) == 0; } /* ------------------------------------------------------------------------ @@ -1805,8 +1784,7 @@ static int uvc_ctrl_fill_xu_info(struct uvc_device *dev, if (data == NULL) return -ENOMEM; - memcpy(info->entity, ctrl->entity->extension.guidExtensionCode, - sizeof(info->entity)); + memcpy(info->entity, ctrl->entity->guid, sizeof(info->entity)); info->index = ctrl->index; info->selector = ctrl->index + 1; @@ -1912,7 +1890,7 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, if (!found) { uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u not found.\n", - entity->extension.guidExtensionCode, xqry->selector); + entity->guid, xqry->selector); return -ENOENT; } diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index ddb9eaa11be7..bfbc5a4d4ca6 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1019,6 +1019,11 @@ static int uvc_parse_streaming(struct uvc_device *dev, return ret; } +static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; +static const u8 uvc_media_transport_input_guid[16] = + UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; +static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; + static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id, unsigned int num_pads, unsigned int extra_size) { @@ -1038,6 +1043,22 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id, entity->id = id; entity->type = type; + /* + * Set the GUID for standard entity types. For extension units, the GUID + * is initialized by the caller. + */ + switch (type) { + case UVC_ITT_CAMERA: + memcpy(entity->guid, uvc_camera_guid, 16); + break; + case UVC_ITT_MEDIA_TRANSPORT_INPUT: + memcpy(entity->guid, uvc_media_transport_input_guid, 16); + break; + case UVC_VC_PROCESSING_UNIT: + memcpy(entity->guid, uvc_processing_guid, 16); + break; + } + entity->num_links = 0; entity->num_pads = num_pads; entity->pads = ((void *)(entity + 1)) + extra_size; @@ -1109,7 +1130,7 @@ static int uvc_parse_vendor_control(struct uvc_device *dev, if (unit == NULL) return -ENOMEM; - memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); + memcpy(unit->guid, &buffer[4], 16); unit->extension.bNumControls = buffer[20]; memcpy(unit->baSourceID, &buffer[22], p); unit->extension.bControlSize = buffer[22+p]; @@ -1368,7 +1389,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, if (unit == NULL) return -ENOMEM; - memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); + memcpy(unit->guid, &buffer[4], 16); unit->extension.bNumControls = buffer[20]; memcpy(unit->baSourceID, &buffer[22], p); unit->extension.bControlSize = buffer[22+p]; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index afcaf49fad1a..0a3404091665 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -304,6 +304,7 @@ struct uvc_entity { u8 id; u16 type; char name[64]; + u8 guid[16]; /* Media controller-related fields. */ struct video_device *vdev; @@ -342,7 +343,6 @@ struct uvc_entity { } selector; struct { - u8 guidExtensionCode[16]; u8 bNumControls; u8 bControlSize; u8 *bmControls; From patchwork Mon Dec 21 16:48:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 346509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A169C433E9 for ; Mon, 21 Dec 2020 18:49:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E82B922AAB for ; Mon, 21 Dec 2020 18:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726889AbgLUStB (ORCPT ); Mon, 21 Dec 2020 13:49:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726683AbgLUStB (ORCPT ); Mon, 21 Dec 2020 13:49:01 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 929ACC0613D3 for ; Mon, 21 Dec 2020 10:48:20 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id r4so11937549wmh.5 for ; Mon, 21 Dec 2020 10:48:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=80KPby0xcz+iK59YkSpKMwmYMBDDjMUhltAQvUYuGYI=; b=PBUhAqFugSrK7CSnPkt/nRSA79ntpcvblfiGq0PCFSBHK4jYX9ZYrQjD2tDDQM+hK4 vRXmKb5Vtzz6ervNwhcR6anPJGRNeJSRyB00KlORr2rUhygnNSh+nujwQde6jcoeAhPd ymmQpV1YZFOh+qGkiFbpAbe9QybGw763WvKv4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=80KPby0xcz+iK59YkSpKMwmYMBDDjMUhltAQvUYuGYI=; b=X60AqBmoKAE9mZXVXdm1s8BbVOlAWyXVN9HYcOigYBa6eygE/XQRiNX+uxqqv33o3D 2moX+RQc2Tivk/31LcPMZ6QLB3yKnU4+rNqDAY04urtZ/pTk5XN5Pra+Q18j/sd2ossh 2Yvq13pYjwfCqjHNhbgAAZh2E4Iw+TwX2eU29gbvgiNeXI5yb0vnUiycI05fqrZRGr5A k+CP2suZS0TzAMcCdMZQEW0X/Ulchhn8BfdJp52E+Ma2/RslajBzxPvz+giRvR2wqLBa m82TKgXNbHCcFanyOOmGqlzCTtEU5Fqqv+vq9iJzuZNuIYuB9Grq3LMo143ZjE5R9Syh y/OQ== X-Gm-Message-State: AOAM531+1P0cJ5MbkEsH+uKzVUkGlghX2SrIcgXcJN3nDyHhg06V72/L IuJ0ZEa/2xUpb2gXEMN2aoPgnupWyJ2vLFVSt0o= X-Google-Smtp-Source: ABdhPJyTadWVI5YU5Jq8O4Budepa0tJFPD1wnTSdIcik689xVi5MtgGunTRsHnBgB4BEI8pFrC/8xw== X-Received: by 2002:a1c:4e0a:: with SMTP id g10mr17324701wmh.88.1608569305892; Mon, 21 Dec 2020 08:48:25 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id o125sm24581109wmo.30.2020.12.21.08.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 08:48:25 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v5 05/12] media: uvcvideo: Allow entities with no pads Date: Mon, 21 Dec 2020 17:48:12 +0100 Message-Id: <20201221164819.792019-6-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201221164819.792019-1-ribalda@chromium.org> References: <20201221164819.792019-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Avoid an underflow while calculating the number of inputs for entities with zero pads. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 82cdd1bb28dc..c0c5f75ade40 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1033,7 +1033,10 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, unsigned int i; extra_size = roundup(extra_size, sizeof(*entity->pads)); - num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1; + if (num_pads) + num_inputs = type & UVC_TERM_OUTPUT ? num_pads : num_pads - 1; + else + num_inputs = 0; size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads + num_inputs; entity = kzalloc(size, GFP_KERNEL); @@ -1065,7 +1068,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, for (i = 0; i < num_inputs; ++i) entity->pads[i].flags = MEDIA_PAD_FL_SINK; - if (!UVC_ENTITY_IS_OTERM(entity)) + if (!UVC_ENTITY_IS_OTERM(entity) && num_pads) entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE; entity->bNrInPins = num_inputs; From patchwork Mon Dec 21 16:48:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 346514 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F22BAC433E0 for ; Mon, 21 Dec 2020 18:29:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4B7922D08 for ; Mon, 21 Dec 2020 18:29:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726557AbgLUS3B (ORCPT ); Mon, 21 Dec 2020 13:29:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725910AbgLUS3B (ORCPT ); Mon, 21 Dec 2020 13:29:01 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5822C0613D3 for ; Mon, 21 Dec 2020 10:28:20 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id y23so11881935wmi.1 for ; Mon, 21 Dec 2020 10:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4kcgi01wgItQpOubw2spttIDcP8vTsmoc49nzk/8qIw=; b=KZzkZ/gSDYYvjeSZ/JCelI18eU6zzJY3dZqIlxQ5JpDcCA4sfRdV7vaFIyDoNmTxrw xlBVxAvq9XxYTDO60TXU+oUJ45QbAWCGX3CRiODJMWt/sEXR63VeaAnWGO+G4Su7jgQU mKbUKa7Tda+ydjgHi4M6mOP2YX7Jrrd5dEcz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4kcgi01wgItQpOubw2spttIDcP8vTsmoc49nzk/8qIw=; b=XZLRrCmYD7NvnRc8bs7Pfjg7VPyCgIiOnQok8tikSudGUbR5rXWKSJdmPL5Q9q8Kmc PtpaEEUtEfTA78zyc/Fs6SCMQg3jUEZtF6GMfn1wClBjGQHT5bXJ4ZzT5VJVZ+UvYKPc 9Jj0ygjpiz6k/WEAA0NIEO6KQeOKJMkMSyBstzTnL/JIg8RrcONoQd1F8ehBNoAwQZiA J6NHAqcma6yHu0swgXngUtCQmNd2OfwUkvxjRsZqL7Zia2/67Gsmqd8r3OHcjbuo6Qzg +2JOmVM7+E+I5B7daW6anLd3a7r0WpZHGCbcJYsXvlYVlTmspEImb/+kM05jf+T2leVf s/ng== X-Gm-Message-State: AOAM533hHEpJx06DBtCbEnv18eb3oBHAoeiqew+b2j3txNn5mlwffPWV ku7sw4DFpSnG7w0BVKVtIAfPr6KtxrftDnlXPv8= X-Google-Smtp-Source: ABdhPJy+SvXsvllykpmarIUJ6j7nFLIP4ZJYvTdam3Fhnv5/RGxuN5yLbb/mGzynU+kUI+jLdwrwJg== X-Received: by 2002:a1c:8115:: with SMTP id c21mr17439949wmd.1.1608569306568; Mon, 21 Dec 2020 08:48:26 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id o125sm24581109wmo.30.2020.12.21.08.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 08:48:26 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v5 06/12] media: uvcvideo: Allow entity-defined get_info and get_cur Date: Mon, 21 Dec 2020 17:48:13 +0100 Message-Id: <20201221164819.792019-7-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201221164819.792019-1-ribalda@chromium.org> References: <20201221164819.792019-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Allows controls to get their properties and current value from an entity-defined function instead of via a query to the USB device. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 22 ++++++++++++++++++---- drivers/media/usb/uvc/uvcvideo.h | 5 +++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index d7ccd0fcd88d..528254230535 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -980,10 +980,20 @@ static int __uvc_ctrl_get(struct uvc_video_chain *chain, return -EACCES; if (!ctrl->loaded) { - ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, - chain->dev->intfnum, ctrl->info.selector, + if (ctrl->entity->get_cur) { + ret = ctrl->entity->get_cur(chain->dev, + ctrl->entity, + ctrl->info.selector, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), ctrl->info.size); + } else { + ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, + ctrl->entity->id, + chain->dev->intfnum, + ctrl->info.selector, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), + ctrl->info.size); + } if (ret < 0) return ret; @@ -1716,8 +1726,12 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev, if (data == NULL) return -ENOMEM; - ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, - info->selector, data, 1); + if (ctrl->entity->get_info) + ret = ctrl->entity->get_info(dev, ctrl->entity, + ctrl->info.selector, data); + else + ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, + dev->intfnum, info->selector, data, 1); if (!ret) info->flags |= (data[0] & UVC_CONTROL_CAP_GET ? UVC_CTRL_FLAG_GET_CUR : 0) diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 5d4da54dfd13..6edbf79b2ff1 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -358,6 +358,11 @@ struct uvc_entity { u8 bNrInPins; u8 *baSourceID; + int (*get_info)(struct uvc_device *dev, struct uvc_entity *entity, + u8 cs, u8 *caps); + int (*get_cur)(struct uvc_device *dev, struct uvc_entity *entity, + u8 cs, void *data, u16 size); + unsigned int ncontrols; struct uvc_control *controls; }; From patchwork Mon Dec 21 16:48:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 346513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 513B3C433DB for ; Mon, 21 Dec 2020 18:31:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 020B322D08 for ; Mon, 21 Dec 2020 18:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726697AbgLUSbN (ORCPT ); Mon, 21 Dec 2020 13:31:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgLUSbN (ORCPT ); Mon, 21 Dec 2020 13:31:13 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3018C061793 for ; Mon, 21 Dec 2020 10:30:32 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id 190so10781169wmz.0 for ; Mon, 21 Dec 2020 10:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qPSq8Qf3oa+zDwHMEyCyB9kgDU9ZtwoI+tmmh5RXbH8=; b=HlnjMoT59rU/B9gGWIQ7KZMrB3raq1PufLD3CQG7Ag9LG8pc0bzeCx9BeWI4n5aOzT MyegdMcpsXln4DMElmsRTXDAj727kvyHsfD6qMoruL4BiPqpj9FTMDkFUS1nPvsSR/Hx atALFDOSSa1m4CR1QxF0psYtrdZbAr7jEPfSo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qPSq8Qf3oa+zDwHMEyCyB9kgDU9ZtwoI+tmmh5RXbH8=; b=ghc8mp2lTM1hJyfpzt66U5akEBc1nXlgWb9owWYLinaELWrd7crFJDBaraqaeEakys jXjLMB1HIarqOg/uPurnJ2GHWWHPD7bfbxmD+zbsKUi5y28ZrEhLbHUOXH8U7hWpem4/ z+0tvbJ85FunSlKQxvDdEGq+znF7fCghdzTxurUFJLEm8xVY9RAZwVds5AlPR4GGe9PF chQKsoB7OkiJ2W+4CgNw7UCNvANeCGcyhmcDkmPq2JRnd+mGV/T5umgyQLytHRlI8cfv WNkdv2Iftt49PS3aQbSQwhJSPoSSW6VwSK3Mf3zu9IBGN9GBcLQGEDrG1fKUAjV9+kL4 H7Vw== X-Gm-Message-State: AOAM53335oTulKaKHoRdQRH3xwmrigZhIK1V0gxQW5SFbDr7cy6Riafz K5fA3pQvXAoUItAUjzGxlrNIkTcEEKvVQ1RiB2k= X-Google-Smtp-Source: ABdhPJzwr+Ql4FgZh2mD5Zb+KIel/a8kyCyrrS8u7Yhn3O0hJGqu71Zn8JBJfVPSL3UGIsGS3Gat2A== X-Received: by 2002:a1c:3c09:: with SMTP id j9mr17557080wma.180.1608569308037; Mon, 21 Dec 2020 08:48:28 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id o125sm24581109wmo.30.2020.12.21.08.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 08:48:27 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v5 08/12] media: uvcvideo: Add Privacy control based on EXT_GPIO Date: Mon, 21 Dec 2020 17:48:15 +0100 Message-Id: <20201221164819.792019-9-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201221164819.792019-1-ribalda@chromium.org> References: <20201221164819.792019-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a new control and mapping for Privacy controls connected to UVC_GUID_EXT_GPIO_CONTROLLERs. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index a430fa666897..374822b1ee94 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -347,6 +347,14 @@ static const struct uvc_control_info uvc_ctrls[] = { | UVC_CTRL_FLAG_RESTORE | UVC_CTRL_FLAG_AUTO_UPDATE, }, + { + .entity = UVC_GUID_EXT_GPIO_CONTROLLER, + .selector = UVC_CT_PRIVACY_CONTROL, + .index = 0, + .size = 1, + .flags = UVC_CTRL_FLAG_GET_CUR + | UVC_CTRL_FLAG_AUTO_UPDATE, + }, }; static const struct uvc_menu_info power_line_frequency_controls[] = { @@ -735,6 +743,16 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, }, + { + .id = V4L2_CID_PRIVACY, + .name = "Privacy", + .entity = UVC_GUID_EXT_GPIO_CONTROLLER, + .selector = UVC_CT_PRIVACY_CONTROL, + .size = 1, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, + .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, + }, }; /* ------------------------------------------------------------------------ From patchwork Mon Dec 21 16:48:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 346515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1E09C433E0 for ; Mon, 21 Dec 2020 18:20:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9370E22D08 for ; Mon, 21 Dec 2020 18:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726144AbgLUSUR (ORCPT ); Mon, 21 Dec 2020 13:20:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725898AbgLUSUQ (ORCPT ); Mon, 21 Dec 2020 13:20:16 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34E01C0613D3 for ; Mon, 21 Dec 2020 10:19:36 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id 3so11842421wmg.4 for ; Mon, 21 Dec 2020 10:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dw71v3CL2kM3raQJeeszspBPFX2F58JASjvYTnrWOCM=; b=XOv3mP7zUK4jneYBbu/i4GBH/kEqUFHETXAhDBUJrLmK6HUbonxcaTAu8F6Ohru5UX rAwsaNimKdp05wcbnmOu2XsGfPhqgup77quWUSS7RUvUrIC5KaJoj1wTz3ChGWOBMAyZ nHwzAKxwOKTYmMRmeebWMQueyrhZ3SqPLyluU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dw71v3CL2kM3raQJeeszspBPFX2F58JASjvYTnrWOCM=; b=IaXPbRzRttU8vTZKdTCn35N9PgVHyWUTDW4msUjdTjWnRKk3TXourQAMyatlT96hLk Nl9mYOzyiJK2O9tdzjj/u64Y/vj10kLk20KReIxd5EupwizYbbBW4tjUTw9ntzzyFBI8 O6wWEOYkwCwUAIGuJA/AVF+9QuyCl0zEpyrbHKZ9YHmrpy5TuEqEUbFnKFxZq/ig3RsS EviEWSfv1MijH+VdYvIXE3mHDVWRRtUxsMojIJRXnMUc17illqXHdV01p+IYjomZMBHe lTzqirImYVktULeemm3I+tWxHDGdppRVAoLy/Dfibuckz0b4kME/bDIchetU5lhSYJww x4+A== X-Gm-Message-State: AOAM533axUA0kNDn/TdAY1XqNldii6TLiSvU8VkvAWFzPKsrHbqoFoPp 9zK0CSApGVp2Jf9ZIZM3YQjj2wqHOUBVpkBq5hk= X-Google-Smtp-Source: ABdhPJydw13iQ9B5q81Px8W3R+OZXO2wPlxvontCOvnnKaWO5tOhYWFAenan2mUZOZgLkc6o+nEe5Q== X-Received: by 2002:a1c:7f8c:: with SMTP id a134mr15711577wmd.184.1608569308687; Mon, 21 Dec 2020 08:48:28 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id o125sm24581109wmo.30.2020.12.21.08.48.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 08:48:28 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v5 09/12] media: uvcvideo: Implement UVC_QUIRK_PRIVACY_DURING_STREAM Date: Mon, 21 Dec 2020 17:48:16 +0100 Message-Id: <20201221164819.792019-10-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201221164819.792019-1-ribalda@chromium.org> References: <20201221164819.792019-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Some devices, can only read the privacy_pin if the device is streaming. This patch implement a quirk for such devices, in order to avoid invalid reads and/or spurious events. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 57 ++++++++++++++++++++++++++++-- drivers/media/usb/uvc/uvc_queue.c | 3 ++ drivers/media/usb/uvc/uvcvideo.h | 4 +++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 72516101fdd0..7af37d4bd60a 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1472,6 +1473,17 @@ static int uvc_parse_control(struct uvc_device *dev) /* ----------------------------------------------------------------------------- * Privacy GPIO */ +static bool uvc_gpio_is_streaming(struct uvc_device *dev) +{ + struct uvc_streaming *streaming; + + list_for_each_entry(streaming, &dev->streams, list) { + if (uvc_queue_streaming(&streaming->queue)) + return true; + } + + return false; +} static u8 uvc_gpio_update_value(struct uvc_device *dev, @@ -1499,7 +1511,12 @@ static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity, if (cs != UVC_CT_PRIVACY_CONTROL || size < 1) return -EINVAL; + if ((dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM) && + !uvc_gpio_is_streaming(dev)) + return -EBUSY; + *(uint8_t *)data = uvc_gpio_update_value(dev, entity); + return 0; } @@ -1528,19 +1545,50 @@ static struct uvc_entity *uvc_gpio_find_entity(struct uvc_device *dev) return NULL; } -static irqreturn_t uvc_gpio_irq(int irq, void *data) +void uvc_privacy_gpio_event(struct uvc_device *dev) { - struct uvc_device *dev = data; struct uvc_entity *unit; + unit = uvc_gpio_find_entity(dev); if (!unit) - return IRQ_HANDLED; + return; uvc_gpio_update_value(dev, unit); +} + +static irqreturn_t uvc_gpio_irq(int irq, void *data) +{ + struct uvc_device *dev = data; + + /* Ignore privacy events during streamoff */ + if (dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM) + if (!uvc_gpio_is_streaming(dev)) + return IRQ_HANDLED; + + uvc_privacy_gpio_event(dev); + return IRQ_HANDLED; } +static const struct dmi_system_id privacy_valid_during_streamon[] = { + { + .ident = "HP Elite c1030 Chromebook", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "Jinlon"), + }, + }, + { + .ident = "HP Pro c640 Chromebook", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "Dratini"), + }, + }, + { } /* terminate list */ +}; + static int uvc_gpio_parse(struct uvc_device *dev) { struct uvc_entity *unit; @@ -1577,6 +1625,9 @@ static int uvc_gpio_parse(struct uvc_device *dev) list_add_tail(&unit->list, &dev->entities); + if (dmi_check_system(privacy_valid_during_streamon)) + dev->quirks |= UVC_QUIRK_PRIVACY_DURING_STREAM; + return 0; } diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c index cd60c6c1749e..e800d491303f 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -337,9 +337,12 @@ int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type) { int ret; + struct uvc_streaming *stream = uvc_queue_to_stream(queue); mutex_lock(&queue->mutex); ret = vb2_streamon(&queue->queue, type); + if (stream->dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM) + uvc_privacy_gpio_event(stream->dev); mutex_unlock(&queue->mutex); return ret; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 079a407ebba5..32c1ba246d97 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -209,6 +209,7 @@ #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 #define UVC_QUIRK_FORCE_Y8 0x00000800 #define UVC_QUIRK_FORCE_BPP 0x00001000 +#define UVC_QUIRK_PRIVACY_DURING_STREAM 0x00002000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 @@ -826,6 +827,9 @@ extern const struct v4l2_file_operations uvc_fops; int uvc_mc_register_entities(struct uvc_video_chain *chain); void uvc_mc_cleanup_entity(struct uvc_entity *entity); +/* Privacy gpio */ +void uvc_privacy_gpio_event(struct uvc_device *dev); + /* Video */ int uvc_video_init(struct uvc_streaming *stream); int uvc_video_suspend(struct uvc_streaming *stream); From patchwork Mon Dec 21 16:48:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 346511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14513C433E0 for ; Mon, 21 Dec 2020 18:43:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAD12225AB for ; Mon, 21 Dec 2020 18:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726667AbgLUSmr (ORCPT ); Mon, 21 Dec 2020 13:42:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgLUSmr (ORCPT ); Mon, 21 Dec 2020 13:42:47 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFB8EC0613D3 for ; Mon, 21 Dec 2020 10:42:06 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id q18so12130081wrn.1 for ; Mon, 21 Dec 2020 10:42:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kGMSfbGcTj+LKi7ZSdzKGpSyU9y79v1hTguQdk41qfQ=; b=BQHGNe8DE3o1bfoSrA7Md+be8FlbkvVie3AOAAuQ93+S25vwP/OHjbLZWiAtffAAcC oq2Hfp3lO66iJgX4T705aYSf7oP7Q5etvo819Z3jWoIj2OCwciIZG0CmBcfTbJcuXory HzAlHC3WigV/Oag/fBHPoNSB6gVadndXvoHpM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kGMSfbGcTj+LKi7ZSdzKGpSyU9y79v1hTguQdk41qfQ=; b=g2WbcEzOcXGnXRR7gYdlLka05yiN9N4UjcCj7jl/NHQiXpj0S/bF1YbbtX6Na94Xdn /rwP/hoXO2SktZC+wq/RaEBKuCDV4RwOdXogawglnXkuTtWGOvTF/yBfMZp93QQKIPDz FTKHu+1Z6i6f5L0ELTh+++eN6KWXyZrj0bdlSCHWZoTLh+doD3n1dazAV84oKujN0ZHe o4kuO0x8A/f+I1tu0viS4L43Ok3PBNAJlN1STp1wofTbahgtCL/1JaM1a2D+MH/s4y3j IBDuLgHbRv7eaQ677Y70tpaT0YKz9AOZL4nZMSg+UjQEo6ZmcczNmxAT2Lp0sIUINDMm eimw== X-Gm-Message-State: AOAM533jQrP/269Y4rkmsoDjXk+rI8odvRkVofpPG7RZsttitFc9wTOI 7x5hs27i45jaRJESGWguAbu40whgc5EUQJPdUkI= X-Google-Smtp-Source: ABdhPJy4SQzf+Nr0c20oi720ETjSs3rA00XYO43Pbt5AqvGT6VpLs78qiVYXhAApHsRiQ688XSEAaA== X-Received: by 2002:a05:6000:185:: with SMTP id p5mr19523691wrx.403.1608569309346; Mon, 21 Dec 2020 08:48:29 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id o125sm24581109wmo.30.2020.12.21.08.48.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 08:48:28 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda , Joe Perches Subject: [PATCH v5 10/12] media: uvcvideo: Use dev_ printk aliases Date: Mon, 21 Dec 2020 17:48:17 +0100 Message-Id: <20201221164819.792019-11-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201221164819.792019-1-ribalda@chromium.org> References: <20201221164819.792019-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Replace all the uses of printk() and uvc_printk() with its equivalent dev_ alias macros. Modify uvc_warn_once() macro to use dev_info instead printk(). They are more standard across the kernel tree and provide more context about the error. Reviewed-by: Laurent Pinchart Suggested-by: Joe Perches Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 12 +++---- drivers/media/usb/uvc/uvc_driver.c | 50 ++++++++++++++++-------------- drivers/media/usb/uvc/uvc_entity.c | 10 +++--- drivers/media/usb/uvc/uvc_status.c | 13 ++++---- drivers/media/usb/uvc/uvc_video.c | 48 ++++++++++++++-------------- drivers/media/usb/uvc/uvcvideo.h | 25 +++++++-------- 6 files changed, 81 insertions(+), 77 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 374822b1ee94..1f1323a649fb 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1326,8 +1326,8 @@ static void __uvc_ctrl_status_event_work(struct uvc_device *dev, w->urb->interval = dev->int_ep->desc.bInterval; ret = usb_submit_urb(w->urb, GFP_KERNEL); if (ret < 0) - uvc_printk(KERN_ERR, "Failed to resubmit status URB (%d).\n", - ret); + dev_err(&dev->udev->dev, + "Failed to resubmit status URB (%d).\n", ret); } static void uvc_ctrl_status_event_work(struct work_struct *work) @@ -2038,10 +2038,10 @@ int uvc_ctrl_restore_values(struct uvc_device *dev) if (!ctrl->initialized || !ctrl->modified || (ctrl->info.flags & UVC_CTRL_FLAG_RESTORE) == 0) continue; - - printk(KERN_INFO "restoring control %pUl/%u/%u\n", - ctrl->info.entity, ctrl->info.index, - ctrl->info.selector); + dev_info(&dev->udev->dev, + "restoring control %pUl/%u/%u\n", + ctrl->info.entity, ctrl->info.index, + ctrl->info.selector); ctrl->dirty = 1; } diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 7af37d4bd60a..c98d57680e5c 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -536,8 +536,8 @@ static int uvc_parse_format(struct uvc_device *dev, sizeof(format->name)); format->fcc = fmtdesc->fcc; } else { - uvc_printk(KERN_INFO, "Unknown video format %pUl\n", - &buffer[5]); + dev_info(&streaming->intf->dev, + "Unknown video format %pUl\n", &buffer[5]); snprintf(format->name, sizeof(format->name), "%pUl\n", &buffer[5]); format->fcc = 0; @@ -2137,7 +2137,7 @@ static int uvc_scan_device(struct uvc_device *dev) uvc_scan_fallback(dev); if (list_empty(&dev->chains)) { - uvc_printk(KERN_INFO, "No valid video chain found.\n"); + dev_info(&dev->udev->dev, "No valid video chain found.\n"); return -1; } @@ -2296,8 +2296,9 @@ int uvc_register_video_device(struct uvc_device *dev, ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); if (ret < 0) { - uvc_printk(KERN_ERR, "Failed to register %s device (%d).\n", - v4l2_type_names[type], ret); + dev_err(&stream->intf->dev, + "Failed to register %s device (%d).\n", + v4l2_type_names[type], ret); return ret; } @@ -2313,8 +2314,8 @@ static int uvc_register_video(struct uvc_device *dev, /* Initialize the streaming interface with default parameters. */ ret = uvc_video_init(stream); if (ret < 0) { - uvc_printk(KERN_ERR, "Failed to initialize the device (%d).\n", - ret); + dev_err(&stream->intf->dev, + "Failed to initialize the device (%d).\n", ret); return ret; } @@ -2348,8 +2349,9 @@ static int uvc_register_terms(struct uvc_device *dev, stream = uvc_stream_by_id(dev, term->id); if (stream == NULL) { - uvc_printk(KERN_INFO, "No streaming interface found " - "for terminal %u.", term->id); + dev_info(&dev->udev->dev, + "No streaming interface found for terminal %u.", + term->id); continue; } @@ -2382,8 +2384,8 @@ static int uvc_register_chains(struct uvc_device *dev) #ifdef CONFIG_MEDIA_CONTROLLER ret = uvc_mc_register_entities(chain); if (ret < 0) - uvc_printk(KERN_INFO, - "Failed to register entities (%d).\n", ret); + dev_info(&dev->udev->dev, + "Failed to register entities (%d).\n", ret); #endif } @@ -2486,17 +2488,18 @@ static int uvc_probe(struct usb_interface *intf, goto error; } - uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n", - dev->uvc_version >> 8, dev->uvc_version & 0xff, - udev->product ? udev->product : "", - le16_to_cpu(udev->descriptor.idVendor), - le16_to_cpu(udev->descriptor.idProduct)); + dev_info(&dev->udev->dev, "Found UVC %u.%02x device %s (%04x:%04x)\n", + dev->uvc_version >> 8, dev->uvc_version & 0xff, + udev->product ? udev->product : "", + le16_to_cpu(udev->descriptor.idVendor), + le16_to_cpu(udev->descriptor.idProduct)); if (dev->quirks != dev->info->quirks) { - uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module " - "parameter for testing purpose.\n", dev->quirks); - uvc_printk(KERN_INFO, "Please report required quirks to the " - "linux-uvc-devel mailing list.\n"); + dev_info(&dev->udev->dev, + "Forcing device quirks to 0x%x by module parameter for testing purpose.\n", + dev->quirks); + dev_info(&dev->udev->dev, + "Please report required quirks to the linux-uvc-devel mailing list.\n"); } /* Register the V4L2 device. */ @@ -2525,9 +2528,9 @@ static int uvc_probe(struct usb_interface *intf, /* Initialize the interrupt URB. */ if ((ret = uvc_status_init(dev)) < 0) { - uvc_printk(KERN_INFO, "Unable to initialize the status " - "endpoint (%d), status interrupt will not be " - "supported.\n", ret); + dev_info(&dev->udev->dev, + "Unable to initialize the status endpoint (%d), status interrupt will not be supported.\n", + ret); } ret = uvc_gpio_init_irq(dev); @@ -3233,7 +3236,6 @@ static int __init uvc_init(void) return ret; } - printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n"); return 0; } diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c index 6a9ba5b498db..7c4d2f93d351 100644 --- a/drivers/media/usb/uvc/uvc_entity.c +++ b/drivers/media/usb/uvc/uvc_entity.c @@ -140,8 +140,9 @@ int uvc_mc_register_entities(struct uvc_video_chain *chain) list_for_each_entry(entity, &chain->entities, chain) { ret = uvc_mc_init_entity(chain, entity); if (ret < 0) { - uvc_printk(KERN_INFO, "Failed to initialize entity for " - "entity %u\n", entity->id); + dev_info(&chain->dev->udev->dev, + "Failed to initialize entity for entity %u\n", + entity->id); return ret; } } @@ -149,8 +150,9 @@ int uvc_mc_register_entities(struct uvc_video_chain *chain) list_for_each_entry(entity, &chain->entities, chain) { ret = uvc_mc_create_links(chain, entity); if (ret < 0) { - uvc_printk(KERN_INFO, "Failed to create links for " - "entity %u\n", entity->id); + dev_info(&chain->dev->udev->dev, + "Failed to create links for entity %u\n", + entity->id); return ret; } } diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index 2bdb0ff203f8..36fa196a9258 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -208,8 +208,9 @@ static void uvc_status_complete(struct urb *urb) return; default: - uvc_printk(KERN_WARNING, "Non-zero status (%d) in status " - "completion handler.\n", urb->status); + dev_warn(&dev->udev->dev, + "Non-zero status (%d) in status completion handler.\n", + urb->status); return; } @@ -243,10 +244,10 @@ static void uvc_status_complete(struct urb *urb) /* Resubmit the URB. */ urb->interval = dev->int_ep->desc.bInterval; - if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { - uvc_printk(KERN_ERR, "Failed to resubmit status URB (%d).\n", - ret); - } + ret = usb_submit_urb(urb, GFP_ATOMIC); + if (ret < 0) + dev_err(&dev->udev->dev, + "Failed to resubmit status URB (%d).\n", ret); } int uvc_status_init(struct uvc_device *dev) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index a6a441d92b94..71e643e6d006 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -76,9 +76,9 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, if (likely(ret == size)) return 0; - uvc_printk(KERN_ERR, - "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", - uvc_query_name(query), cs, unit, ret, size); + dev_err(&dev->udev->dev, + "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", + uvc_query_name(query), cs, unit, ret, size); if (ret != -EPIPE) return ret; @@ -254,9 +254,9 @@ static int uvc_get_video_ctrl(struct uvc_streaming *stream, ret = -EIO; goto out; } else if (ret != size) { - uvc_printk(KERN_ERR, "Failed to query (%u) UVC %s control : " - "%d (exp. %u).\n", query, probe ? "probe" : "commit", - ret, size); + dev_err(&stream->intf->dev, + "Failed to query (%u) UVC %s control : %d (exp. %u).\n", + query, probe ? "probe" : "commit", ret, size); ret = -EIO; goto out; } @@ -334,9 +334,9 @@ static int uvc_set_video_ctrl(struct uvc_streaming *stream, probe ? UVC_VS_PROBE_CONTROL : UVC_VS_COMMIT_CONTROL, data, size, uvc_timeout_param); if (ret != size) { - uvc_printk(KERN_ERR, "Failed to set UVC %s control : " - "%d (exp. %u).\n", probe ? "probe" : "commit", - ret, size); + dev_err(&stream->intf->dev, + "Failed to set UVC %s control : %d (exp. %u).\n", + probe ? "probe" : "commit", ret, size); ret = -EIO; } @@ -1120,8 +1120,8 @@ static void uvc_video_copy_data_work(struct work_struct *work) ret = usb_submit_urb(uvc_urb->urb, GFP_KERNEL); if (ret < 0) - uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n", - ret); + dev_err(&uvc_urb->stream->intf->dev, + "Failed to resubmit video URB (%d).\n", ret); } static void uvc_video_decode_data(struct uvc_urb *uvc_urb, @@ -1507,8 +1507,9 @@ static void uvc_video_complete(struct urb *urb) break; default: - uvc_printk(KERN_WARNING, "Non-zero status (%d) in video " - "completion handler.\n", urb->status); + dev_warn(&stream->intf->dev, + "Non-zero status (%d) in video completion handler.\n", + urb->status); fallthrough; case -ENOENT: /* usb_poison_urb() called. */ if (stream->frozen) @@ -1545,9 +1546,8 @@ static void uvc_video_complete(struct urb *urb) if (!uvc_urb->async_operations) { ret = usb_submit_urb(uvc_urb->urb, GFP_ATOMIC); if (ret < 0) - uvc_printk(KERN_ERR, - "Failed to resubmit video URB (%d).\n", - ret); + dev_err(&stream->intf->dev, + "Failed to resubmit video URB (%d).\n", ret); return; } @@ -1893,8 +1893,9 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, for_each_uvc_urb(uvc_urb, stream) { ret = usb_submit_urb(uvc_urb->urb, gfp_flags); if (ret < 0) { - uvc_printk(KERN_ERR, "Failed to submit URB %u (%d).\n", - uvc_urb_index(uvc_urb), ret); + dev_err(&stream->intf->dev, + "Failed to submit URB %u (%d).\n", + uvc_urb_index(uvc_urb), ret); uvc_video_stop_transfer(stream, 1); return ret; } @@ -1989,7 +1990,8 @@ int uvc_video_init(struct uvc_streaming *stream) int ret; if (stream->nformats == 0) { - uvc_printk(KERN_INFO, "No supported video formats found.\n"); + dev_info(&stream->intf->dev, + "No supported video formats found.\n"); return -EINVAL; } @@ -2029,8 +2031,8 @@ int uvc_video_init(struct uvc_streaming *stream) } if (format->nframes == 0) { - uvc_printk(KERN_INFO, "No frame descriptor found for the " - "default format.\n"); + dev_info(&stream->intf->dev, + "No frame descriptor found for the default format.\n"); return -EINVAL; } @@ -2064,8 +2066,8 @@ int uvc_video_init(struct uvc_streaming *stream) if (stream->intf->num_altsetting == 1) stream->decode = uvc_video_encode_bulk; else { - uvc_printk(KERN_INFO, "Isochronous endpoints are not " - "supported for video output devices.\n"); + dev_info(&stream->intf->dev, + "Isochronous endpoints are not supported for video output devices.\n"); return -EINVAL; } } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 32c1ba246d97..a4ebd56bb987 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -757,20 +757,17 @@ extern unsigned int uvc_trace_param; extern unsigned int uvc_timeout_param; extern unsigned int uvc_hw_timestamps_param; -#define uvc_trace(flag, msg...) \ - do { \ - if (uvc_trace_param & flag) \ - printk(KERN_DEBUG "uvcvideo: " msg); \ - } while (0) - -#define uvc_warn_once(dev, warn, msg...) \ - do { \ - if (!test_and_set_bit(warn, &dev->warnings)) \ - printk(KERN_INFO "uvcvideo: " msg); \ - } while (0) - -#define uvc_printk(level, msg...) \ - printk(level "uvcvideo: " msg) +#define uvc_trace(flag, fmt, ...) \ +do { \ + if (uvc_trace_param & flag) \ + printk(KERN_DEBUG "uvcvideo: " fmt, ##__VA_ARGS__); \ +} while (0) + +#define uvc_warn_once(_dev, warn, fmt, ...) \ +do { \ + if (!test_and_set_bit(warn, &(_dev)->warnings)) \ + dev_info(&(_dev)->udev->dev, fmt, ##__VA_ARGS__); \ +} while (0) /* -------------------------------------------------------------------------- * Internal functions.