From patchwork Wed Aug 23 16:09:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9917753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF022603FF for ; Wed, 23 Aug 2017 16:10:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1334289C7 for ; Wed, 23 Aug 2017 16:10:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1CAD289DA; Wed, 23 Aug 2017 16:10:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20090289CC for ; Wed, 23 Aug 2017 16:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932134AbdHWQKJ (ORCPT ); Wed, 23 Aug 2017 12:10:09 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34292 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932103AbdHWQKH (ORCPT ); Wed, 23 Aug 2017 12:10:07 -0400 Received: by mail-wm0-f67.google.com with SMTP id r187so615463wma.1 for ; Wed, 23 Aug 2017 09:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YUBvPuSyfmMnHIypnZvYJ8XAxZ/hIb/wpiCZuc26apw=; b=HHyLUfMUOBuRCg/T21xztw0ETCs923x277g/zf5lCj4eH7pVB/OPgJ0U6/+pHr01hc MgIibI1pBCZgIkhPsmAIHgXUO+fC/xCqyGi1Jvea3gvqshrQZUrc+8S82mdCzpBUPAHN ZqkqZ/jOmn1N02ZkexRpL1M0M0OloDo0bZxLbNnq5h/ldWU/8I6dPs0rI3GbMjXZhIJJ x4v0N8Ej+v755Ihj66bR4p8Dxvw3FuUAExaLqp89X/WSa54DpS8oDQmuqWuSCkRRTEiX 6DXCEkGJMyojLjBvVrO/oF7P7kxEup0Iwww3KqIPCeuGgv1n6ywqWa9JkVFY8NEWE1OJ ve4g== 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=YUBvPuSyfmMnHIypnZvYJ8XAxZ/hIb/wpiCZuc26apw=; b=aKax1b7pEGdQOARTqNkDt7Nf+nvCMhu0s8bGy/PtnH/iQIeTPA4Dd/gtNXaD9tMODI KyO9Ee4RqYiSKW6RdvKQIhYDp3qy909z17yPyJ+ySTpWBTE+soaEdV3g/NBykZxs6Ma7 /LdDts8l5CcFOmOFafLAKz+ktu/7efJ7KXjS6CT1/jJn0buW4pKOH9A8JA0L7FWjNM9w OP5F5I3ZuUwz58aCFSVlBcBHqA9KBTajmS6EYTJr5SD8hkX6D0gdpJhEpNSVtY24UQXQ 6TWvEaUlh/gOD1RFnH9Q8mfdX8YkJg+lqIzmkiPfHYBRdZWTQ/dfuq+bDO9kbEmBL9gJ R3tA== X-Gm-Message-State: AHYfb5hQQgkeRPUFHqHha15F39Jx0BWv+FELCqfsUl55bfvsVbBBXoMl K2Ddv56Uvrn2MXxE X-Received: by 10.28.87.194 with SMTP id l185mr2126556wmb.109.1503504606140; Wed, 23 Aug 2017 09:10:06 -0700 (PDT) Received: from dvbdev.wuest.de (ip-84-118-193-88.unity-media.net. [84.118.193.88]) by smtp.gmail.com with ESMTPSA id b13sm2772356wmi.7.2017.08.23.09.10.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Aug 2017 09:10:05 -0700 (PDT) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Cc: jasmin@anw.at, Julia Lawall Subject: [PATCH 1/5] [media] dvb-frontends/stv0910: release lock on gate_ctrl() failure Date: Wed, 23 Aug 2017 18:09:58 +0200 Message-Id: <20170823161002.25459-2-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170823161002.25459-1-d.scheller.oss@gmail.com> References: <20170823161002.25459-1-d.scheller.oss@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Scheller Whenever write_reg() fails to open/close the demod's I2C gate, release the lock to avoid deadlocking situations. If I2c gate open failed, there's no need to hold a lock, and if close fails, the mutex_unlock() at the end of the function is never reached, leaving the mutex_lock in locked state, which in turn will cause potential for deadlocks. Thus, release the lock on failure. While we're touching gate_ctrl(), add some explanation about the need for locking and the shared I2C bus/gate. Cc: Julia Lawall Signed-off-by: Daniel Scheller --- drivers/media/dvb-frontends/stv0910.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/media/dvb-frontends/stv0910.c b/drivers/media/dvb-frontends/stv0910.c index d1ae9553f74c..0d4a6a115159 100644 --- a/drivers/media/dvb-frontends/stv0910.c +++ b/drivers/media/dvb-frontends/stv0910.c @@ -1221,17 +1221,32 @@ static int gate_ctrl(struct dvb_frontend *fe, int enable) struct stv *state = fe->demodulator_priv; u8 i2crpt = state->i2crpt & ~0x86; - if (enable) - mutex_lock(&state->base->i2c_lock); + /* + * mutex_lock note: Concurrent I2C gate bus accesses must be + * prevented (STV0910 = dual demod on a single IC with a single I2C + * gate/bus, and two tuners attached), similar to most (if not all) + * other I2C host interfaces/busses. + * + * enable=1 (open I2C gate) will grab the lock + * enable=0 (close I2C gate) releases the lock + */ - if (enable) + if (enable) { + mutex_lock(&state->base->i2c_lock); i2crpt |= 0x80; - else + } else { i2crpt |= 0x02; + } if (write_reg(state, state->nr ? RSTV0910_P2_I2CRPT : - RSTV0910_P1_I2CRPT, i2crpt) < 0) + RSTV0910_P1_I2CRPT, i2crpt) < 0) { + /* don't hold the I2C bus lock on failure */ + mutex_unlock(&state->base->i2c_lock); + dev_err(&state->base->i2c->dev, + "%s() write_reg failure (enable=%d)\n", + __func__, enable); return -EIO; + } state->i2crpt = i2crpt;