From patchwork Mon Apr 9 16:47:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10331753 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 D93F560236 for ; Mon, 9 Apr 2018 16:48:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8C8B28800 for ; Mon, 9 Apr 2018 16:48:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBF002880B; Mon, 9 Apr 2018 16:48:04 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 4F0EF28800 for ; Mon, 9 Apr 2018 16:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753355AbeDIQsC (ORCPT ); Mon, 9 Apr 2018 12:48:02 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36772 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753328AbeDIQsA (ORCPT ); Mon, 9 Apr 2018 12:48:00 -0400 Received: by mail-wr0-f195.google.com with SMTP id y55so10273215wry.3 for ; Mon, 09 Apr 2018 09:48:00 -0700 (PDT) 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=H7O3JIQZHOd5XF/m0jO2smRjYqcFfWSpFffnnV4sK24=; b=QwqPS9fcYsaBoszojbRCOmyiJDVkwV8nBx3l+6OZNBVxasyQ3g63LpjEcuQELcFQWm WTC5sSPbuK3jU6WMiVZJWfnOsdMTMl+Y3T6Kp8WVFGyo2CeC3B+928LfKC4FHYw2/hlP Ny1Hh9pv299FTebl+2NqHlPIzGt6/alaOg7IWqRPfzCXTv+qdGNeIQataiLSel4Ks/Ux wqnW8r5ijsleEWfsCnkN3v8qpyCIjMdBBcZ5hfRuxxX5+FAYuy/hqdKy56uwQDMK2Oeb yhuejmpLdQL9VZ5AQpVmLW2KliQZhQxFBGQKjVSODo7Gx4jTuK8iQbHyOavye6KhrczP 4pXw== 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=H7O3JIQZHOd5XF/m0jO2smRjYqcFfWSpFffnnV4sK24=; b=qhsix98MORp4Cdt66Xio+cPWTXZHnEdpH3OR2sBJFy9D2Oz9Pgfbn11VnsW3recSI2 LWHvIyh69TTv8JpVehVP2G3LVURmvB1FBDqxL/E3lnGPzVPqv3pG6DuOb1LwSbaetUC0 YhSxmtZvEnd9/NCuodgMtDqFYij/yYGXwCFQol5z5hXvN9/H1RipXiMNoGxn901z/X/d p9QU8Qwkqm76u4DWQoA4hg8IaGWU3JKTjtTYfwTCXL/TuyHkaMcXZBmNySHfnRHGqBjM +9BD7LYeoAxGhCZPh7yFIc8AzMah2MX0cTGDU0SX7CtBp+vVGCOEehfzurdx8WIrg/JQ w3SA== X-Gm-Message-State: AElRT7HZIXlFbR7ec4hXLf2HtflStoivTC/E8MSsS6aWBw4+o5II/xRt aZc0KU8WfOgbueGGhdnOnLsALA== X-Google-Smtp-Source: AIpwx487SnLps7R8LuB2Rlly9wfmMu4w9PmT643w6YKlmWQzyhr63JCSPDM5lI90X/ISgHE268tZZQ== X-Received: by 10.223.163.221 with SMTP id m29mr28921635wrb.4.1523292479132; Mon, 09 Apr 2018 09:47:59 -0700 (PDT) Received: from dvbdev.wuest.de (ip-84-118-193-200.unity-media.net. [84.118.193.200]) by smtp.gmail.com with ESMTPSA id 11sm1380416wmd.1.2018.04.09.09.47.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Apr 2018 09:47:58 -0700 (PDT) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH v2 04/19] [media] ddbridge: move ddb_wq and the wq+class initialisation to -core Date: Mon, 9 Apr 2018 18:47:37 +0200 Message-Id: <20180409164752.641-5-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180409164752.641-1-d.scheller.oss@gmail.com> References: <20180409164752.641-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 Move the ddbridge module initialisation and cleanup code to ddbridge-core and set up the ddb_wq workqueue there, and create and destroy the ddb device class there aswell. Due to this, the prototypes for ddb_wq, ddb_class_create() and ddb_class_destroy() aren't required in ddbridge.h anymore, so remove them. Also, declare ddb_wq and the ddb_class_*() functions static. Picked up from the upstream dddvb-0.9.33 release. Signed-off-by: Daniel Scheller --- drivers/media/pci/ddbridge/ddbridge-core.c | 32 +++++++++++++++++++++++++++--- drivers/media/pci/ddbridge/ddbridge-main.c | 21 +++++++------------- drivers/media/pci/ddbridge/ddbridge.h | 7 ++----- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index 933046d03db5..fb9a2cb758e6 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -100,7 +100,7 @@ MODULE_PARM_DESC(stv0910_single, "use stv0910 cards as single demods"); static DEFINE_MUTEX(redirect_lock); -struct workqueue_struct *ddb_wq; +static struct workqueue_struct *ddb_wq; static struct ddb *ddbs[DDB_MAX_ADAPTER]; @@ -3055,7 +3055,7 @@ static struct class ddb_class = { .devnode = ddb_devnode, }; -int ddb_class_create(void) +static int ddb_class_create(void) { ddb_major = register_chrdev(0, DDB_NAME, &ddb_fops); if (ddb_major < 0) @@ -3065,7 +3065,7 @@ int ddb_class_create(void) return 0; } -void ddb_class_destroy(void) +static void ddb_class_destroy(void) { class_unregister(&ddb_class); unregister_chrdev(ddb_major, DDB_NAME); @@ -3337,3 +3337,29 @@ void ddb_unmap(struct ddb *dev) iounmap(dev->regs); vfree(dev); } + +int ddb_exit_ddbridge(int stage, int error) +{ + switch (stage) { + default: + case 2: + destroy_workqueue(ddb_wq); + /* fall-through */ + case 1: + ddb_class_destroy(); + break; + } + + return error; +} + +int ddb_init_ddbridge(void) +{ + if (ddb_class_create() < 0) + return -1; + ddb_wq = alloc_workqueue("ddbridge", 0, 0); + if (!ddb_wq) + return ddb_exit_ddbridge(1, -1); + + return 0; +} diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c b/drivers/media/pci/ddbridge/ddbridge-main.c index bde04dc39080..7088162af9d3 100644 --- a/drivers/media/pci/ddbridge/ddbridge-main.c +++ b/drivers/media/pci/ddbridge/ddbridge-main.c @@ -282,32 +282,25 @@ static struct pci_driver ddb_pci_driver = { static __init int module_init_ddbridge(void) { - int stat = -1; + int stat; pr_info("Digital Devices PCIE bridge driver " DDBRIDGE_VERSION ", Copyright (C) 2010-17 Digital Devices GmbH\n"); - if (ddb_class_create() < 0) - return -1; - ddb_wq = create_workqueue("ddbridge"); - if (!ddb_wq) - goto exit1; + stat = ddb_init_ddbridge(); + if (stat < 0) + return stat; stat = pci_register_driver(&ddb_pci_driver); if (stat < 0) - goto exit2; - return stat; -exit2: - destroy_workqueue(ddb_wq); -exit1: - ddb_class_destroy(); + ddb_exit_ddbridge(0, stat); + return stat; } static __exit void module_exit_ddbridge(void) { pci_unregister_driver(&ddb_pci_driver); - destroy_workqueue(ddb_wq); - ddb_class_destroy(); + ddb_exit_ddbridge(0, 0); } module_init(module_init_ddbridge); diff --git a/drivers/media/pci/ddbridge/ddbridge.h b/drivers/media/pci/ddbridge/ddbridge.h index e22e67d7e0fe..dbd5f551ce76 100644 --- a/drivers/media/pci/ddbridge/ddbridge.h +++ b/drivers/media/pci/ddbridge/ddbridge.h @@ -368,9 +368,6 @@ int ddbridge_flashread(struct ddb *dev, u32 link, u8 *buf, u32 addr, u32 len); /****************************************************************************/ -/* ddbridge-main.c (modparams) */ -extern struct workqueue_struct *ddb_wq; - /* ddbridge-core.c */ void ddb_ports_detach(struct ddb *dev); void ddb_ports_release(struct ddb *dev); @@ -383,9 +380,9 @@ void ddb_ports_init(struct ddb *dev); int ddb_buffers_alloc(struct ddb *dev); int ddb_ports_attach(struct ddb *dev); int ddb_device_create(struct ddb *dev); -int ddb_class_create(void); -void ddb_class_destroy(void); int ddb_init(struct ddb *dev); void ddb_unmap(struct ddb *dev); +int ddb_exit_ddbridge(int stage, int error); +int ddb_init_ddbridge(void); #endif /* DDBRIDGE_H */