From: Sean Young <sean@mess.org>
To: Srinivas KANDAGATLA <srinivas.kandagatla@st.com>
Cc: linux-media@vger.kernel.org, alipowski@interia.pl,
Mauro Carvalho Chehab <mchehab@redhat.com>,
linux-kernel@vger.kernel.org, srinivas.kandagatla@gmail.com
Subject: Re: [PATCH v1 1/2] media: rc: Add user count to rc dev.
Date: Fri, 19 Jul 2013 12:01:47 +0100 [thread overview]
Message-ID: <20130719110147.GA1104@pequod.mess.org> (raw)
In-Reply-To: <1374223167-4980-1-git-send-email-srinivas.kandagatla@st.com>
On Fri, Jul 19, 2013 at 09:39:27AM +0100, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
>
> This patch adds user count to rc_dev structure, the reason to add this
> new member is to allow other code like lirc to open rc device directly.
> In the existing code, rc device is only opened by input subsystem which
> works ok if we have any input drivers to match. But in case like lirc
> where there will be no input driver, rc device will be never opened.
>
> Having this user count variable will be useful to allow rc device to be
> opened from code other than rc-main.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
> ---
> drivers/media/rc/rc-main.c | 11 +++++++++--
> include/media/rc-core.h | 1 +
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
> index 1cf382a..e800b96 100644
> --- a/drivers/media/rc/rc-main.c
> +++ b/drivers/media/rc/rc-main.c
> @@ -702,15 +702,22 @@ EXPORT_SYMBOL_GPL(rc_keydown_notimeout);
> static int ir_open(struct input_dev *idev)
> {
> struct rc_dev *rdev = input_get_drvdata(idev);
> + int rval = 0;
>
> - return rdev->open(rdev);
> + if (!rdev->users++)
> + rval = rdev->open(rdev);
> +
> + if (rval)
> + rdev->users--;
> +
> + return rval;
This looks racey. Some locking is needed, I think rc_dev->lock should work
fine for this. Here and in the lirc code path too.
Sean
> }
>
> static void ir_close(struct input_dev *idev)
> {
> struct rc_dev *rdev = input_get_drvdata(idev);
>
> - if (rdev)
> + if (rdev && !--rdev->users)
> rdev->close(rdev);
> }
>
> diff --git a/include/media/rc-core.h b/include/media/rc-core.h
> index 06a75de..b42016a 100644
> --- a/include/media/rc-core.h
> +++ b/include/media/rc-core.h
> @@ -101,6 +101,7 @@ struct rc_dev {
> bool idle;
> u64 allowed_protos;
> u64 enabled_protocols;
> + u32 users;
> u32 scanmask;
> void *priv;
> spinlock_t keylock;
> --
> 1.7.6.5
next prev parent reply other threads:[~2013-07-19 11:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-19 8:38 [PATCH v1 0/2] Allow rc device to open from lirc Srinivas KANDAGATLA
2013-07-19 8:39 ` [PATCH v1 1/2] media: rc: Add user count to rc dev Srinivas KANDAGATLA
2013-07-19 11:01 ` Sean Young [this message]
2013-07-19 11:07 ` Srinivas KANDAGATLA
2013-07-19 8:39 ` [PATCH v1 2/2] media: lirc: Allow lirc dev to talk to rc device Srinivas KANDAGATLA
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=20130719110147.GA1104@pequod.mess.org \
--to=sean@mess.org \
--cc=alipowski@interia.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@redhat.com \
--cc=srinivas.kandagatla@gmail.com \
--cc=srinivas.kandagatla@st.com \
/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).