All of lore.kernel.org
 help / color / mirror / Atom feed
* Resend [PATCH] hidp: Make hidp_get_raw_report abort if the session is terminating
@ 2013-02-18 14:25 Karl and Karen Relton
  0 siblings, 0 replies; 3+ messages in thread
From: Karl and Karen Relton @ 2013-02-18 14:25 UTC (permalink / raw)
  To: linux-bluetooth

From: Karl Relton <karllinuxtest.relton@ntlworld.com>

After linux 3.2 the hid_destroy_device call in hidp_session cleaning up
invokes a hook to the power_supply code which in turn tries to read the
battery capacity. This read will trigger a call to hidp_get_raw_report
which is bound to fail because the device is being taken away - so rather
than wait for the 5 second timeout failure this change enables it to fail
straight away.

Signed-off-by: Karl Relton <karllinuxtest.relton@ntlworld.com>
---
 net/bluetooth/hidp/core.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index b2bcbe2..a4c1bb0 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -311,6 +311,9 @@ static int hidp_get_raw_report(struct hid_device *hid,
 	int numbered_reports = hid->report_enum[report_type].numbered;
 	int ret;
 
+	if (atomic_read(&session->terminate))
+		return -EIO;
+
 	switch (report_type) {
 	case HID_FEATURE_REPORT:
 		report_type = HIDP_TRANS_GET_REPORT | HIDP_DATA_RTYPE_FEATURE;
@@ -695,8 +698,10 @@ static int hidp_session(void *arg)
 	set_current_state(TASK_INTERRUPTIBLE);
 	while (!atomic_read(&session->terminate)) {
 		if (ctrl_sk->sk_state != BT_CONNECTED ||
-				intr_sk->sk_state != BT_CONNECTED)
+				intr_sk->sk_state != BT_CONNECTED) {
+			atomic_inc(&session->terminate);
 			break;
+		}
 
 		while ((skb = skb_dequeue(&intr_sk->sk_receive_queue))) {
 			skb_orphan(skb);
-- 
1.7.9.5



-- 
----------------------------------------------------------------
Karen & Karl Relton                ka_ka@reltons.freeserve.co.uk



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Resend [PATCH] hidp: Make hidp_get_raw_report abort if the session is terminating
  2013-02-18 14:27 Karl Relton
@ 2013-02-20 15:29 ` David Herrmann
  0 siblings, 0 replies; 3+ messages in thread
From: David Herrmann @ 2013-02-20 15:29 UTC (permalink / raw)
  To: Karl Relton; +Cc: linux-bluetooth

Hi Karl

One minor nitpick below:

On Mon, Feb 18, 2013 at 3:27 PM, Karl Relton
<karllinuxtest.relton@ntlworld.com> wrote:
> From: Karl Relton <karllinuxtest.relton@ntlworld.com>
>
> After linux 3.2 the hid_destroy_device call in hidp_session cleaning up
> invokes a hook to the power_supply code which in turn tries to read the
> battery capacity. This read will trigger a call to hidp_get_raw_report
> which is bound to fail because the device is being taken away - so rather
> than wait for the 5 second timeout failure this change enables it to fail
> straight away.
>
> Signed-off-by: Karl Relton <karllinuxtest.relton@ntlworld.com>
> ---
>  net/bluetooth/hidp/core.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
> index b2bcbe2..a4c1bb0 100644
> --- a/net/bluetooth/hidp/core.c
> +++ b/net/bluetooth/hidp/core.c
> @@ -311,6 +311,9 @@ static int hidp_get_raw_report(struct hid_device *hid,
>         int numbered_reports = hid->report_enum[report_type].numbered;
>         int ret;
>
> +       if (atomic_read(&session->terminate))
> +               return -EIO;
> +
>         switch (report_type) {
>         case HID_FEATURE_REPORT:
>                 report_type = HIDP_TRANS_GET_REPORT | HIDP_DATA_RTYPE_FEATURE;
> @@ -695,8 +698,10 @@ static int hidp_session(void *arg)
>         set_current_state(TASK_INTERRUPTIBLE);
>         while (!atomic_read(&session->terminate)) {
>                 if (ctrl_sk->sk_state != BT_CONNECTED ||
> -                               intr_sk->sk_state != BT_CONNECTED)
> +                               intr_sk->sk_state != BT_CONNECTED) {
> +                       atomic_inc(&session->terminate);

Lets move this atomic_inc() directly below the while() loop. This
guarantees that we won't trap into this again if we add other "break;"
conditions.

Other than that the patch looks fine. Feel free to add a:
  Reviewed-by: David Herrmann <dh.herrmann@gmail.com>

Thanks
David

>                         break;
> +               }
>
>                 while ((skb = skb_dequeue(&intr_sk->sk_receive_queue))) {
>                         skb_orphan(skb);
> --
> 1.7.9.5
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Resend [PATCH] hidp: Make hidp_get_raw_report abort if the session is terminating
@ 2013-02-18 14:27 Karl Relton
  2013-02-20 15:29 ` David Herrmann
  0 siblings, 1 reply; 3+ messages in thread
From: Karl Relton @ 2013-02-18 14:27 UTC (permalink / raw)
  To: linux-bluetooth

From: Karl Relton <karllinuxtest.relton@ntlworld.com>

After linux 3.2 the hid_destroy_device call in hidp_session cleaning up
invokes a hook to the power_supply code which in turn tries to read the
battery capacity. This read will trigger a call to hidp_get_raw_report
which is bound to fail because the device is being taken away - so rather
than wait for the 5 second timeout failure this change enables it to fail
straight away.

Signed-off-by: Karl Relton <karllinuxtest.relton@ntlworld.com>
---
 net/bluetooth/hidp/core.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index b2bcbe2..a4c1bb0 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -311,6 +311,9 @@ static int hidp_get_raw_report(struct hid_device *hid,
 	int numbered_reports = hid->report_enum[report_type].numbered;
 	int ret;
 
+	if (atomic_read(&session->terminate))
+		return -EIO;
+
 	switch (report_type) {
 	case HID_FEATURE_REPORT:
 		report_type = HIDP_TRANS_GET_REPORT | HIDP_DATA_RTYPE_FEATURE;
@@ -695,8 +698,10 @@ static int hidp_session(void *arg)
 	set_current_state(TASK_INTERRUPTIBLE);
 	while (!atomic_read(&session->terminate)) {
 		if (ctrl_sk->sk_state != BT_CONNECTED ||
-				intr_sk->sk_state != BT_CONNECTED)
+				intr_sk->sk_state != BT_CONNECTED) {
+			atomic_inc(&session->terminate);
 			break;
+		}
 
 		while ((skb = skb_dequeue(&intr_sk->sk_receive_queue))) {
 			skb_orphan(skb);
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-20 15:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-18 14:25 Resend [PATCH] hidp: Make hidp_get_raw_report abort if the session is terminating Karl and Karen Relton
2013-02-18 14:27 Karl Relton
2013-02-20 15:29 ` David Herrmann

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.