From patchwork Thu Jul 9 04:06:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 6753011 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F10DD9F38C for ; Thu, 9 Jul 2015 04:07:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 218522060D for ; Thu, 9 Jul 2015 04:07:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B39E120676 for ; Thu, 9 Jul 2015 04:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751449AbbGIEHK (ORCPT ); Thu, 9 Jul 2015 00:07:10 -0400 Received: from mail.kapsi.fi ([217.30.184.167]:36535 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750955AbbGIEG4 (ORCPT ); Thu, 9 Jul 2015 00:06:56 -0400 Received: from 85-23-164-218.bb.dnainternet.fi ([85.23.164.218] helo=localhost.localdomain.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1ZD36t-0002AB-0c; Thu, 09 Jul 2015 07:06:55 +0300 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Antti Palosaari Subject: [PATCH 10/12] tda10071: protect firmware command exec with mutex Date: Thu, 9 Jul 2015 07:06:30 +0300 Message-Id: <1436414792-9716-10-git-send-email-crope@iki.fi> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1436414792-9716-1-git-send-email-crope@iki.fi> References: <1436414792-9716-1-git-send-email-crope@iki.fi> X-SA-Exim-Connect-IP: 85.23.164.218 X-SA-Exim-Mail-From: crope@iki.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There should be clearly some lock in order to make sure firmware command in execution is not disturbed by another command. It has worked as callbacks are serialized somehow pretty well and command execution happens usually without any delays. Signed-off-by: Antti Palosaari --- drivers/media/dvb-frontends/tda10071.c | 12 +++++++++--- drivers/media/dvb-frontends/tda10071_priv.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c index c1507cc..c8feb58 100644 --- a/drivers/media/dvb-frontends/tda10071.c +++ b/drivers/media/dvb-frontends/tda10071.c @@ -62,15 +62,17 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev, goto error; } + mutex_lock(&dev->cmd_execute_mutex); + /* write cmd and args for firmware */ ret = regmap_bulk_write(dev->regmap, 0x00, cmd->args, cmd->len); if (ret) - goto error; + goto error_mutex_unlock; /* start cmd execution */ ret = regmap_write(dev->regmap, 0x1f, 1); if (ret) - goto error; + goto error_mutex_unlock; /* wait cmd execution terminate */ #define CMD_EXECUTE_TIMEOUT 30 @@ -78,8 +80,9 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev, for (uitmp = 1; !time_after(jiffies, timeout) && uitmp;) { ret = regmap_read(dev->regmap, 0x1f, &uitmp); if (ret) - goto error; + goto error_mutex_unlock; } + mutex_unlock(&dev->cmd_execute_mutex); dev_dbg(&client->dev, "cmd execution took %u ms\n", jiffies_to_msecs(jiffies) - @@ -91,6 +94,8 @@ static int tda10071_cmd_execute(struct tda10071_dev *dev, } return ret; +error_mutex_unlock: + mutex_unlock(&dev->cmd_execute_mutex); error: dev_dbg(&client->dev, "failed=%d\n", ret); return ret; @@ -1170,6 +1175,7 @@ static int tda10071_probe(struct i2c_client *client, } dev->client = client; + mutex_init(&dev->cmd_execute_mutex); dev->clk = pdata->clk; dev->i2c_wr_max = pdata->i2c_wr_max; dev->ts_mode = pdata->ts_mode; diff --git a/drivers/media/dvb-frontends/tda10071_priv.h b/drivers/media/dvb-frontends/tda10071_priv.h index 30143c8..cf5b433 100644 --- a/drivers/media/dvb-frontends/tda10071_priv.h +++ b/drivers/media/dvb-frontends/tda10071_priv.h @@ -30,6 +30,7 @@ struct tda10071_dev { struct dvb_frontend fe; struct i2c_client *client; struct regmap *regmap; + struct mutex cmd_execute_mutex; u32 clk; u16 i2c_wr_max; u8 ts_mode;