From patchwork Tue Dec 8 19:36:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 7801991 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 305B09F1C2 for ; Tue, 8 Dec 2015 19:36:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5CE602047C for ; Tue, 8 Dec 2015 19:36:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7AF1B20462 for ; Tue, 8 Dec 2015 19:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752194AbbLHTgX (ORCPT ); Tue, 8 Dec 2015 14:36:23 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:34878 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752135AbbLHTgX (ORCPT ); Tue, 8 Dec 2015 14:36:23 -0500 Received: by wmuu63 with SMTP id u63so194204328wmu.0 for ; Tue, 08 Dec 2015 11:36:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=ubOQIn4W3PWxUVQHrCnoMZN4Mm+gtN6uihx7CXcQNdw=; b=T5QVbZvZTgrbWWDE63qKEu3/VOOLDi9fC+NCiqx1nFJBETYi3NOKb1xhRPiKaKWGfl 9BXlunvAdPvjbW9p2BOQou0+clumRPKBuCrv0DixA3ynORxJZH3SRjR5Xq14A8D3I5UU JHwnNWHmc4T7nCyEionQGDuJwJfvbglFbnCie9wp7kIoIS+auz8bwR0XmaIogO/rgl6C Q0KuJirG/MyNIbGR0gAgGqyuFdOk4Ah5jczNAQvrFuVKOW7m8T7P5JHQS6qZsaoCk21Z TIXW1ymlZ7ygxC9cy4Wly+2wbXW3eS4v6/8NiIZC8EU7FaW5EBVOtwSdctXYFGiFJvSu aWZA== X-Received: by 10.28.218.75 with SMTP id r72mr27753606wmg.59.1449603382127; Tue, 08 Dec 2015 11:36:22 -0800 (PST) Received: from ?IPv6:2003:62:5f55:ba00:dd6a:43b0:defe:e97d? (p200300625F55BA00DD6A43B0DEFEE97D.dip0.t-ipconnect.de. [2003:62:5f55:ba00:dd6a:43b0:defe:e97d]) by smtp.googlemail.com with ESMTPSA id gl10sm4288668wjb.30.2015.12.08.11.36.21 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Dec 2015 11:36:21 -0800 (PST) From: Heiner Kallweit Subject: [PATCH v2 2/2] media: rc: improve lirc module detection To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Message-ID: <5667312A.5030809@gmail.com> Date: Tue, 8 Dec 2015 20:36:10 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Improve detection whether lirc codec is loaded and avoid dependency on config symbols and having to check for a specific module. This also fixes the bug that the current check checks for module lirc_dev instead of ir_lirc_codec (which depends on lirc_dev). If the ir_lirc_codec module is unloaded the check would still return OK. Signed-off-by: Heiner Kallweit --- v2: export an accessor instead of the variable --- drivers/media/rc/ir-lirc-codec.c | 4 ++++ drivers/media/rc/rc-main.c | 24 ++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c index a32659f..1f72bef 100644 --- a/drivers/media/rc/ir-lirc-codec.c +++ b/drivers/media/rc/ir-lirc-codec.c @@ -22,6 +22,8 @@ #define LIRCBUF_SIZE 256 +extern void ir_raw_set_lirc_available(bool avail); + /** * ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the * lircd userspace daemon for decoding. @@ -398,6 +400,7 @@ static int ir_lirc_register(struct rc_dev *dev) dev->raw->lirc.drv = drv; dev->raw->lirc.dev = dev; + ir_raw_set_lirc_available(true); return 0; lirc_register_failed: @@ -413,6 +416,7 @@ static int ir_lirc_unregister(struct rc_dev *dev) { struct lirc_codec *lirc = &dev->raw->lirc; + ir_raw_set_lirc_available(false); lirc_unregister_driver(lirc->drv->minor); lirc_buffer_free(lirc->drv->rbuf); kfree(lirc->drv); diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 1042fa3..600e9e9 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -829,22 +829,18 @@ struct rc_filter_attribute { .mask = (_mask), \ } -static bool lirc_is_present(void) +static atomic_t lirc_available = ATOMIC_INIT(0); + +static inline bool lirc_is_present(void) { -#if defined(CONFIG_LIRC_MODULE) - struct module *lirc; - - mutex_lock(&module_mutex); - lirc = find_module("lirc_dev"); - mutex_unlock(&module_mutex); - - return lirc ? true : false; -#elif defined(CONFIG_LIRC) - return true; -#else - return false; -#endif + return atomic_read(&lirc_available) != 0; +} + +void ir_raw_set_lirc_available(bool avail) +{ + atomic_set(&lirc_available, avail); } +EXPORT_SYMBOL(ir_raw_set_lirc_available); /** * show_protocols() - shows the current/wakeup IR protocol(s)