From patchwork Sun Dec 17 15:40:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10117745 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 E3C9E60327 for ; Sun, 17 Dec 2017 15:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9F1E292A1 for ; Sun, 17 Dec 2017 15:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEDFB293C0; Sun, 17 Dec 2017 15:41:09 +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 5D976292A1 for ; Sun, 17 Dec 2017 15:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752517AbdLQPlC (ORCPT ); Sun, 17 Dec 2017 10:41:02 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:45200 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752569AbdLQPlA (ORCPT ); Sun, 17 Dec 2017 10:41:00 -0500 Received: by mail-wr0-f193.google.com with SMTP id h1so11890601wre.12 for ; Sun, 17 Dec 2017 07:40:59 -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=nKh1nVXPDsLNioTv04dQ0js4UGxhIZt6Su8u3PCC8Qw=; b=MqzQiN6939RJNToIJDUOSz3woHiJB5z+v3iIfs7omxf7r6Ta7m4h56T/2lmSYnnalO 7f/2CHU2EMlPeSBoVMyFdqNq/hNQQ/0B5wjZKGQXDVYHth9735uYxrtHp/7cp4BC/1Km 4bjpspXA5hzJs8eyFvXw9PUxtwWTRPVEfPieoXTt2V684CqXuqHbZ/6f7pOH/ftkNQaG Hn3qZ/ym47YphA+HhbG/6IAFejasBjHs4adAsTX1eQPZcbYfjSfMPW24cHcv5mImkjo4 3cbWhqApABvoKh3wF/QcNnjENMcAqva9h19dKT36pS9pm1ZS7XcDqBO+8p66g+O+jd+q ug7Q== 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=nKh1nVXPDsLNioTv04dQ0js4UGxhIZt6Su8u3PCC8Qw=; b=Krb3SwEh5Jdd+WJ2hAntC2ZY2ylrndhGSE6C389lHBVC9UarghtSaRqNw+rbsy2Vih jlOQMl9HyTfm/ilLdqzhqbCtyDueoNqvo6idySCNYhhDVEvZYcVIvn+hrrZYkWzs9lP0 mnp/9xDhBw54qZ7hMQbrplrbQ87rQzyvcjhN6u6BrEpf7OnICkDQRDl8i+N+EELJXEmQ 06NRZeHChHeqM1NEakYleuinC5e5lxYg8UahDOvihNZ6+tYVI4F53L2bImcQ1OibX/EJ 3Lv5bKfk+yMWrZrKQwjBfSGRCwLr6XyB9QFxOTy60a13t7pSRgyVnqBBH2NJcTb7pHZ+ NWcg== X-Gm-Message-State: AKGB3mI2ysOrqGnlhtJ8MWZxYCALY6GN7iyR+7oGDxsfmjeiZ9ZjBp+a XODoj8nFwVzvAlqSKGwyJw3QkQ== X-Google-Smtp-Source: ACJfBoshzVVAztW6FAhxZVrQFMAOwjpOGjTgMn6rkqB99YUF0xUEBZ4+sUEBcxV4jC6ug+uZl/gvgg== X-Received: by 10.223.144.204 with SMTP id i70mr15433312wri.57.1513525258441; Sun, 17 Dec 2017 07:40:58 -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 m52sm2420974wrm.12.2017.12.17.07.40.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Dec 2017 07:40:57 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH 5/8] [media] ddbridge: completely tear down input resources on failure Date: Sun, 17 Dec 2017 16:40:46 +0100 Message-Id: <20171217154049.1125-6-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171217154049.1125-1-d.scheller.oss@gmail.com> References: <20171217154049.1125-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 In dvb_input_attach(), whenever a demod driver fails to initialise, or if frontend registration fails, perform a full input/frontend teardown using dvb_input_detach() (which can safely be done since the current init state is tracked in the 'attached' struct member). Claimed resources thus are freed which aren't needed when an input or a port is not functional. While at it, in ddb_ports_detach(), detach the secondary input first. Also increase the kernlog severity of TDA18212 errors and tuner failures in general. Signed-off-by: Daniel Scheller --- drivers/media/pci/ddbridge/ddbridge-core.c | 46 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index c2f028152388..07f3e37a0fca 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -1032,7 +1032,7 @@ static int tuner_attach_tda18212(struct ddb_input *input, u32 porttype) return 0; err: - dev_notice(dev, "TDA18212 tuner not found. Device is not fully operational.\n"); + dev_err(dev, "TDA18212 tuner not found. Device is not fully operational.\n"); return -ENODEV; } @@ -1425,7 +1425,7 @@ static int dvb_input_attach(struct ddb_input *input) dvb->dmxdev.demux = &dvbdemux->dmx; ret = dvb_dmxdev_init(&dvb->dmxdev, adap); if (ret < 0) - return ret; + goto err_detach; dvb->attached = 0x11; dvb->mem_frontend.source = DMX_MEMORY_FE; @@ -1434,12 +1434,12 @@ static int dvb_input_attach(struct ddb_input *input) dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->hw_frontend); ret = dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, &dvb->hw_frontend); if (ret < 0) - return ret; + goto err_detach; dvb->attached = 0x12; ret = dvb_net_init(adap, &dvb->dvbnet, dvb->dmxdev.demux); if (ret < 0) - return ret; + goto err_detach; dvb->attached = 0x20; dvb->fe = NULL; @@ -1447,47 +1447,47 @@ static int dvb_input_attach(struct ddb_input *input) switch (port->type) { case DDB_TUNER_MXL5XX: if (ddb_fe_attach_mxl5xx(input) < 0) - return -ENODEV; + goto err_detach; break; case DDB_TUNER_DVBS_ST: if (demod_attach_stv0900(input, 0) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_stv6110(input, 0) < 0) goto err_tuner; break; case DDB_TUNER_DVBS_ST_AA: if (demod_attach_stv0900(input, 1) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_stv6110(input, 1) < 0) goto err_tuner; break; case DDB_TUNER_DVBS_STV0910: if (demod_attach_stv0910(input, 0) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_stv6111(input, 0) < 0) goto err_tuner; break; case DDB_TUNER_DVBS_STV0910_PR: if (demod_attach_stv0910(input, 1) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_stv6111(input, 1) < 0) goto err_tuner; break; case DDB_TUNER_DVBS_STV0910_P: if (demod_attach_stv0910(input, 0) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_stv6111(input, 1) < 0) goto err_tuner; break; case DDB_TUNER_DVBCT_TR: if (demod_attach_drxk(input) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_tda18271(input) < 0) goto err_tuner; break; case DDB_TUNER_DVBCT_ST: if (demod_attach_stv0367(input) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_tda18212(input, port->type) < 0) goto err_tuner; break; @@ -1507,7 +1507,7 @@ static int dvb_input_attach(struct ddb_input *input) else par = 1; if (demod_attach_cxd28xx(input, par, osc24) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_tda18212(input, port->type) < 0) goto err_tuner; break; @@ -1518,7 +1518,7 @@ static int dvb_input_attach(struct ddb_input *input) case DDB_TUNER_DVBC2T2_SONY: case DDB_TUNER_ISDBT_SONY: if (demod_attach_cxd28xx(input, 0, osc24) < 0) - return -ENODEV; + goto err_detach; if (tuner_attach_tda18212(input, port->type) < 0) goto err_tuner; break; @@ -1529,11 +1529,13 @@ static int dvb_input_attach(struct ddb_input *input) if (dvb->fe) { if (dvb_register_frontend(adap, dvb->fe) < 0) - return -ENODEV; + goto err_detach; if (dvb->fe2) { - if (dvb_register_frontend(adap, dvb->fe2) < 0) - return -ENODEV; + if (dvb_register_frontend(adap, dvb->fe2) < 0) { + dvb_unregister_frontend(dvb->fe); + goto err_detach; + } dvb->fe2->tuner_priv = dvb->fe->tuner_priv; memcpy(&dvb->fe2->ops.tuner_ops, &dvb->fe->ops.tuner_ops, @@ -1545,12 +1547,18 @@ static int dvb_input_attach(struct ddb_input *input) return 0; err_tuner: - dev_warn(port->dev->dev, "tuner attach failed!\n"); + dev_err(port->dev->dev, "tuner attach failed!\n"); if (dvb->fe2) dvb_frontend_detach(dvb->fe2); if (dvb->fe) dvb_frontend_detach(dvb->fe); +err_detach: + dvb_input_detach(input); + + /* return error from ret if set */ + if (ret < 0) + return ret; return -ENODEV; } @@ -1981,8 +1989,8 @@ void ddb_ports_detach(struct ddb *dev) switch (port->class) { case DDB_PORT_TUNER: - dvb_input_detach(port->input[0]); dvb_input_detach(port->input[1]); + dvb_input_detach(port->input[0]); break; case DDB_PORT_CI: case DDB_PORT_LOOP: