From patchwork Tue Jun 13 08:58:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 104344 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp301524qgd; Tue, 13 Jun 2017 01:59:11 -0700 (PDT) X-Received: by 10.98.211.89 with SMTP id q86mr25954267pfg.126.1497344351246; Tue, 13 Jun 2017 01:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497344351; cv=none; d=google.com; s=arc-20160816; b=ORNMFIJJ4NzSg9OeF0NUtFRdSo6OtGP1ucVTSv1fAEpfRZCz/qSLg7j93ilv/2OQhO EE4YxHnDbv9feoYSN+zKYJMn+tFf40MdvRaS7H/DuW6xF7LqcaXmFCT1JtzvjcW7t83d qIbP+VjpJtz/dU/prbmyaRhF6qO3Qtk9N1hAfG4sKkpqzB88nyydCuUd2NnwQrRbeN4F o+oAfxaKQXzNoUJwrcFZda3xSes1K9efG5VF0dUxIqTmVB730M92+sH7uK5ZY1ZY0RhE 066n2Srk2mLw2Bfs6rgkczOLgxD9Hz3I+JKOkCLX86kbb4Xz6dEsyUQRVSYfhlHuh5Yu RWbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=lrLaC4fPkHpmGcJTE0hifYvPjRHSoHktu5nxt3M1QSM=; b=I6DeQkDdFP7FHjcQ5EPAWxG47aYDnL0UOlIKuHq+JYYhr1heRJsJzTJy9BCB4OZhNi RbTAZe530ixGJQvIDM6Vh2rXcGO8tcCC1SAzsCZNKkSQL9Op9z86tkdF1N6G8yINK4rH klHtp5LYBILtysHsT8zhfpP3dnleXiltXD11anlLW2mtDDu2YsQAi3t5ZG2vKeX5caS1 LcUqm5z3FFYJ5uH70+Gmb9JuxDDgzN8LaiNeNv5e2I0Wam0+ZUiAFFOj7tsRGKZgy9Ok PSQm4hUnV5jcGjSuibOk/gArRc7N2l/LQt1cKAv2F8WJivoJpVbpg7/1VyqPxZmNombh lj0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e20si8773508pfl.208.2017.06.13.01.59.10; Tue, 13 Jun 2017 01:59:11 -0700 (PDT) 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=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752382AbdFMI7G (ORCPT + 25 others); Tue, 13 Jun 2017 04:59:06 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:35393 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752254AbdFMI7D (ORCPT ); Tue, 13 Jun 2017 04:59:03 -0400 Received: by mail-pf0-f179.google.com with SMTP id l89so64601858pfi.2 for ; Tue, 13 Jun 2017 01:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lrLaC4fPkHpmGcJTE0hifYvPjRHSoHktu5nxt3M1QSM=; b=I/U9OGr/qqgwoz+aJ9Xn8Lr+QaW3O7Rj91SyXjQce1nS1MmIGNGUtzbEP8woVUk4jB beyBjGBnrN/ZyzhcdNW0x2JA+GRgxEc1AZo2KVBIxyv4KaTlaMhmuxylErNwn9t9qY08 Ei4TeDxsDu+GZ7IN91Ui5jkfEbpO5mx9QdDHs= 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; bh=lrLaC4fPkHpmGcJTE0hifYvPjRHSoHktu5nxt3M1QSM=; b=ESEUGJ/3rhBgw/m8GyMilT0P75jeIFaeOpIjks7iLb3FuX+TX6VxqClqZCjCc5t+mO FP01zEvIJ8en7WFUmBmCAeAk4q76s8zEcPoiA+dM9Ly9H92VBiJaAjqGTkk8LDNCktwN 5C1OnmeMCLTVoa/0L8vxagAyRUwveOLxIODTBr7wYrvME16mhYiSQoyqVUEusOYCgD7N b1OmwNKoRp5egR7H0SGRaTJDQfC0Q5zsxFjHH5Luc/0gi4rPFLesTaKLH/vc/6SHtWFQ VeXibzYmYT76KWJKqBzMIJEiTlDLs6id+f+G/niaapK3fNWeEnrcVwKm4+TUSMUv9R6l zFJQ== X-Gm-Message-State: AODbwcDjF9QEWEn6cd8BZdgVMMfDwqBCHDeRlPtkOTaOjTbSXlr9tVEM t84uVT62dWiFmiP9 X-Received: by 10.99.51.200 with SMTP id z191mr40701214pgz.227.1497344342621; Tue, 13 Jun 2017 01:59:02 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id p89sm24054354pfk.67.2017.06.13.01.58.59 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jun 2017 01:59:02 -0700 (PDT) From: Binoy Jayan To: Binoy Jayan Cc: linux-kernel@vger.kernel.org, Arnd Bergmann , Rajendra , Mark Brown , Mauro Carvalho Chehab , Sakari Ailus , Julia Lawall , "Michael S. Tsirkin" , Cao jin , linux-media@vger.kernel.org Subject: [PATCH v2 2/3] media: ngene: Replace semaphore stream_mutex with mutex Date: Tue, 13 Jun 2017 14:28:49 +0530 Message-Id: <1497344330-13915-3-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497344330-13915-1-git-send-email-binoy.jayan@linaro.org> References: <1497344330-13915-1-git-send-email-binoy.jayan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The semaphore 'stream_mutex' is used as a simple mutex, so it should be written as one. Also moving the mutex_[lock/unlock] to the caller as it is anyway locked at the beginning of the callee thus avoiding repetition. Signed-off-by: Binoy Jayan --- drivers/media/pci/ngene/ngene-core.c | 18 +++++++----------- drivers/media/pci/ngene/ngene.h | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) -- Binoy Jayan diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c index eeb61eb..ea64901 100644 --- a/drivers/media/pci/ngene/ngene-core.c +++ b/drivers/media/pci/ngene/ngene-core.c @@ -560,7 +560,6 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream, u16 BsSPI = ((stream & 1) ? 0x9800 : 0x9700); u16 BsSDO = 0x9B00; - down(&dev->stream_mutex); memset(&com, 0, sizeof(com)); com.cmd.hdr.Opcode = CMD_CONTROL; com.cmd.hdr.Length = sizeof(struct FW_STREAM_CONTROL) - 2; @@ -586,17 +585,13 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream, chan->State = KSSTATE_ACQUIRE; chan->HWState = HWSTATE_STOP; spin_unlock_irq(&chan->state_lock); - if (ngene_command(dev, &com) < 0) { - up(&dev->stream_mutex); + if (ngene_command(dev, &com) < 0) return -1; - } /* clear_buffers(chan); */ flush_buffers(chan); - up(&dev->stream_mutex); return 0; } spin_unlock_irq(&chan->state_lock); - up(&dev->stream_mutex); return 0; } @@ -692,11 +687,9 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream, chan->HWState = HWSTATE_STARTUP; spin_unlock_irq(&chan->state_lock); - if (ngene_command(dev, &com) < 0) { - up(&dev->stream_mutex); + if (ngene_command(dev, &com) < 0) return -1; - } - up(&dev->stream_mutex); + return 0; } @@ -750,8 +743,11 @@ void set_transfer(struct ngene_channel *chan, int state) /* else printk(KERN_INFO DEVICE_NAME ": lock=%08x\n", ngreadl(0x9310)); */ + mutex_lock(&dev->stream_mutex); ret = ngene_command_stream_control(dev, chan->number, control, mode, flags); + mutex_unlock(&dev->stream_mutex); + if (!ret) chan->running = state; else @@ -1347,7 +1343,7 @@ static int ngene_start(struct ngene *dev) init_waitqueue_head(&dev->tx_wq); init_waitqueue_head(&dev->rx_wq); mutex_init(&dev->cmd_mutex); - sema_init(&dev->stream_mutex, 1); + mutex_init(&dev->stream_mutex); sema_init(&dev->pll_mutex, 1); sema_init(&dev->i2c_switch_mutex, 1); spin_lock_init(&dev->cmd_lock); diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h index e600b70..0dd15d6 100644 --- a/drivers/media/pci/ngene/ngene.h +++ b/drivers/media/pci/ngene/ngene.h @@ -763,7 +763,7 @@ struct ngene { wait_queue_head_t cmd_wq; int cmd_done; struct mutex cmd_mutex; - struct semaphore stream_mutex; + struct mutex stream_mutex; struct semaphore pll_mutex; struct semaphore i2c_switch_mutex; int i2c_current_channel;