From patchwork Wed Dec 6 17:59:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10096721 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 7EE6A60210 for ; Wed, 6 Dec 2017 17:59:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75CD528A5A for ; Wed, 6 Dec 2017 17:59:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A9BC28AC5; Wed, 6 Dec 2017 17:59:24 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 029DD28A5A for ; Wed, 6 Dec 2017 17:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752484AbdLFR7W (ORCPT ); Wed, 6 Dec 2017 12:59:22 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:37281 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752468AbdLFR7U (ORCPT ); Wed, 6 Dec 2017 12:59:20 -0500 Received: by mail-wr0-f196.google.com with SMTP id k61so4819303wrc.4 for ; Wed, 06 Dec 2017 09:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=ZMJT0+TDH07C9wGFCXBH2MMOF63EqlWNyjmwyfiEKeo=; b=J07Z7gGdbBTE8shsH9/EUs7b8ToqFYObSOFOIjuzXse9069vmJt/ant3cC9lRzZXg7 6bQdGR8sYyfif05uumP+J7wID0NizZPxyo2V9d1+csJbjVwIR+m8tMnxNu5Udlt3BbMS eAWveRJZgu9TvTKNDmCyrRQYOenaFeOxgO2v8blOsmoDkYlAupq8i40pGk72rzRcukJM 8LBxLhbESn9D1uBFM4XgFj2K5V69btmVE3BqYA3hEEan2871Csx9snbM3BOqp2mos0tw C9luGuxbaW0nHszoh8FQfrQQeK2HhIOmOVCcubjzu0422+5N4/XW5LrIeT8z69OXF48X WuKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ZMJT0+TDH07C9wGFCXBH2MMOF63EqlWNyjmwyfiEKeo=; b=JwAJXQTv77EUuJ7mlOUW/Na6FDAlm+kMndZL+8Tl2OlBG5IGofDj0q8sml4rHu5waV PQWaz5VyAtqf0fjTbmi1kNV90TsKa6NxO8FobdH2JIhMDq/9I5gC0yqaDzJ24f4y/CvC k+j7bzwNEsMh4DGuIdWCBhKAw8p+8ixEB80w6zAItDQTSK0+4kO1Oz8fvjDk37kny6qm R/w9PVFAb6Cb8hxFnVTeEbNtKzmxQ3lc7B/kdjl0H1oGMPSv50kt0WRxJTkdqqgikb4h Ho9yKG0VBIpWEXv3XyBh3cE8ajvA8Irv0X4FWbVFAQSXBVYoxFlyZhreuUh8faSvDZ1r tj3g== X-Gm-Message-State: AJaThX6Abor5Rygu/KDf2cZQe4BOkkcvzG4AGT6pK+ZOu3ie0PrdVS4E cMm5hnPeSmuEP5sEoxHt9dpslg== X-Google-Smtp-Source: AGs4zMbTJWmbq6iLh5I+0kLWdXeU8EgAyygdbJjmm6gk5T9xcqsdFpJW1/AdGqHWFaH6gmpNPxM2bw== X-Received: by 10.223.156.202 with SMTP id h10mr17954469wre.174.1512583158767; Wed, 06 Dec 2017 09:59:18 -0800 (PST) Received: from dvbdev.wuest.de (ip-84-118-193-200.unity-media.net. [84.118.193.200]) by smtp.gmail.com with ESMTPSA id q16sm2958538wre.46.2017.12.06.09.59.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Dec 2017 09:59:18 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH 1/2] [media] ddbridge: improve error handling logic on fe attach failures Date: Wed, 6 Dec 2017 18:59:14 +0100 Message-Id: <20171206175915.20669-2-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171206175915.20669-1-d.scheller.oss@gmail.com> References: <20171206175915.20669-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 This change makes sure that demod frontends are always detached whenever a tuner frontend attach failed. Achieve this by moving the detach-on- failure logic at the end of dvb_input_attach(), and adding a goto to this block on every tuner attach failure case, so if an error occurs, there are no stray attached frontends left. As a side effect, this removes some duplicated code. Signed-off-by: Daniel Scheller --- drivers/media/pci/ddbridge/ddbridge-core.c | 49 ++++++++++++++---------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index 348cc8b3d1f9..11c5cae92408 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -1449,48 +1449,43 @@ static int dvb_input_attach(struct ddb_input *input) if (demod_attach_stv0900(input, 0) < 0) return -ENODEV; if (tuner_attach_stv6110(input, 0) < 0) - return -ENODEV; + goto err_tuner; break; case DDB_TUNER_DVBS_ST_AA: if (demod_attach_stv0900(input, 1) < 0) return -ENODEV; if (tuner_attach_stv6110(input, 1) < 0) - return -ENODEV; + goto err_tuner; break; case DDB_TUNER_DVBS_STV0910: if (demod_attach_stv0910(input, 0) < 0) return -ENODEV; if (tuner_attach_stv6111(input, 0) < 0) - return -ENODEV; + goto err_tuner; break; case DDB_TUNER_DVBS_STV0910_PR: if (demod_attach_stv0910(input, 1) < 0) return -ENODEV; if (tuner_attach_stv6111(input, 1) < 0) - return -ENODEV; + goto err_tuner; break; case DDB_TUNER_DVBS_STV0910_P: if (demod_attach_stv0910(input, 0) < 0) return -ENODEV; if (tuner_attach_stv6111(input, 1) < 0) - return -ENODEV; + goto err_tuner; break; case DDB_TUNER_DVBCT_TR: if (demod_attach_drxk(input) < 0) return -ENODEV; if (tuner_attach_tda18271(input) < 0) - return -ENODEV; + goto err_tuner; break; case DDB_TUNER_DVBCT_ST: if (demod_attach_stv0367(input) < 0) return -ENODEV; - if (tuner_attach_tda18212(input, port->type) < 0) { - if (dvb->fe2) - dvb_frontend_detach(dvb->fe2); - if (dvb->fe) - dvb_frontend_detach(dvb->fe); - return -ENODEV; - } + if (tuner_attach_tda18212(input, port->type) < 0) + goto err_tuner; break; case DDB_TUNER_DVBC2T2I_SONY_P: if (input->port->dev->link[input->port->lnr].info->ts_quirks & @@ -1509,13 +1504,8 @@ static int dvb_input_attach(struct ddb_input *input) par = 1; if (demod_attach_cxd28xx(input, par, osc24) < 0) return -ENODEV; - if (tuner_attach_tda18212(input, port->type) < 0) { - if (dvb->fe2) - dvb_frontend_detach(dvb->fe2); - if (dvb->fe) - dvb_frontend_detach(dvb->fe); - return -ENODEV; - } + if (tuner_attach_tda18212(input, port->type) < 0) + goto err_tuner; break; case DDB_TUNER_DVBC2T2I_SONY: osc24 = 1; @@ -1525,13 +1515,8 @@ static int dvb_input_attach(struct ddb_input *input) case DDB_TUNER_ISDBT_SONY: if (demod_attach_cxd28xx(input, 0, osc24) < 0) return -ENODEV; - if (tuner_attach_tda18212(input, port->type) < 0) { - if (dvb->fe2) - dvb_frontend_detach(dvb->fe2); - if (dvb->fe) - dvb_frontend_detach(dvb->fe); - return -ENODEV; - } + if (tuner_attach_tda18212(input, port->type) < 0) + goto err_tuner; break; default: return 0; @@ -1554,6 +1539,16 @@ static int dvb_input_attach(struct ddb_input *input) dvb->attached = 0x31; return 0; + +err_tuner: + dev_warn(port->dev->dev, "tuner attach failed!\n"); + + if (dvb->fe2) + dvb_frontend_detach(dvb->fe2); + if (dvb->fe) + dvb_frontend_detach(dvb->fe); + + return -ENODEV; } static int port_has_encti(struct ddb_port *port)