From: Darren Hart <dvhart@infradead.org>
To: "Pali Rohár" <pali.rohar@gmail.com>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org,
Gabriele Mazzotta <gabriele.mzt@gmail.com>,
Alex Hung <alex.hung@canonical.com>
Subject: Re: [PATCH 2/3] platform: x86: dell-rbtn: Export notifier for other kernel modules
Date: Tue, 25 Nov 2014 14:39:37 -0800 [thread overview]
Message-ID: <20141125223936.GD116670@vmdeb7> (raw)
In-Reply-To: <1416755361-17357-3-git-send-email-pali.rohar@gmail.com>
On Sun, Nov 23, 2014 at 04:09:20PM +0100, Pali Rohár wrote:
> This patch exports notifier functions so other modules can receive HW switch
> events. By default when some module register notifier, dell-rbtn driver
The commit message needs to describe the problem being addressed as well. Why is
this necessary?
> automatically remove rfkill interfaces from system (it is expected that other
> module will use events for other rfkill interface). This behaviour can be
> changed with new module parameter "auto_remove_rfkill".
We try to avoid using such parameters to define behavior when possible.
Why is it justified to use auto_remove_rfkill here? When is it needed? As
opposed to doing something that works based on the detected hardware? (It could
be this is the right thing, but we have to justify it).
>
> This patch is designed for dell-laptop module for receiving those events.
>
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> ---
> drivers/platform/x86/dell-rbtn.c | 87 ++++++++++++++++++++++++++++++++++++--
> drivers/platform/x86/dell-rbtn.h | 35 +++++++++++++++
> 2 files changed, 119 insertions(+), 3 deletions(-)
> create mode 100644 drivers/platform/x86/dell-rbtn.h
>
> diff --git a/drivers/platform/x86/dell-rbtn.c b/drivers/platform/x86/dell-rbtn.c
> index f1f039a..69c17e8 100644
> --- a/drivers/platform/x86/dell-rbtn.c
> +++ b/drivers/platform/x86/dell-rbtn.c
> @@ -128,6 +128,74 @@ static void rbtn_disable(struct acpi_device *device)
> }
>
>
> +/*** notifier export functions ***/
> +
If you want to emphasize a comment, use a block comment. Apply throughout.
/*
* notifier export functions
*/
> +static bool auto_remove_rfkill = true;
> +
> +static ATOMIC_NOTIFIER_HEAD(rbtn_chain_head);
> +
> +static int rbtn_inc_count(struct device *dev, void *data)
> +{
> + int *count = data;
> +
> + (*count)++;
> + return 0;
> +}
> +
> +static int rbtn_switch_dev(struct device *dev, void *data)
> +{
> + struct acpi_device *device = to_acpi_device(dev);
> + bool enable = data;
> +
> + if (enable)
> + rbtn_enable(device);
> + else
> + rbtn_disable(device);
> +
> + return 0;
> +}
> +
> +int dell_rbtn_notifier_register(struct notifier_block *nb)
> +{
> + int ret;
> + bool first;
Descending line length order. Apply throughout where feasible.
bool first;
int ret;
> +
> + ret = 0;
> + driver_for_each_device(&rbtn_driver.drv, NULL, &ret, rbtn_inc_count);
> + if (ret == 0)
> + return -ENODEV;
> +
> + first = !rbtn_chain_head.head;
Maybe it's just late... but "first" what?
> +
> + ret = atomic_notifier_chain_register(&rbtn_chain_head, nb);
> + if (ret != 0)
> + return ret;
> +
> + if (auto_remove_rfkill && first)
> + driver_for_each_device(&rbtn_driver.drv, NULL, (void *)false,
> + rbtn_switch_dev);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(dell_rbtn_notifier_register);
> +
> +int dell_rbtn_notifier_unregister(struct notifier_block *nb)
> +{
> + int ret;
> +
> + ret = atomic_notifier_chain_unregister(&rbtn_chain_head, nb);
> + if (ret != 0)
> + return ret;
> +
> + if (auto_remove_rfkill && !rbtn_chain_head.head)
> + driver_for_each_device(&rbtn_driver.drv, NULL, (void *)true,
> + rbtn_switch_dev);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(dell_rbtn_notifier_unregister);
> +
> +
> /*** acpi driver functions ***/
>
> static int rbtn_add(struct acpi_device *device)
> @@ -138,6 +206,9 @@ static int rbtn_add(struct acpi_device *device)
> if (ret < 0)
> return ret;
>
> + if (auto_remove_rfkill && rbtn_chain_head.head)
> + return 0;
> +
> return rbtn_enable(device);
> }
>
> @@ -151,10 +222,13 @@ static void rbtn_notify(struct acpi_device *device, u32 event)
> {
> struct rfkill *rfkill = device->driver_data;
>
> - if (event == 0x80)
> + if (rfkill && event == 0x80)
> rbtn_query(rfkill, device);
> - else
> +
> + if (!rbtn_chain_head.head && event != 0x80)
> dev_info(&device->dev, "Received unknown event (0x%x)\n", event);
> +
> + atomic_notifier_call_chain(&rbtn_chain_head, event, device);
> }
>
>
> @@ -162,7 +236,9 @@ static void rbtn_notify(struct acpi_device *device, u32 event)
>
> static int __init rbtn_init(void)
> {
> - return acpi_bus_register_driver(&rbtn_driver);
> + /* ignore errors so module always loads and exports needed functions */
> + acpi_bus_register_driver(&rbtn_driver);
> + return 0;
> }
>
> static void __exit rbtn_exit(void)
> @@ -170,9 +246,14 @@ static void __exit rbtn_exit(void)
> acpi_bus_unregister_driver(&rbtn_driver);
> }
>
> +module_param(auto_remove_rfkill, bool, 0444);
> module_init(rbtn_init);
> module_exit(rbtn_exit);
>
> +MODULE_PARM_DESC(auto_remove_rfkill, "automatically remove rfkill devices when "
> + "other module start receiving events from "
another module starts
> + "this module and re-add them when last "
when the last
> + "module stop receving events");
stops
> MODULE_DEVICE_TABLE(acpi, rbtn_ids);
> MODULE_DESCRIPTION("Dell Airplane Mode Switch driver");
> MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
> diff --git a/drivers/platform/x86/dell-rbtn.h b/drivers/platform/x86/dell-rbtn.h
> new file mode 100644
> index 0000000..41ffbc8
> --- /dev/null
> +++ b/drivers/platform/x86/dell-rbtn.h
> @@ -0,0 +1,35 @@
> +/*
> + Dell Airplane Mode Switch driver
> + Copyright (C) 2014 Pali Rohár <pali.rohar@gmail.com>
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 2 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +*/
See Mika's comments on block quote formatting.
> +
> +#ifndef _DELL_RBTN_H_
> +#define _DELL_RBTN_H_
> +
> +struct notifier_block;
> +
> +#if defined(CONFIG_DELL_RBTN) || defined(CONFIG_DELL_RBTN_MODULE)
> +int dell_rbtn_notifier_register(struct notifier_block *nb);
> +int dell_rbtn_notifier_unregister(struct notifier_block *nb);
> +#else
> +static inline int dell_rbtn_notifier_register(struct notifier_block *nb)
> +{
> + return -ENODEV;
> +}
> +static inline int dell_rbtn_notifier_unregister(struct notifier_block *nb)
> +{
> + return -ENODEV;
> +}
> +#endif
> +
> +#endif
> --
> 1.7.9.5
>
>
--
Darren Hart
Intel Open Source Technology Center
next prev parent reply other threads:[~2014-12-02 7:30 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-23 15:09 [PATCH 0/3] Dell Airplane Mode Switch driver Pali Rohár
2014-11-23 15:09 ` [PATCH 1/3] platform: x86: dell-rbtn: " Pali Rohár
2014-11-24 20:09 ` Matthew Garrett
2014-11-24 20:55 ` Pali Rohár
2014-11-24 21:50 ` Matthew Garrett
2014-11-24 22:01 ` Pali Rohár
2014-11-28 11:33 ` Mika Westerberg
2014-11-28 11:45 ` Pali Rohár
2014-11-28 11:54 ` Mika Westerberg
2014-11-25 21:58 ` Darren Hart
2014-11-23 15:09 ` [PATCH 2/3] platform: x86: dell-rbtn: Export notifier for other kernel modules Pali Rohár
2014-11-25 22:39 ` Darren Hart [this message]
2015-04-29 9:55 ` Pali Rohár
2014-11-23 15:09 ` [PATCH 3/3] platform: x86: dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2014-11-25 23:05 ` [PATCH 0/3] Dell Airplane Mode Switch driver Darren Hart
2014-12-02 8:42 ` Pali Rohár
2014-12-04 8:16 ` Alex Hung
2014-12-03 12:56 ` Darren Hart
2014-12-04 9:55 ` Pali Rohár
2014-12-03 13:00 ` Darren Hart
2014-12-05 20:38 ` Pali Rohár
2014-12-05 20:53 ` Gabriele Mazzotta
2014-12-05 21:03 ` Pali Rohár
2014-12-05 21:12 ` Gabriele Mazzotta
2014-12-05 21:23 ` Pali Rohár
2014-12-05 21:49 ` Gabriele Mazzotta
2014-12-22 7:27 ` Alex Hung
2014-12-22 9:21 ` Pali Rohár
2014-12-22 12:35 ` Gabriele Mazzotta
2014-12-22 19:16 ` Gabriele Mazzotta
2014-12-24 9:13 ` Alex Hung
2014-12-24 11:40 ` Gabriele Mazzotta
2014-12-25 3:13 ` Alex Hung
2014-12-25 20:11 ` Pali Rohár
2014-12-25 21:55 ` Gabriele Mazzotta
2014-12-29 7:27 ` Alex Hung
2014-12-29 8:32 ` Pali Rohár
2015-01-05 9:55 ` Alex Hung
2015-04-24 7:39 ` Alex Hung
2015-04-29 9:51 ` [PATCH v2 " Pali Rohár
2015-04-29 9:51 ` [PATCH v2 1/3] platform: x86: dell-rbtn: " Pali Rohár
2015-04-29 10:30 ` Gabriele Mazzotta
2015-04-29 13:08 ` Pali Rohár
2015-04-29 13:57 ` Gabriele Mazzotta
2015-04-29 16:28 ` Pali Rohár
2015-04-29 17:54 ` Gabriele Mazzotta
2015-04-29 18:00 ` Pali Rohár
2015-04-29 18:11 ` Gabriele Mazzotta
2015-04-29 18:16 ` Pali Rohár
2015-04-29 18:41 ` Gabriele Mazzotta
2015-04-29 18:59 ` Pali Rohár
2015-04-30 6:06 ` Alex Hung
2015-04-30 7:44 ` Pali Rohár
2015-05-02 13:51 ` Gabriele Mazzotta
2015-05-02 15:13 ` Pali Rohár
2015-05-05 20:31 ` Darren Hart
2015-05-05 21:23 ` Gabriele Mazzotta
2015-05-06 5:55 ` Darren Hart
2015-05-06 7:49 ` Pali Rohár
2015-05-06 9:34 ` Alex Hung
2015-04-29 9:51 ` [PATCH v2 2/3] platform: x86: dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-04-29 9:51 ` [PATCH v2 3/3] platform: x86: dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-05-03 10:38 ` [PATCH v2 0/3] Dell Airplane Mode Switch driver Pali Rohár
2015-05-05 20:37 ` Darren Hart
2015-05-05 21:24 ` Gabriele Mazzotta
2015-05-06 7:58 ` Pali Rohár
2015-05-06 9:11 ` Alex Hung
2015-05-06 11:31 ` Pali Rohár
2015-05-06 21:57 ` Darren Hart
2015-05-07 2:24 ` Alex Hung
2015-05-13 11:48 ` Pali Rohár
2015-05-13 18:38 ` Darren Hart
2015-05-14 10:54 ` [PATCH v3 " Pali Rohár
2015-05-14 10:54 ` [PATCH v3 1/3] dell-rbtn: " Pali Rohár
2015-05-14 10:54 ` [PATCH v3 2/3] dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-05-22 22:45 ` Dmitry Torokhov
2015-05-23 1:05 ` Pali Rohár
2015-05-24 5:07 ` Valdis.Kletnieks
2015-05-24 11:42 ` Pali Rohár
2015-05-14 10:54 ` [PATCH v3 3/3] dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-05-18 18:07 ` [PATCH v3 0/3] Dell Airplane Mode Switch driver Darren Hart
2015-05-27 21:28 ` [PATCH v4 " Pali Rohár
2015-05-27 21:28 ` [PATCH v4 1/3] dell-rbtn: " Pali Rohár
2015-05-27 21:28 ` [PATCH v4 2/3] dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-05-27 21:28 ` [PATCH v4 3/3] dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-05-28 2:52 ` Darren Hart
2015-06-03 3:55 ` Darren Hart
2015-06-03 8:15 ` Pali Rohár
2015-06-04 5:16 ` Darren Hart
2015-06-06 8:24 ` Pali Rohár
2015-06-06 8:23 ` [PATCH v5 0/3] Dell Airplane Mode Switch driver Pali Rohár
2015-06-06 8:23 ` [PATCH v5 1/3] dell-rbtn: " Pali Rohár
2015-06-06 8:23 ` [PATCH v5 2/3] dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-06-06 8:23 ` [PATCH v5 3/3] dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-06-08 4:12 ` [PATCH v5 0/3] Dell Airplane Mode Switch driver Darren Hart
2015-06-08 7:30 ` Pali Rohár
2015-06-11 4:55 ` Darren Hart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141125223936.GD116670@vmdeb7 \
--to=dvhart@infradead.org \
--cc=alex.hung@canonical.com \
--cc=gabriele.mzt@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjg59@srcf.ucam.org \
--cc=pali.rohar@gmail.com \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).