Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2119547ybh; Fri, 24 Jul 2020 05:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJJ/qDZOyIG7uhCJG4CHP44M1ncTrzyF1eFMskJpTeIq1E8GN1UVrQYllZQbEWH0vHGX9x X-Received: by 2002:a17:906:82d2:: with SMTP id a18mr8681945ejy.522.1595592204738; Fri, 24 Jul 2020 05:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595592204; cv=none; d=google.com; s=arc-20160816; b=xqQu1FZnIsvjMzgW77hgpNlRHn6FwGU9hYQyBH7quRN+TUCMUwBP4ZmJ7TCqvT9u9e L+oLkJG20D+OVVLdYxv84fKdA8fizF/pmZtS2m+t22ToCGIwVquTSDXAoLaoJolTkkm0 gv7pkA/Yl1sSTMDBKhaHkgLno1RA6MukaKU2YLjPPt+rUkXeKZZ8qUhE+Ewdp2Na6kuY w63P7T3haTB3+WWt372cRJuyT11GArgQHwGX4XND2xxmmLq4s2UeuGqM0JBR8Gr1fABv f1nArqOwiBTH8kx5T3q3Lk4JX1sfcDSZ3nNbCWPIMqAN+BK5Rk6lEWnXGL1Tluyg6wus dV1w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6aW+OAbXsp3FlPblfOXdNolvlbzdTC0MkCKKEXc8Ieo=; b=CDZIQT0uPdLpnFL/Hzc+1pHOxu4vskcvcEoMFK+ufke/0e9vcMMIZ3TnwXiHV+kJ7S gTGQZMv0Nwjay9+SxcJdLjKi5rCCuSZ97nFuhPqH2mrg47GgMvfVrtBtZMd11c3Rvveo QKyz9EaqZ49XJd0RgklzDXI1q+KCCEInZUKkJke/zjvrvOYNrNJ2ydZp/s1Bk8W8/oAn gKX6uzAcyXXxE/Vso2YkAYG/yA2klOYHV9QZ86td4W1POsWC7jdsdHjWHUuQ+O0hUCby WZ+/EUBfn28uV4rfF9AcGfUhQVK6W/LAq6Y50+zoSoGrEWu5pdju14O9PWb8LQi1zs0g xuiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.s=20150623 header.b=j64VirAV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=iitr.ac.in Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l6si466449ejc.207.2020.07.24.05.03.02; Fri, 24 Jul 2020 05:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.s=20150623 header.b=j64VirAV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=iitr.ac.in Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727969AbgGXMCk (ORCPT + 99 others); Fri, 24 Jul 2020 08:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727859AbgGXMCh (ORCPT ); Fri, 24 Jul 2020 08:02:37 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE5DCC0619E4 for ; Fri, 24 Jul 2020 05:02:36 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id x9so4336058plr.2 for ; Fri, 24 Jul 2020 05:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6aW+OAbXsp3FlPblfOXdNolvlbzdTC0MkCKKEXc8Ieo=; b=j64VirAVnfq9D8gtEAgxq6H8YErCJSqcg/A3pTwm7JCYI1LmLeKkuVNSpCTl+0l0rJ JMHlSzc+ErXAIGNo0oRshO3h+BJA3QNI6YrRZfEkamVXHWQoQ2Fi3W4rhjTNxm4DC1G4 UXROwf2VNkw2L4OncqKi21oEzrNTkCn3wNssPxW+7mbKrxjQgBr5W3Zof68SL1hTsN8y tBsWFLtdgGacbfg6s3W3AXFO2WlaI7S+4gGijgey+w+ZU6U7D4CY8lRo5jEWazoaqOPg Z/9VLDAW1OG3jjzRFW2/EY5SiTw6QCHBgYGggjIWZf9ow6yP97qFMc9T7jJLJHaGhhyW F71Q== 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=6aW+OAbXsp3FlPblfOXdNolvlbzdTC0MkCKKEXc8Ieo=; b=HUshOMTb3vc/2AwpdVWZbz+0YzSzXVBJJd7pPIYUkuShG26oBRh+hqsF8GutVzSxN7 s7svZ5s6P0jNUVju9TSP2GLxUz/YrzjN4Vrqps1few1odkj6Wj34oTt7lEPS2aD/v+Ti 0ki3jcROnqpnpYVbLU5GXSB09XMh4i2BcGySht2FzJ0duyLL/a0E2g1u1D44NNhFUkFD E2pki4B7deKflvJ40OOPPBqxIIjvGdzWHhJ/GPY4iRMNms5tycTDn3cimpuCzjjgbS0f vyT/7RGzlTQ1W1rIP/h2h748LOaR1++Zh5U0VqlBhlTH/9ni+qjiYgz2DZBaQsqFgEVX og+w== X-Gm-Message-State: AOAM530bXkLBidQa1P/8gTKhK8f+owueKclBndLFxDQuDDDihBO5JzoU Lnwa9RZHlmxNrH58d2gZ7pz+lA== X-Received: by 2002:a17:90a:26ac:: with SMTP id m41mr4880104pje.169.1595592156165; Fri, 24 Jul 2020 05:02:36 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.178]) by smtp.gmail.com with ESMTPSA id w9sm5622318pfq.178.2020.07.24.05.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 05:02:35 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Cc: Kaaira Gupta Subject: [PATCH v2 2/3] media: vimc: Serialize vimc_streamer_s_stream() Date: Fri, 24 Jul 2020 17:32:12 +0530 Message-Id: <20200724120213.17119-3-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724120213.17119-1-kgupta@es.iitr.ac.in> References: <20200724120213.17119-1-kgupta@es.iitr.ac.in> 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 Prepare for multiple video streams from the same sensor by serializing vimc_streamer_s_stream(). Multiple streams will allow for multiple concurrent calls to this function that could involve the same subdevices. If that happens the internal state of the involved subdevices could go out of sync as they are being started and stopped at the same time, prevent this by serializing starting and stopping of the vimc streamer. [Kaaira: rebased the patch on current HEAD of media-tree (8f2a4a9d5ff5202d0b3e3a144ebb9b67aabadd29)] Signed-off-by: Niklas Söderlund Signed-off-by: Kaaira Gupta --- .../media/test-drivers/vimc/vimc-streamer.c | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index 451a32c0d034..5cd2f86a146a 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -192,18 +192,23 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, struct vimc_ent_device *ved, int enable) { + static DEFINE_MUTEX(vimc_streamer_lock); int ret; if (!stream || !ved) return -EINVAL; + ret = mutex_lock_interruptible(&vimc_streamer_lock); + if (ret) + return ret; + if (enable) { if (stream->kthread) - return 0; + goto out; ret = vimc_streamer_pipeline_init(stream, ved); if (ret) - return ret; + goto out; stream->kthread = kthread_run(vimc_streamer_thread, stream, "vimc-streamer thread"); @@ -211,14 +216,12 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, if (IS_ERR(stream->kthread)) { ret = PTR_ERR(stream->kthread); dev_err(ved->dev, "kthread_run failed with %d\n", ret); - vimc_streamer_pipeline_terminate(stream); - stream->kthread = NULL; - return ret; + goto out; } } else { if (!stream->kthread) - return 0; + goto out; ret = kthread_stop(stream->kthread); /* @@ -227,13 +230,17 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, * a chance to run. Ignore errors to stop the stream in the * pipeline. */ - if (ret) + if (ret) { dev_dbg(ved->dev, "kthread_stop returned '%d'\n", ret); + goto out; + } stream->kthread = NULL; vimc_streamer_pipeline_terminate(stream); } +out: + mutex_unlock(&vimc_streamer_lock); - return 0; + return ret; } -- 2.17.1