All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julian Calaby <julian.calaby@gmail.com>
To: "João Paulo Rechi Vita" <jprvita@gmail.com>
Cc: "Johannes Berg" <johannes@sipsolutions.net>,
	"David S. Miller" <davem@davemloft.net>,
	"Darren Hart" <dvhart@infradead.org>,
	linux-wireless <linux-wireless@vger.kernel.org>,
	netdev <netdev@vger.kernel.org>,
	platform-driver-x86@vger.kernel.org, linux-api@vger.kernel.org,
	linux-doc@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux@endlessm.com,
	"João Paulo Rechi Vita" <jprvita@endlessm.com>
Subject: Re: [PATCH 8/9] rfkill: Userspace control for airplane mode
Date: Tue, 9 Feb 2016 09:53:06 +1100	[thread overview]
Message-ID: <CAGRGNgVuwrh5unUoQ0P+ow55ChOQ+qsRRjfD1bb7DC6PcrCO2g@mail.gmail.com> (raw)
In-Reply-To: <1454946096-9752-9-git-send-email-jprvita@endlessm.com>

Hi João,

On Tue, Feb 9, 2016 at 2:41 AM, João Paulo Rechi Vita <jprvita@gmail.com> wrote:
> Provide an interface for the airplane-mode indicator be controlled from
> userspace. User has to first acquire the control through
> RFKILL_OP_AIRPLANE_MODE_ACQUIRE and keep the fd open for the whole time
> it wants to be in control of the indicator. Closing the fd or using
> RFKILL_OP_AIRPLANE_MODE_RELEASE restores the default policy.
>
> To change state of the indicator, the RFKILL_OP_AIRPLANE_MODE_CHANGE
> operation is used, passing the value on "struct rfkill_event.soft". If
> the caller has not acquired the airplane-mode control beforehand, the
> operation fails.
>
> Signed-off-by: João Paulo Rechi Vita <jprvita@endlessm.com>
> ---
>  Documentation/rfkill.txt    | 10 ++++++++++
>  include/uapi/linux/rfkill.h |  3 +++
>  net/rfkill/core.c           | 47 ++++++++++++++++++++++++++++++++++++++++++---
>  3 files changed, 57 insertions(+), 3 deletions(-)
>
> diff --git a/net/rfkill/core.c b/net/rfkill/core.c
> index fb11547..8067701 100644
> --- a/net/rfkill/core.c
> +++ b/net/rfkill/core.c
> @@ -1207,6 +1210,34 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
>
>         mutex_lock(&rfkill_global_mutex);
>
> +       if (ev.op == RFKILL_OP_AIRPLANE_MODE_ACQUIRE) {
> +               if (rfkill_apm_owned && !data->is_apm_owner) {
> +                       count = -EACCES;
> +               } else {
> +                       rfkill_apm_owned = true;
> +                       data->is_apm_owner = true;
> +               }
> +       }
> +
> +       if (ev.op == RFKILL_OP_AIRPLANE_MODE_RELEASE) {
> +               if (rfkill_apm_owned && !data->is_apm_owner) {

Are you sure this is correct?

In the case that airplane mode isn't owned, the
rfkill_apm_led_trigger_event() call will be a noop, so we should
arguably not be calling it.

Also, should we just fail silently if we're not the owner? I.e. what
does userspace learn from this op failing and is that useful?

> +                       count = -EACCES;
> +               } else {
> +                       bool state = rfkill_global_states[RFKILL_TYPE_ALL].cur;
> +
> +                       rfkill_apm_owned = false;
> +                       data->is_apm_owner = false;
> +                       rfkill_apm_led_trigger_event(state);
> +               }
> +       }
> +
> +       if (ev.op == RFKILL_OP_AIRPLANE_MODE_CHANGE) {
> +               if (rfkill_apm_owned && data->is_apm_owner)
> +                       rfkill_apm_led_trigger_event(ev.soft);
> +               else
> +                       count = -EACCES;
> +       }
> +
>         if (ev.op == RFKILL_OP_CHANGE_ALL)
>                 rfkill_update_global_state(ev.type, ev.soft);
>
> @@ -1230,7 +1261,17 @@ static int rfkill_fop_release(struct inode *inode, struct file *file)
>         struct rfkill_int_event *ev, *tmp;
>
>         mutex_lock(&rfkill_global_mutex);
> +
> +       if (data->is_apm_owner) {
> +               bool state = rfkill_global_states[RFKILL_TYPE_ALL].cur;
> +
> +               rfkill_apm_owned = false;
> +               data->is_apm_owner = false;
> +               rfkill_apm_led_trigger_event(state);

Also, this code is duplicated from the _RELEASE op above. Would it
make sense to factor it out into a separate function?

> +       }
> +
>         list_del(&data->list);
> +

(extra line)

>         mutex_unlock(&rfkill_global_mutex);
>
>         mutex_destroy(&data->mtx);

Thanks,

-- 
Julian Calaby

Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/

  parent reply	other threads:[~2016-02-08 22:53 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-08 15:41 [PATCH 0/9] RFKill airplane-mode indicator João Paulo Rechi Vita
2016-02-08 15:41 ` [PATCH 1/9] rfkill: Improve documentation language João Paulo Rechi Vita
2016-02-08 22:37   ` Julian Calaby
2016-02-08 22:37     ` Julian Calaby
2016-02-08 15:41 ` [PATCH 2/9] rfkill: Remove extra blank line João Paulo Rechi Vita
2016-02-08 22:38   ` Julian Calaby
2016-02-08 15:41 ` [PATCH 3/9] rfkill: Point to the correct deprecated doc location João Paulo Rechi Vita
2016-02-08 22:39   ` Julian Calaby
2016-02-08 15:41 ` [PATCH 4/9] rfkill: Move "state" sysfs file back to stable João Paulo Rechi Vita
2016-02-08 15:41 ` [PATCH 5/9] rfkill: Factor rfkill_global_states[].cur assignments João Paulo Rechi Vita
2016-02-08 22:40   ` Julian Calaby
2016-02-08 22:40     ` Julian Calaby
2016-02-08 15:41 ` [PATCH 6/9] rfkill: Add documentation about LED triggers João Paulo Rechi Vita
2016-02-08 15:41 ` [PATCH 7/9] rfkill: Create "rfkill-airplane_mode" LED trigger João Paulo Rechi Vita
2016-02-18 20:08   ` Johannes Berg
2016-02-22 16:10     ` João Paulo Rechi Vita
2016-02-08 15:41 ` [PATCH 8/9] rfkill: Userspace control for airplane mode João Paulo Rechi Vita
2016-02-08 15:41   ` João Paulo Rechi Vita
2016-02-08 16:11   ` Dan Williams
2016-02-08 17:22     ` João Paulo Rechi Vita
2016-02-10 16:07     ` Johannes Berg
2016-02-10 16:07       ` Johannes Berg
2016-02-10 16:53       ` Dan Williams
2016-02-10 17:12         ` Johannes Berg
2016-02-16 15:12           ` João Paulo Rechi Vita
2016-02-08 16:20   ` Marcel Holtmann
2016-02-08 16:20     ` Marcel Holtmann
2016-02-08 17:18     ` Johannes Berg
2016-02-08 17:22     ` João Paulo Rechi Vita
2016-02-08 22:53   ` Julian Calaby [this message]
2016-02-09 21:35     ` João Paulo Rechi Vita
2016-02-09 21:35       ` João Paulo Rechi Vita
2016-02-09 21:36       ` João Paulo Rechi Vita
2016-02-09 22:01         ` Julian Calaby
2016-02-18 20:12   ` Johannes Berg
2016-02-22 16:11     ` João Paulo Rechi Vita
2016-02-08 15:41 ` [PATCH 9/9] rfkill: Notify userspace of airplane-mode state changes João Paulo Rechi Vita

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=CAGRGNgVuwrh5unUoQ0P+ow55ChOQ+qsRRjfD1bb7DC6PcrCO2g@mail.gmail.com \
    --to=julian.calaby@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dvhart@infradead.org \
    --cc=johannes@sipsolutions.net \
    --cc=jprvita@endlessm.com \
    --cc=jprvita@gmail.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@endlessm.com \
    --cc=netdev@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.