Message ID | 20221212-uvc-race-v2-2-54496cc3b8ab@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp158277wrn; Tue, 13 Dec 2022 06:38:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf5FdSpnH6nqQrnT7es8VcyfksgIXTDfyU2JD3o7VYKxw1pSFbXSxCXCadYXOqbvB+Oo98fd X-Received: by 2002:a17:90a:d24f:b0:219:251f:d92d with SMTP id o15-20020a17090ad24f00b00219251fd92dmr21069825pjw.9.1670942291298; Tue, 13 Dec 2022 06:38:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670942291; cv=none; d=google.com; s=arc-20160816; b=VK/qMaD8oSi0Scj60ONVdUa+7FR45RB/RH8n3qiGLecAorDUKdgqfU8H7C5XLINtHs 1KtWeuis7Wv6FSt/DvaWwGr4hwCv7qW36UAScQFzDztHLxv1nNk3qhGabL2LH3LuDimz 5/iZZcvLWDcehcsjOqZ+5iHHXJDSHB+kwIgjJy0DTbyr7Wsysg/kmucwgf8OQP+Seuag 6/3olgWVTfZCgn5/e93sprC38AErO0UNkZQXqW1+l4GJvfO+VxoefzAT0WSBG7uhb1SK qxcx0/nf1ddTUgm81NGkmp8R8L3VfR9GtEXiD3bNgp7s+INn3wvikAXt90/hoWpnI+Q8 3ksg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=LoBGLUjEyhQfXWIWPOu9C92qTSNRy93bFCVJA1Gy7YQ=; b=pcA/Avs+i2wno5R07MsDiiHC6h7pu4XDMyTPKuqSnKNFc1EOzi42SbNzC7JEvN/eNf QDQIwaDd3T7fWsNxrno1jltXR+K9qlCCon7dUp+b+4M94+O4kwHnAgGW5Gf9fKQzAHwO UjRiXkuXBp/QdkLSWOzuaJFF9uecOfcWoJX0dX0anPTQdB8F3eG4KT/1PnEa2XwlmBxh 9E3gYW1BVmZQwE7XzMAuQuWRnoo0Defx4Airf9lB5q32bqpSBwLSVTyHwoFrpn3IUYr+ CQmjtCWGeoHeoySwX8C+/GEyMWb4GiC1VWEPpLa6w8B6rescsRp5JZMmfuWl6rHz68qt ++wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A9+F+Qfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s78-20020a632c51000000b00477c0882415si13169645pgs.58.2022.12.13.06.37.57; Tue, 13 Dec 2022 06:38:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A9+F+Qfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235937AbiLMOgU (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Tue, 13 Dec 2022 09:36:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235692AbiLMOgI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 13 Dec 2022 09:36:08 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DFC720BFA for <linux-kernel@vger.kernel.org>; Tue, 13 Dec 2022 06:36:05 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id kw15so36924430ejc.10 for <linux-kernel@vger.kernel.org>; Tue, 13 Dec 2022 06:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LoBGLUjEyhQfXWIWPOu9C92qTSNRy93bFCVJA1Gy7YQ=; b=A9+F+Qfs1V94/OeuF0azEIfhIkJi+LCS+d3Cs11+Nwe+721/Z9kPMq2qwYD6CWLhp7 xjy4l9MDJSxb5AwXA6oXMgl0/A8whNjolgrz2x9VQtDgLXTsT8oDiDcUz6Ca9mq1MNb4 P12dtwtMiMZQBdZz0Ow2u4D0VNu0bWqYtRQcw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LoBGLUjEyhQfXWIWPOu9C92qTSNRy93bFCVJA1Gy7YQ=; b=THmGI8FvkJVIv+/Xz6suF6aO0X5hw3UgC0OSn9yZOQAPqfdj8xX1F/G7YKkVkKEmSe FBYOxDYPfUZrvw75UCVH9LFuPNOkw2QHFwkEX+0wNu3d/s5rsy5dUX3BFZYxc2zz2PKO 0sSCdx52BDaR4VU0O3CKHF32dhO60wospMbWqjHB7UxI2JCAnPfRFuSjunTeMRFvwgcw YfmizbjQc7IYV0OdOPtW5rfaid2/FXmXaaXeYRnK3czB8Juqykb5VBFWTJngBX5VGPQy t7e3ZoacXJa2AN5yHdqyggk6uD8CWvDfDIGT9IHggQJnseS5JKOD2RGWze9pobNsNFJe +uOQ== X-Gm-Message-State: ANoB5pltR2VquBZBRq2ltAbj/vt+7dURghFsJQgcVU69gTMMnLxH3eWf /gpNkv4RmpQn9YAlWk6AK72YHQ== X-Received: by 2002:a17:906:a410:b0:7c0:e5ca:411c with SMTP id l16-20020a170906a41000b007c0e5ca411cmr15851856ejz.17.1670942163897; Tue, 13 Dec 2022 06:36:03 -0800 (PST) Received: from alco.roam.corp.google.com ([100.104.168.209]) by smtp.gmail.com with ESMTPSA id kv17-20020a17090778d100b00781dbdb292asm4613960ejc.155.2022.12.13.06.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 06:36:03 -0800 (PST) From: Ricardo Ribalda <ribalda@chromium.org> Date: Tue, 13 Dec 2022 15:35:31 +0100 Subject: [PATCH v2 2/2] media: uvcvideo: Do not alloc dev->status MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20221212-uvc-race-v2-2-54496cc3b8ab@chromium.org> References: <20221212-uvc-race-v2-0-54496cc3b8ab@chromium.org> In-Reply-To: <20221212-uvc-race-v2-0-54496cc3b8ab@chromium.org> To: Max Staudt <mstaudt@google.com>, Sergey Senozhatsky <senozhatsky@chromium.org>, Yunke Cao <yunkec@chromium.org>, Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Mauro Carvalho Chehab <mchehab@kernel.org> Cc: linux-media@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda <ribalda@chromium.org> X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1689; i=ribalda@chromium.org; h=from:subject:message-id; bh=jEDQuOW3z7ZGcsKin4RTBJvSelqdlHZ1geiYjpdBLTo=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjmI3O4ptcgGHWc6J12tWDekLKnqXOo3j3z7Rmykia fM6ORvGJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY5iNzgAKCRDRN9E+zzrEiFvcEA CRu/tDiApvFvJAFb1Ou/ogsX4eEXmPAA4FtTn3zf36wW/CYBD3IefrmVoFpPkS1vS50bXAbNZO4gEG YBw2ZUKrDBFcwgKx01rQD9CDjIZBWR+yyP7SnKw8TMMcIsvK6nkgUdwotVDWvJC/gBWr3qCdrwo38l LtHT+kfE1PBU027stWfi3t0SzBk620H27apN5mmbcrXN5SKx/g61r/9dwZGRWGJqAAFtJi5ETOmwfD xKePSptFpzgeVQxpGskAZYlD+KyoYzzlcOQMQ+CiCVRckf1GD+iZdpo2wuWSE3E0W/nTsq3Sl0Sj5t c7Ny3sOMd1vkTfGhxl7ftL5y85B14Ilp17tqbpD5s9SqCRcNCyu6Al5Zn2+AKpuXtiZFu5KkLjBCVJ e95B6qrk35kQyrEb73wS9iChL/KNYgrdoVyITF+j5OHxruVFeYa2Wi4H2evV245EDo07y/qL7O3++1 OpC3WHZ0mYJk/rFS8eWfUTMqiBzfha7iTCx3u7r5AZXr/DZ8ngyDkBehsMNY4w51rZ7e05kVp87cKJ EJvUimG4v+ZCaFVF2RrNCsDZtoFbDPD8Q+OnK4TYyDtmipeGdtF0hmUXi6a5xDLxvXaCRDG0/fN/8Q mwxYI/uW9XzF1H5HGCc4EhYdkQf6FgPzX6vtW5Jc7cUCY/QH98gAAektEAFA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752109984017187460?= X-GMAIL-MSGID: =?utf-8?q?1752109984017187460?= |
Series |
uvc: Fix race condition on uvc
|
|
Commit Message
Ricardo Ribalda
Dec. 13, 2022, 2:35 p.m. UTC
UVC_MAX_STATUS_SIZE is 16, simplify the code by inlining dev->status.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/uvc/uvc_status.c | 9 +--------
drivers/media/usb/uvc/uvcvideo.h | 2 +-
2 files changed, 2 insertions(+), 9 deletions(-)
Comments
On (22/12/13 15:35), Ricardo Ribalda wrote: [..] > +++ b/drivers/media/usb/uvc/uvcvideo.h > @@ -559,7 +559,7 @@ struct uvc_device { > /* Status Interrupt Endpoint */ > struct usb_host_endpoint *int_ep; > struct urb *int_urb; > - u8 *status; > + u8 status[UVC_MAX_STATUS_SIZE]; Can we use `struct uvc_control_status status;` instead of open-coding it? Seems that this is what the code wants anyway: struct uvc_control_status *status = (struct uvc_control_status *)dev->status; And then we can drop casts in uvc_status_complete().
Hi Sergey Thanks for the review On Wed, 14 Dec 2022 at 01:40, Sergey Senozhatsky <senozhatsky@chromium.org> wrote: > > On (22/12/13 15:35), Ricardo Ribalda wrote: > [..] > > +++ b/drivers/media/usb/uvc/uvcvideo.h > > @@ -559,7 +559,7 @@ struct uvc_device { > > /* Status Interrupt Endpoint */ > > struct usb_host_endpoint *int_ep; > > struct urb *int_urb; > > - u8 *status; > > + u8 status[UVC_MAX_STATUS_SIZE]; > > Can we use `struct uvc_control_status status;` instead of open-coding it? > Seems that this is what the code wants anyway: It can also be a `struct uvc_streaming_status` https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/media/usb/uvc/uvc_status.c#n230 so we always need the casting :( > > struct uvc_control_status *status = > (struct uvc_control_status *)dev->status; > > And then we can drop casts in uvc_status_complete().
On (22/12/14 06:57), Ricardo Ribalda wrote: > > On (22/12/13 15:35), Ricardo Ribalda wrote: > > [..] > > > +++ b/drivers/media/usb/uvc/uvcvideo.h > > > @@ -559,7 +559,7 @@ struct uvc_device { > > > /* Status Interrupt Endpoint */ > > > struct usb_host_endpoint *int_ep; > > > struct urb *int_urb; > > > - u8 *status; > > > + u8 status[UVC_MAX_STATUS_SIZE]; > > > > Can we use `struct uvc_control_status status;` instead of open-coding it? > > Seems that this is what the code wants anyway: > > It can also be a `struct uvc_streaming_status` > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/media/usb/uvc/uvc_status.c#n230 > > so we always need the casting :( Then perhaps we can put both of them into anon union in struct uvc_device as stream_status and control_status?
diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index 09a5802dc974..52999b3b7c48 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -259,15 +259,9 @@ int uvc_status_init(struct uvc_device *dev) uvc_input_init(dev); - dev->status = kzalloc(UVC_MAX_STATUS_SIZE, GFP_KERNEL); - if (dev->status == NULL) - return -ENOMEM; - dev->int_urb = usb_alloc_urb(0, GFP_KERNEL); - if (dev->int_urb == NULL) { - kfree(dev->status); + if (!dev->int_urb) return -ENOMEM; - } pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress); @@ -296,7 +290,6 @@ void uvc_status_unregister(struct uvc_device *dev) void uvc_status_cleanup(struct uvc_device *dev) { usb_free_urb(dev->int_urb); - kfree(dev->status); } int uvc_status_start(struct uvc_device *dev, gfp_t flags) diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 6a9b72d6789e..ccc7e3b60bf1 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -559,7 +559,7 @@ struct uvc_device { /* Status Interrupt Endpoint */ struct usb_host_endpoint *int_ep; struct urb *int_urb; - u8 *status; + u8 status[UVC_MAX_STATUS_SIZE]; bool flush_status; struct input_dev *input; char input_phys[64];