From patchwork Wed Jul 12 23:00:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jasmin J." X-Patchwork-Id: 9837539 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 9C1BA60393 for ; Wed, 12 Jul 2017 23:01:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E03128550 for ; Wed, 12 Jul 2017 23:01:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82DCA28552; Wed, 12 Jul 2017 23:01:52 +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.9 required=2.0 tests=BAYES_00,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 42FF628567 for ; Wed, 12 Jul 2017 23:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750766AbdGLXBq (ORCPT ); Wed, 12 Jul 2017 19:01:46 -0400 Received: from mail.anw.at ([195.234.101.228]:54595 "EHLO mail.anw.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750775AbdGLXBm (ORCPT ); Wed, 12 Jul 2017 19:01:42 -0400 Received: from hoppel.217.196.72.190 (anwhome.anw.at [195.234.103.23]) by mail.anw.at (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id v6CN1axi023278; Thu, 13 Jul 2017 01:01:36 +0200 From: "Jasmin J." To: linux-media@vger.kernel.org Cc: mchehab@s-opensource.com, max.kellermann@gmail.com, rjkm@metzlerbros.de, d.scheller@gmx.net, jasmin@anw.at Subject: [PATCH V2 2/9] [media] dvb-core/dvb_ca_en50221.c: New function dvb_ca_en50221_poll_cam_gone Date: Thu, 13 Jul 2017 01:00:51 +0200 Message-Id: <1499900458-2339-3-git-send-email-jasmin@anw.at> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499900458-2339-1-git-send-email-jasmin@anw.at> References: <1499900458-2339-1-git-send-email-jasmin@anw.at> X-Antivirus: checked in 0.019sec at mail.anw.at ([195.234.102.72]) by smf-clamd v1.2.1 - http://smfs.sf.net/ 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: Jasmin Jessich The CAM poll code for the budget-av is exactly the same on several places. Extracting the code to a new function improves maintainability. Signed-off-by: Jasmin Jessich --- drivers/media/dvb-core/dvb_ca_en50221.c | 63 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c index 19d0e9a..66a58ed 100644 --- a/drivers/media/dvb-core/dvb_ca_en50221.c +++ b/drivers/media/dvb-core/dvb_ca_en50221.c @@ -1064,6 +1064,36 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca) } /** + * Poll if the CAM is gone. + * + * @ca: CA instance. + * @slot: Slot to process. + * @return: 0 .. no change + * 1 .. CAM state changed + */ + +static int dvb_ca_en50221_poll_cam_gone(struct dvb_ca_private *ca, int slot) +{ + int changed = 0; + int status; + + /* we need this extra check for annoying interfaces like the + * budget-av + */ + if ((!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) + && (ca->pub->poll_slot_status)) { + status = ca->pub->poll_slot_status(ca->pub, slot, 0); + if (!(status & + DVB_CA_EN50221_POLL_CAM_PRESENT)) { + ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_NONE; + dvb_ca_en50221_thread_update_delay(ca); + changed = 1; + } + } + return changed; +} + +/** * Thread state machine for one CA slot to perform the data transfer. * * @ca: CA instance. @@ -1074,7 +1104,6 @@ static void dvb_ca_en50221_thread_state_machine(struct dvb_ca_private *ca, { struct dvb_ca_slot *sl = &ca->slot_info[slot]; int flags; - int status; int pktcount; void *rxbuf; @@ -1123,20 +1152,8 @@ static void dvb_ca_en50221_thread_state_machine(struct dvb_ca_private *ca, case DVB_CA_SLOTSTATE_VALIDATE: if (dvb_ca_en50221_parse_attributes(ca, slot) != 0) { - /* we need this extra check for annoying interfaces like - * the budget-av - */ - if ((!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) - && (ca->pub->poll_slot_status)) { - status = ca->pub->poll_slot_status(ca->pub, - slot, 0); - if (!(status & - DVB_CA_EN50221_POLL_CAM_PRESENT)) { - sl->slot_state = DVB_CA_SLOTSTATE_NONE; - dvb_ca_en50221_thread_update_delay(ca); - break; - } - } + if (dvb_ca_en50221_poll_cam_gone(ca, slot)) + break; pr_err("dvb_ca adapter %d: Invalid PC card inserted :(\n", ca->dvbdev->adapter->num); @@ -1185,20 +1202,8 @@ static void dvb_ca_en50221_thread_state_machine(struct dvb_ca_private *ca, case DVB_CA_SLOTSTATE_LINKINIT: if (dvb_ca_en50221_link_init(ca, slot) != 0) { - /* we need this extra check for annoying interfaces like - * the budget-av - */ - if ((!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) - && (ca->pub->poll_slot_status)) { - status = ca->pub->poll_slot_status(ca->pub, - slot, 0); - if (!(status & - DVB_CA_EN50221_POLL_CAM_PRESENT)) { - sl->slot_state = DVB_CA_SLOTSTATE_NONE; - dvb_ca_en50221_thread_update_delay(ca); - break; - } - } + if (dvb_ca_en50221_poll_cam_gone(ca, slot)) + break; pr_err("dvb_ca adapter %d: DVB CAM link initialisation failed :(\n", ca->dvbdev->adapter->num);