* (no subject)
@ 2011-03-21 13:19 Szymon Janc
2011-03-21 13:19 ` [PATCH 01/10] Bluetooth: Opencode macros in bnep/core.c Szymon Janc
` (9 more replies)
0 siblings, 10 replies; 16+ messages in thread
From: Szymon Janc @ 2011-03-21 13:19 UTC (permalink / raw)
To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc
Subject: [PATCH 00/10] Use kthread API instead of kernel_thread in bluetooth
Use kthread API in bnep, hidp and cmtp.
Why: kernel_thread is a low-level implementation detail. Drivers should
use the <linux/kthread.h> API instead which shields them from
implementation details and provides a higherlevel interface that
prevents bugs and code duplication
Rest of patches are just cleanup work in touched files.
Comments are welcome.
BR,
Szymon Janc
on behalf of ST-Ericsson
Szymon Janc (10):
Bluetooth: Opencode macros in bnep/core.c
Bluetooth: Fix checkpatch errors and some code style issues in bnep
Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h>
Bluetooth: Use kthread API in bnep
Bluetooth: Fix checkpatch errors, code style issues and typos in hidp
Bluetooth: Use kthread API in hidp
Bluetooth: Do not use assignments in IF conditions
Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h>
Bluetooth: Fix checkpatch error in cmtp.h
Bluetooth: Use kthread API in cmtp
net/bluetooth/bnep/bnep.h | 148 ++++++++++++++++++++++----------------------
net/bluetooth/bnep/core.c | 71 +++++++++++----------
net/bluetooth/bnep/sock.c | 2 +-
net/bluetooth/cmtp/capi.c | 6 +-
net/bluetooth/cmtp/cmtp.h | 11 +---
net/bluetooth/cmtp/core.c | 25 +++++---
net/bluetooth/cmtp/sock.c | 2 +-
net/bluetooth/hidp/core.c | 86 +++++++++++++-------------
net/bluetooth/hidp/hidp.h | 6 +-
net/bluetooth/hidp/sock.c | 7 +-
10 files changed, 182 insertions(+), 182 deletions(-)
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH 01/10] Bluetooth: Opencode macros in bnep/core.c 2011-03-21 13:19 Szymon Janc @ 2011-03-21 13:19 ` Szymon Janc 2011-03-21 13:19 ` [PATCH 02/10] Bluetooth: Fix checkpatch errors and some code style issues in bnep Szymon Janc ` (8 subsequent siblings) 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:19 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc BNEP_RX_TYPES and INCA macros have only one user each and don't provide any benefits compared to opencoding them. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/bnep/core.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c index 03d4d12..940b4e1 100644 --- a/net/bluetooth/bnep/core.c +++ b/net/bluetooth/bnep/core.c @@ -187,6 +187,8 @@ static int bnep_ctrl_set_mcfilter(struct bnep_session *s, u8 *data, int len) n /= (ETH_ALEN * 2); if (n > 0) { + int i; + s->mc_filter = 0; /* Always send broadcast */ @@ -202,12 +204,14 @@ static int bnep_ctrl_set_mcfilter(struct bnep_session *s, u8 *data, int len) BT_DBG("mc filter %s -> %s", batostr((void *) a1), batostr((void *) a2)); - #define INCA(a) { int i = 5; while (i >=0 && ++a[i--] == 0); } - /* Iterate from a1 to a2 */ set_bit(bnep_mc_hash(a1), (ulong *) &s->mc_filter); while (memcmp(a1, a2, 6) < 0 && s->mc_filter != ~0LL) { - INCA(a1); + /* Increment a1 */ + i = 5; + while (i >= 0 && ++a1[i--] == 0) + ; + set_bit(bnep_mc_hash(a1), (ulong *) &s->mc_filter); } } @@ -302,7 +306,6 @@ static u8 __bnep_rx_hlen[] = { ETH_ALEN + 2, /* BNEP_COMPRESSED_SRC_ONLY */ ETH_ALEN + 2 /* BNEP_COMPRESSED_DST_ONLY */ }; -#define BNEP_RX_TYPES (sizeof(__bnep_rx_hlen) - 1) static inline int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb) { @@ -314,7 +317,7 @@ static inline int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb) type = *(u8 *) skb->data; skb_pull(skb, 1); - if ((type & BNEP_TYPE_MASK) > BNEP_RX_TYPES) + if ((type & BNEP_TYPE_MASK) >= sizeof(__bnep_rx_hlen)) goto badframe; if ((type & BNEP_TYPE_MASK) == BNEP_CONTROL) { -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 02/10] Bluetooth: Fix checkpatch errors and some code style issues in bnep 2011-03-21 13:19 Szymon Janc 2011-03-21 13:19 ` [PATCH 01/10] Bluetooth: Opencode macros in bnep/core.c Szymon Janc @ 2011-03-21 13:19 ` Szymon Janc 2011-03-21 13:19 ` [PATCH 03/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> Szymon Janc ` (7 subsequent siblings) 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:19 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/bnep/bnep.h | 146 ++++++++++++++++++++++---------------------- net/bluetooth/bnep/core.c | 37 +++++++----- 2 files changed, 94 insertions(+), 89 deletions(-) diff --git a/net/bluetooth/bnep/bnep.h b/net/bluetooth/bnep/bnep.h index 7067254..d768e04 100644 --- a/net/bluetooth/bnep/bnep.h +++ b/net/bluetooth/bnep/bnep.h @@ -23,88 +23,88 @@ #include <linux/crc32.h> #include <net/bluetooth/bluetooth.h> -// Limits -#define BNEP_MAX_PROTO_FILTERS 5 -#define BNEP_MAX_MULTICAST_FILTERS 20 - -// UUIDs -#define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB -#define BNEP_UUID16 0x02 -#define BNEP_UUID32 0x04 -#define BNEP_UUID128 0x16 - -#define BNEP_SVC_PANU 0x1115 -#define BNEP_SVC_NAP 0x1116 -#define BNEP_SVC_GN 0x1117 - -// Packet types -#define BNEP_GENERAL 0x00 -#define BNEP_CONTROL 0x01 -#define BNEP_COMPRESSED 0x02 -#define BNEP_COMPRESSED_SRC_ONLY 0x03 -#define BNEP_COMPRESSED_DST_ONLY 0x04 - -// Control types -#define BNEP_CMD_NOT_UNDERSTOOD 0x00 -#define BNEP_SETUP_CONN_REQ 0x01 -#define BNEP_SETUP_CONN_RSP 0x02 -#define BNEP_FILTER_NET_TYPE_SET 0x03 -#define BNEP_FILTER_NET_TYPE_RSP 0x04 -#define BNEP_FILTER_MULTI_ADDR_SET 0x05 -#define BNEP_FILTER_MULTI_ADDR_RSP 0x06 - -// Extension types -#define BNEP_EXT_CONTROL 0x00 - -// Response messages -#define BNEP_SUCCESS 0x00 - -#define BNEP_CONN_INVALID_DST 0x01 -#define BNEP_CONN_INVALID_SRC 0x02 -#define BNEP_CONN_INVALID_SVC 0x03 -#define BNEP_CONN_NOT_ALLOWED 0x04 - -#define BNEP_FILTER_UNSUPPORTED_REQ 0x01 -#define BNEP_FILTER_INVALID_RANGE 0x02 -#define BNEP_FILTER_INVALID_MCADDR 0x02 -#define BNEP_FILTER_LIMIT_REACHED 0x03 -#define BNEP_FILTER_DENIED_SECURITY 0x04 - -// L2CAP settings -#define BNEP_MTU 1691 -#define BNEP_PSM 0x0f -#define BNEP_FLUSH_TO 0xffff -#define BNEP_CONNECT_TO 15 -#define BNEP_FILTER_TO 15 - -// Headers -#define BNEP_TYPE_MASK 0x7f -#define BNEP_EXT_HEADER 0x80 +/* Limits */ +#define BNEP_MAX_PROTO_FILTERS 5 +#define BNEP_MAX_MULTICAST_FILTERS 20 + +/* UUIDs */ +#define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB +#define BNEP_UUID16 0x02 +#define BNEP_UUID32 0x04 +#define BNEP_UUID128 0x16 + +#define BNEP_SVC_PANU 0x1115 +#define BNEP_SVC_NAP 0x1116 +#define BNEP_SVC_GN 0x1117 + +/* Packet types */ +#define BNEP_GENERAL 0x00 +#define BNEP_CONTROL 0x01 +#define BNEP_COMPRESSED 0x02 +#define BNEP_COMPRESSED_SRC_ONLY 0x03 +#define BNEP_COMPRESSED_DST_ONLY 0x04 + +/* Control types */ +#define BNEP_CMD_NOT_UNDERSTOOD 0x00 +#define BNEP_SETUP_CONN_REQ 0x01 +#define BNEP_SETUP_CONN_RSP 0x02 +#define BNEP_FILTER_NET_TYPE_SET 0x03 +#define BNEP_FILTER_NET_TYPE_RSP 0x04 +#define BNEP_FILTER_MULTI_ADDR_SET 0x05 +#define BNEP_FILTER_MULTI_ADDR_RSP 0x06 + +/* Extension types */ +#define BNEP_EXT_CONTROL 0x00 + +/* Response messages */ +#define BNEP_SUCCESS 0x00 + +#define BNEP_CONN_INVALID_DST 0x01 +#define BNEP_CONN_INVALID_SRC 0x02 +#define BNEP_CONN_INVALID_SVC 0x03 +#define BNEP_CONN_NOT_ALLOWED 0x04 + +#define BNEP_FILTER_UNSUPPORTED_REQ 0x01 +#define BNEP_FILTER_INVALID_RANGE 0x02 +#define BNEP_FILTER_INVALID_MCADDR 0x02 +#define BNEP_FILTER_LIMIT_REACHED 0x03 +#define BNEP_FILTER_DENIED_SECURITY 0x04 + +/* L2CAP settings */ +#define BNEP_MTU 1691 +#define BNEP_PSM 0x0f +#define BNEP_FLUSH_TO 0xffff +#define BNEP_CONNECT_TO 15 +#define BNEP_FILTER_TO 15 + +/* Headers */ +#define BNEP_TYPE_MASK 0x7f +#define BNEP_EXT_HEADER 0x80 struct bnep_setup_conn_req { - __u8 type; - __u8 ctrl; - __u8 uuid_size; - __u8 service[0]; + __u8 type; + __u8 ctrl; + __u8 uuid_size; + __u8 service[0]; } __packed; struct bnep_set_filter_req { - __u8 type; - __u8 ctrl; + __u8 type; + __u8 ctrl; __be16 len; - __u8 list[0]; + __u8 list[0]; } __packed; struct bnep_control_rsp { - __u8 type; - __u8 ctrl; + __u8 type; + __u8 ctrl; __be16 resp; } __packed; struct bnep_ext_hdr { - __u8 type; - __u8 len; - __u8 data[0]; + __u8 type; + __u8 len; + __u8 data[0]; } __packed; /* BNEP ioctl defines */ @@ -114,10 +114,10 @@ struct bnep_ext_hdr { #define BNEPGETCONNINFO _IOR('B', 211, int) struct bnep_connadd_req { - int sock; // Connected socket + int sock; /* Connected socket */ __u32 flags; __u16 role; - char device[16]; // Name of the Ethernet device + char device[16]; /* Name of the Ethernet device */ }; struct bnep_conndel_req { @@ -148,7 +148,7 @@ int bnep_del_connection(struct bnep_conndel_req *req); int bnep_get_connlist(struct bnep_connlist_req *req); int bnep_get_conninfo(struct bnep_conninfo *ci); -// BNEP sessions +/* BNEP sessions */ struct bnep_session { struct list_head list; @@ -173,7 +173,7 @@ void bnep_sock_cleanup(void); static inline int bnep_mc_hash(__u8 *addr) { - return (crc32_be(~0, addr, ETH_ALEN) >> 26); + return crc32_be(~0, addr, ETH_ALEN) >> 26; } #endif diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c index 940b4e1..0a2e76b 100644 --- a/net/bluetooth/bnep/core.c +++ b/net/bluetooth/bnep/core.c @@ -131,7 +131,8 @@ static int bnep_ctrl_set_netfilter(struct bnep_session *s, __be16 *data, int len return -EILSEQ; n = get_unaligned_be16(data); - data++; len -= 2; + data++; + len -= 2; if (len < n) return -EILSEQ; @@ -176,7 +177,8 @@ static int bnep_ctrl_set_mcfilter(struct bnep_session *s, u8 *data, int len) return -EILSEQ; n = get_unaligned_be16(data); - data += 2; len -= 2; + data += 2; + len -= 2; if (len < n) return -EILSEQ; @@ -198,8 +200,10 @@ static int bnep_ctrl_set_mcfilter(struct bnep_session *s, u8 *data, int len) for (; n > 0; n--) { u8 a1[6], *a2; - memcpy(a1, data, ETH_ALEN); data += ETH_ALEN; - a2 = data; data += ETH_ALEN; + memcpy(a1, data, ETH_ALEN); + data += ETH_ALEN; + a2 = data; + data += ETH_ALEN; BT_DBG("mc filter %s -> %s", batostr((void *) a1), batostr((void *) a2)); @@ -231,7 +235,8 @@ static int bnep_rx_control(struct bnep_session *s, void *data, int len) u8 cmd = *(u8 *)data; int err = 0; - data++; len--; + data++; + len--; switch (cmd) { case BNEP_CMD_NOT_UNDERSTOOD: @@ -315,7 +320,8 @@ static inline int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb) dev->stats.rx_bytes += skb->len; - type = *(u8 *) skb->data; skb_pull(skb, 1); + type = *(u8 *) skb->data; + skb_pull(skb, 1); if ((type & BNEP_TYPE_MASK) >= sizeof(__bnep_rx_hlen)) goto badframe; @@ -370,14 +376,14 @@ static inline int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb) case BNEP_COMPRESSED_DST_ONLY: memcpy(__skb_put(nskb, ETH_ALEN), skb_mac_header(skb), - ETH_ALEN); + ETH_ALEN); memcpy(__skb_put(nskb, ETH_ALEN + 2), s->eh.h_source, - ETH_ALEN + 2); + ETH_ALEN + 2); break; case BNEP_GENERAL: memcpy(__skb_put(nskb, ETH_ALEN * 2), skb_mac_header(skb), - ETH_ALEN * 2); + ETH_ALEN * 2); put_unaligned(s->eh.h_proto, (__be16 *) __skb_put(nskb, 2)); break; } @@ -481,7 +487,7 @@ static int bnep_session(void *arg) while (!atomic_read(&s->killed)) { set_current_state(TASK_INTERRUPTIBLE); - // RX + /* RX */ while ((skb = skb_dequeue(&sk->sk_receive_queue))) { skb_orphan(skb); bnep_rx_frame(s, skb); @@ -490,7 +496,7 @@ static int bnep_session(void *arg) if (sk->sk_state != BT_CONNECTED) break; - // TX + /* TX */ while ((skb = skb_dequeue(&sk->sk_write_queue))) if (bnep_tx_frame(s, skb)) break; @@ -558,8 +564,8 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock) /* session struct allocated as private part of net_device */ dev = alloc_netdev(sizeof(struct bnep_session), - (*req->device) ? req->device : "bnep%d", - bnep_net_setup); + (*req->device) ? req->device : "bnep%d", + bnep_net_setup); if (!dev) return -ENOMEM; @@ -574,7 +580,7 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock) s = netdev_priv(dev); /* This is rx header therefore addresses are swapped. - * ie eh.h_dest is our local address. */ + * ie. eh.h_dest is our local address. */ memcpy(s->eh.h_dest, &src, ETH_ALEN); memcpy(s->eh.h_source, &dst, ETH_ALEN); memcpy(dev->dev_addr, s->eh.h_dest, ETH_ALEN); @@ -600,9 +606,8 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock) SET_NETDEV_DEVTYPE(dev, &bnep_type); err = register_netdev(dev); - if (err) { + if (err) goto failed; - } __bnep_link_session(s); -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 03/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> 2011-03-21 13:19 Szymon Janc 2011-03-21 13:19 ` [PATCH 01/10] Bluetooth: Opencode macros in bnep/core.c Szymon Janc 2011-03-21 13:19 ` [PATCH 02/10] Bluetooth: Fix checkpatch errors and some code style issues in bnep Szymon Janc @ 2011-03-21 13:19 ` Szymon Janc 2011-03-21 13:20 ` [PATCH 04/10] Bluetooth: Use kthread API in bnep Szymon Janc ` (6 subsequent siblings) 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:19 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc As warned by checkpatch.pl, use #include <linux/uaccess.h> instead of <asm/uaccess.h> Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/bnep/sock.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c index d935da7..17800b1 100644 --- a/net/bluetooth/bnep/sock.c +++ b/net/bluetooth/bnep/sock.c @@ -39,10 +39,10 @@ #include <linux/init.h> #include <linux/compat.h> #include <linux/gfp.h> +#include <linux/uaccess.h> #include <net/sock.h> #include <asm/system.h> -#include <asm/uaccess.h> #include "bnep.h" -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 04/10] Bluetooth: Use kthread API in bnep 2011-03-21 13:19 Szymon Janc ` (2 preceding siblings ...) 2011-03-21 13:19 ` [PATCH 03/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> Szymon Janc @ 2011-03-21 13:20 ` Szymon Janc 2011-03-24 20:12 ` Gustavo F. Padovan 2011-03-21 13:20 ` [PATCH 05/10] Bluetooth: Fix checkpatch errors, code style issues and typos in hidp Szymon Janc ` (5 subsequent siblings) 9 siblings, 1 reply; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:20 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc kernel_thread() is a low-level implementation detail and EXPORT_SYMBOL(kernel_thread) is scheduled for removal. Use the <linux/kthread.h> API instead. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/bnep/bnep.h | 2 +- net/bluetooth/bnep/core.c | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/net/bluetooth/bnep/bnep.h b/net/bluetooth/bnep/bnep.h index d768e04..8e6c061 100644 --- a/net/bluetooth/bnep/bnep.h +++ b/net/bluetooth/bnep/bnep.h @@ -155,7 +155,7 @@ struct bnep_session { unsigned int role; unsigned long state; unsigned long flags; - atomic_t killed; + struct task_struct *task; struct ethhdr eh; struct msghdr msg; diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c index 0a2e76b..ca39fcf 100644 --- a/net/bluetooth/bnep/core.c +++ b/net/bluetooth/bnep/core.c @@ -36,6 +36,7 @@ #include <linux/errno.h> #include <linux/net.h> #include <linux/slab.h> +#include <linux/kthread.h> #include <net/sock.h> #include <linux/socket.h> @@ -479,12 +480,11 @@ static int bnep_session(void *arg) BT_DBG(""); - daemonize("kbnepd %s", dev->name); set_user_nice(current, -15); init_waitqueue_entry(&wait, current); add_wait_queue(sk_sleep(sk), &wait); - while (!atomic_read(&s->killed)) { + while (!kthread_should_stop()) { set_current_state(TASK_INTERRUPTIBLE); /* RX */ @@ -611,11 +611,12 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock) __bnep_link_session(s); - err = kernel_thread(bnep_session, s, CLONE_KERNEL); - if (err < 0) { + s->task = kthread_run(bnep_session, s, "kbnepd %s", dev->name); + if (IS_ERR(s->task)) { /* Session thread start failed, gotta cleanup. */ unregister_netdev(dev); __bnep_unlink_session(s); + err = PTR_ERR(s->task); goto failed; } @@ -639,15 +640,9 @@ int bnep_del_connection(struct bnep_conndel_req *req) down_read(&bnep_session_sem); s = __bnep_get_session(req->dst); - if (s) { - /* Wakeup user-space which is polling for socket errors. - * This is temporary hack until we have shutdown in L2CAP */ - s->sock->sk->sk_err = EUNATCH; - - /* Kill session thread */ - atomic_inc(&s->killed); - wake_up_interruptible(sk_sleep(s->sock->sk)); - } else + if (s) + kthread_stop(s->task); + else err = -ENOENT; up_read(&bnep_session_sem); -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 04/10] Bluetooth: Use kthread API in bnep 2011-03-21 13:20 ` [PATCH 04/10] Bluetooth: Use kthread API in bnep Szymon Janc @ 2011-03-24 20:12 ` Gustavo F. Padovan 2011-04-05 7:51 ` Szymon Janc 0 siblings, 1 reply; 16+ messages in thread From: Gustavo F. Padovan @ 2011-03-24 20:12 UTC (permalink / raw) To: Szymon Janc; +Cc: linux-bluetooth, par-gunnar.p.hjalmdahl, henrik.possung Hy Szymon, * Szymon Janc <szymon.janc@tieto.com> [2011-03-21 14:20:00 +0100]: > kernel_thread() is a low-level implementation detail and > EXPORT_SYMBOL(kernel_thread) is scheduled for removal. > Use the <linux/kthread.h> API instead. Just to be sure. Have you tested the kernel_thread removal patches for bnep and hipd? -- Gustavo F. Padovan http://profusion.mobi ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 04/10] Bluetooth: Use kthread API in bnep 2011-03-24 20:12 ` Gustavo F. Padovan @ 2011-04-05 7:51 ` Szymon Janc 2011-04-05 13:37 ` [PATCH v2] Bluetooth: Use kthread API in hidp Szymon Janc 2011-04-05 15:39 ` [PATCH 04/10] Bluetooth: Use kthread API in bnep Gustavo F. Padovan 0 siblings, 2 replies; 16+ messages in thread From: Szymon Janc @ 2011-04-05 7:51 UTC (permalink / raw) To: Gustavo F. Padovan Cc: linux-bluetooth@vger.kernel.org, par-gunnar.p.hjalmdahl@stericsson.com, henrik.possung@stericsson.com > Hy Szymon, Hi, > * Szymon Janc <szymon.janc@tieto.com> [2011-03-21 14:20:00 +0100]: > > > kernel_thread() is a low-level implementation detail and > > EXPORT_SYMBOL(kernel_thread) is scheduled for removal. > > Use the <linux/kthread.h> API instead. > > Just to be sure. Have you tested the kernel_thread removal patches for bnep > and hipd? Sorry for late reply, missed that one.. Yes, I did test both bnep (basic connect-disconnect) and hidp (play around with it from my mobile). Kernel processes create and terminate fine. I didn't test cmtp (don't have isdn hw) but change is very similar to rest of patches. I've noticed that hidp patch doesn't apply anymore to bluetooth-next-2.6 after merging 2.6.39-rc1. I'll send v2 shortly (only for that one if you're fine with that) BR, Szymon Janc ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2] Bluetooth: Use kthread API in hidp 2011-04-05 7:51 ` Szymon Janc @ 2011-04-05 13:37 ` Szymon Janc 2011-04-05 15:39 ` [PATCH 04/10] Bluetooth: Use kthread API in bnep Gustavo F. Padovan 1 sibling, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-04-05 13:37 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc kernel_thread() is a low-level implementation detail and EXPORT_SYMBOL(kernel_thread) is scheduled for removal. Use the <linux/kthread.h> API instead. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/hidp/core.c | 53 ++++++++++++++++++++------------------------ net/bluetooth/hidp/hidp.h | 2 +- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c index a1472b7..ae6ebc6 100644 --- a/net/bluetooth/hidp/core.c +++ b/net/bluetooth/hidp/core.c @@ -37,6 +37,7 @@ #include <linux/init.h> #include <linux/wait.h> #include <linux/mutex.h> +#include <linux/kthread.h> #include <net/sock.h> #include <linux/input.h> @@ -463,8 +464,7 @@ static void hidp_idle_timeout(unsigned long arg) { struct hidp_session *session = (struct hidp_session *) arg; - atomic_inc(&session->terminate); - hidp_schedule(session); + kthread_stop(session->task); } static void hidp_set_timer(struct hidp_session *session) @@ -535,9 +535,7 @@ static void hidp_process_hid_control(struct hidp_session *session, skb_queue_purge(&session->ctrl_transmit); skb_queue_purge(&session->intr_transmit); - /* Kill session thread */ - atomic_inc(&session->terminate); - hidp_schedule(session); + kthread_stop(session->task); } } @@ -696,22 +694,10 @@ static int hidp_session(void *arg) struct sock *ctrl_sk = session->ctrl_sock->sk; struct sock *intr_sk = session->intr_sock->sk; struct sk_buff *skb; - int vendor = 0x0000, product = 0x0000; wait_queue_t ctrl_wait, intr_wait; BT_DBG("session %p", session); - if (session->input) { - vendor = session->input->id.vendor; - product = session->input->id.product; - } - - if (session->hid) { - vendor = session->hid->vendor; - product = session->hid->product; - } - - daemonize("khidpd_%04x%04x", vendor, product); set_user_nice(current, -15); init_waitqueue_entry(&ctrl_wait, current); @@ -720,7 +706,7 @@ static int hidp_session(void *arg) add_wait_queue(sk_sleep(intr_sk), &intr_wait); session->waiting_for_startup = 0; wake_up_interruptible(&session->startup_queue); - while (!atomic_read(&session->terminate)) { + while (!kthread_should_stop()) { set_current_state(TASK_INTERRUPTIBLE); if (ctrl_sk->sk_state != BT_CONNECTED || @@ -968,6 +954,7 @@ fault: int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock) { struct hidp_session *session, *s; + int vendor, product; int err; BT_DBG(""); @@ -1029,9 +1016,24 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, hidp_set_timer(session); - err = kernel_thread(hidp_session, session, CLONE_KERNEL); - if (err < 0) + if (session->hid) { + vendor = session->hid->vendor; + product = session->hid->product; + } else if (session->input) { + vendor = session->input->id.vendor; + product = session->input->id.product; + } else { + vendor = 0x0000; + product = 0x0000; + } + + session->task = kthread_run(hidp_session, session, "khidpd_%04x%04x", + vendor, product); + if (IS_ERR(session->task)) { + err = PTR_ERR(session->task); goto unlink; + } + while (session->waiting_for_startup) { wait_event_interruptible(session->startup_queue, !session->waiting_for_startup); @@ -1056,8 +1058,7 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, err_add_device: hid_destroy_device(session->hid); session->hid = NULL; - atomic_inc(&session->terminate); - hidp_schedule(session); + kthread_stop(session->task); unlink: hidp_del_timer(session); @@ -1108,13 +1109,7 @@ int hidp_del_connection(struct hidp_conndel_req *req) skb_queue_purge(&session->ctrl_transmit); skb_queue_purge(&session->intr_transmit); - /* Wakeup user-space polling for socket errors */ - session->intr_sock->sk->sk_err = EUNATCH; - session->ctrl_sock->sk->sk_err = EUNATCH; - - /* Kill session thread */ - atomic_inc(&session->terminate); - hidp_schedule(session); + kthread_stop(session->task); } } else err = -ENOENT; diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h index b412e71..12822cd 100644 --- a/net/bluetooth/hidp/hidp.h +++ b/net/bluetooth/hidp/hidp.h @@ -142,7 +142,7 @@ struct hidp_session { uint ctrl_mtu; uint intr_mtu; - atomic_t terminate; + struct task_struct *task; unsigned char keys[8]; unsigned char leds; -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 04/10] Bluetooth: Use kthread API in bnep 2011-04-05 7:51 ` Szymon Janc 2011-04-05 13:37 ` [PATCH v2] Bluetooth: Use kthread API in hidp Szymon Janc @ 2011-04-05 15:39 ` Gustavo F. Padovan 1 sibling, 0 replies; 16+ messages in thread From: Gustavo F. Padovan @ 2011-04-05 15:39 UTC (permalink / raw) To: Szymon Janc Cc: linux-bluetooth@vger.kernel.org, par-gunnar.p.hjalmdahl@stericsson.com, henrik.possung@stericsson.com Hi Szymon, * Szymon Janc <szymon.janc@tieto.com> [2011-04-05 09:51:17 +0200]: > > Hy Szymon, > > Hi, > > > * Szymon Janc <szymon.janc@tieto.com> [2011-03-21 14:20:00 +0100]: > > > > > kernel_thread() is a low-level implementation detail and > > > EXPORT_SYMBOL(kernel_thread) is scheduled for removal. > > > Use the <linux/kthread.h> API instead. > > > > Just to be sure. Have you tested the kernel_thread removal patches for bnep > > and hipd? > > Sorry for late reply, missed that one.. > Yes, I did test both bnep (basic connect-disconnect) and hidp (play around with it > from my mobile). Kernel processes create and terminate fine. Fair enough, I applied the 3 patches. Thanks for fixing this. > > I didn't test cmtp (don't have isdn hw) but change is very similar to rest of patches. No problem, no one should be using this thing these days. -- Gustavo F. Padovan http://profusion.mobi ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 05/10] Bluetooth: Fix checkpatch errors, code style issues and typos in hidp 2011-03-21 13:19 Szymon Janc ` (3 preceding siblings ...) 2011-03-21 13:20 ` [PATCH 04/10] Bluetooth: Use kthread API in bnep Szymon Janc @ 2011-03-21 13:20 ` Szymon Janc 2011-03-21 13:20 ` [PATCH 06/10] Bluetooth: Use kthread API " Szymon Janc ` (4 subsequent siblings) 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:20 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/hidp/core.c | 37 ++++++++++++++++++++----------------- net/bluetooth/hidp/hidp.h | 4 ++-- net/bluetooth/hidp/sock.c | 7 ++++--- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c index 2429ca2..ba546d4 100644 --- a/net/bluetooth/hidp/core.c +++ b/net/bluetooth/hidp/core.c @@ -54,22 +54,24 @@ static DECLARE_RWSEM(hidp_session_sem); static LIST_HEAD(hidp_session_list); static unsigned char hidp_keycode[256] = { - 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, - 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3, - 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26, - 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106, - 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71, - 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190, - 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113, - 115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0, - 122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113, - 150,158,159,128,136,177,178,176,142,152,173,140 + 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, + 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, + 21, 44, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, + 14, 15, 57, 12, 13, 26, 27, 43, 43, 39, 40, 41, 51, 52, + 53, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 87, 88, + 99, 70, 119, 110, 102, 104, 111, 107, 109, 106, 105, 108, 103, 69, + 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71, 72, 73, + 82, 83, 86, 127, 116, 117, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 134, 138, 130, 132, 128, 129, 131, 137, 133, 135, + 136, 113, 115, 114, 0, 0, 0, 121, 0, 89, 93, 124, 92, 94, + 95, 0, 0, 0, 122, 123, 90, 91, 85, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 29, 42, 56, 125, 97, 54, 100, 126, 164, 166, 165, 163, 161, 115, + 114, 113, 150, 158, 159, 128, 136, 177, 178, 176, 142, 152, 173, 140 }; static unsigned char hidp_mkeyspat[] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }; @@ -569,7 +571,8 @@ static int hidp_session(void *arg) while (!atomic_read(&session->terminate)) { set_current_state(TASK_INTERRUPTIBLE); - if (ctrl_sk->sk_state != BT_CONNECTED || intr_sk->sk_state != BT_CONNECTED) + if (ctrl_sk->sk_state != BT_CONNECTED || + intr_sk->sk_state != BT_CONNECTED) break; while ((skb = skb_dequeue(&ctrl_sk->sk_receive_queue))) { diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h index 8d934a1..28bb9ce 100644 --- a/net/bluetooth/hidp/hidp.h +++ b/net/bluetooth/hidp/hidp.h @@ -82,8 +82,8 @@ #define HIDP_BLUETOOTH_VENDOR_ID 9 struct hidp_connadd_req { - int ctrl_sock; // Connected control socket - int intr_sock; // Connteted interrupt socket + int ctrl_sock; /* Connected control socket */ + int intr_sock; /* Connected interrupt socket */ __u16 parser; __u16 rd_size; __u8 __user *rd_data; diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c index 250dfd4..178ac7f 100644 --- a/net/bluetooth/hidp/sock.c +++ b/net/bluetooth/hidp/sock.c @@ -85,7 +85,8 @@ static int hidp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long return err; } - if (csock->sk->sk_state != BT_CONNECTED || isock->sk->sk_state != BT_CONNECTED) { + if (csock->sk->sk_state != BT_CONNECTED || + isock->sk->sk_state != BT_CONNECTED) { sockfd_put(csock); sockfd_put(isock); return -EBADFD; @@ -140,8 +141,8 @@ static int hidp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long #ifdef CONFIG_COMPAT struct compat_hidp_connadd_req { - int ctrl_sock; // Connected control socket - int intr_sock; // Connteted interrupt socket + int ctrl_sock; /* Connected control socket */ + int intr_sock; /* Connected interrupt socket */ __u16 parser; __u16 rd_size; compat_uptr_t rd_data; -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 06/10] Bluetooth: Use kthread API in hidp 2011-03-21 13:19 Szymon Janc ` (4 preceding siblings ...) 2011-03-21 13:20 ` [PATCH 05/10] Bluetooth: Fix checkpatch errors, code style issues and typos in hidp Szymon Janc @ 2011-03-21 13:20 ` Szymon Janc 2011-03-21 13:20 ` [PATCH 07/10] Bluetooth: Do not use assignments in IF conditions Szymon Janc ` (3 subsequent siblings) 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:20 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc kernel_thread() is a low-level implementation detail and EXPORT_SYMBOL(kernel_thread) is scheduled for removal. Use the <linux/kthread.h> API instead. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/hidp/core.c | 49 ++++++++++++++++++++------------------------ net/bluetooth/hidp/hidp.h | 2 +- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c index ba546d4..f61aa80 100644 --- a/net/bluetooth/hidp/core.c +++ b/net/bluetooth/hidp/core.c @@ -36,6 +36,7 @@ #include <linux/file.h> #include <linux/init.h> #include <linux/wait.h> +#include <linux/kthread.h> #include <net/sock.h> #include <linux/input.h> @@ -342,8 +343,7 @@ static void hidp_idle_timeout(unsigned long arg) { struct hidp_session *session = (struct hidp_session *) arg; - atomic_inc(&session->terminate); - hidp_schedule(session); + kthread_stop(session->task); } static void hidp_set_timer(struct hidp_session *session) @@ -402,9 +402,7 @@ static void hidp_process_hid_control(struct hidp_session *session, skb_queue_purge(&session->ctrl_transmit); skb_queue_purge(&session->intr_transmit); - /* Kill session thread */ - atomic_inc(&session->terminate); - hidp_schedule(session); + kthread_stop(session->task); } } @@ -546,29 +544,17 @@ static int hidp_session(void *arg) struct sock *ctrl_sk = session->ctrl_sock->sk; struct sock *intr_sk = session->intr_sock->sk; struct sk_buff *skb; - int vendor = 0x0000, product = 0x0000; wait_queue_t ctrl_wait, intr_wait; BT_DBG("session %p", session); - if (session->input) { - vendor = session->input->id.vendor; - product = session->input->id.product; - } - - if (session->hid) { - vendor = session->hid->vendor; - product = session->hid->product; - } - - daemonize("khidpd_%04x%04x", vendor, product); set_user_nice(current, -15); init_waitqueue_entry(&ctrl_wait, current); init_waitqueue_entry(&intr_wait, current); add_wait_queue(sk_sleep(ctrl_sk), &ctrl_wait); add_wait_queue(sk_sleep(intr_sk), &intr_wait); - while (!atomic_read(&session->terminate)) { + while (!kthread_should_stop()) { set_current_state(TASK_INTERRUPTIBLE); if (ctrl_sk->sk_state != BT_CONNECTED || @@ -821,6 +807,7 @@ fault: int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock) { struct hidp_session *session, *s; + int vendor, product; int err; BT_DBG(""); @@ -878,9 +865,23 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, hidp_set_timer(session); - err = kernel_thread(hidp_session, session, CLONE_KERNEL); - if (err < 0) + if (session->hid) { + vendor = session->hid->vendor; + product = session->hid->product; + } else if (session->input) { + vendor = session->input->id.vendor; + product = session->input->id.product; + } else { + vendor = 0x0000; + product = 0x0000; + } + + session->task = kthread_run(hidp_session, session, "khidpd_%04x%04x", + vendor, product); + if (IS_ERR(session->task)) { + err = PTR_ERR(session->task); goto unlink; + } if (session->input) { hidp_send_ctrl_message(session, @@ -943,13 +944,7 @@ int hidp_del_connection(struct hidp_conndel_req *req) skb_queue_purge(&session->ctrl_transmit); skb_queue_purge(&session->intr_transmit); - /* Wakeup user-space polling for socket errors */ - session->intr_sock->sk->sk_err = EUNATCH; - session->ctrl_sock->sk->sk_err = EUNATCH; - - /* Kill session thread */ - atomic_inc(&session->terminate); - hidp_schedule(session); + kthread_stop(session->task); } } else err = -ENOENT; diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h index 28bb9ce..8262acd 100644 --- a/net/bluetooth/hidp/hidp.h +++ b/net/bluetooth/hidp/hidp.h @@ -140,7 +140,7 @@ struct hidp_session { uint ctrl_mtu; uint intr_mtu; - atomic_t terminate; + struct task_struct *task; unsigned char keys[8]; unsigned char leds; -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 07/10] Bluetooth: Do not use assignments in IF conditions 2011-03-21 13:19 Szymon Janc ` (5 preceding siblings ...) 2011-03-21 13:20 ` [PATCH 06/10] Bluetooth: Use kthread API " Szymon Janc @ 2011-03-21 13:20 ` Szymon Janc 2011-03-21 13:20 ` [PATCH 08/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> Szymon Janc ` (2 subsequent siblings) 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:20 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc Fix checkpatch warnings concerning assignments in if conditions. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/cmtp/core.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c index 964ea91..16aa6bd 100644 --- a/net/bluetooth/cmtp/core.c +++ b/net/bluetooth/cmtp/core.c @@ -235,9 +235,12 @@ static void cmtp_process_transmit(struct cmtp_session *session) size = min_t(uint, ((tail < 258) ? (tail - 2) : (tail - 3)), skb->len); - if ((scb->id < 0) && ((scb->id = cmtp_alloc_block_id(session)) < 0)) { - skb_queue_head(&session->transmit, skb); - break; + if (scb->id < 0) { + scb->id = cmtp_alloc_block_id(session); + if (scb->id < 0) { + skb_queue_head(&session->transmit, skb); + break; + } } if (size < 256) { -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 08/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> 2011-03-21 13:19 Szymon Janc ` (6 preceding siblings ...) 2011-03-21 13:20 ` [PATCH 07/10] Bluetooth: Do not use assignments in IF conditions Szymon Janc @ 2011-03-21 13:20 ` Szymon Janc 2011-03-21 13:20 ` [PATCH 09/10] Bluetooth: Fix checkpatch error in cmtp.h Szymon Janc 2011-03-21 13:20 ` [PATCH 10/10] Bluetooth: Use kthread API in cmtp Szymon Janc 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:20 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc As warned by checkpatch.pl, use #include <linux/uaccess.h> instead of <asm/uaccess.h> Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/cmtp/sock.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c index 7ea1979..3f2dd5c 100644 --- a/net/bluetooth/cmtp/sock.c +++ b/net/bluetooth/cmtp/sock.c @@ -34,12 +34,12 @@ #include <linux/file.h> #include <linux/compat.h> #include <linux/gfp.h> +#include <linux/uaccess.h> #include <net/sock.h> #include <linux/isdn/capilli.h> #include <asm/system.h> -#include <asm/uaccess.h> #include "cmtp.h" -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 09/10] Bluetooth: Fix checkpatch error in cmtp.h 2011-03-21 13:19 Szymon Janc ` (7 preceding siblings ...) 2011-03-21 13:20 ` [PATCH 08/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> Szymon Janc @ 2011-03-21 13:20 ` Szymon Janc 2011-03-24 20:23 ` Gustavo F. Padovan 2011-03-21 13:20 ` [PATCH 10/10] Bluetooth: Use kthread API in cmtp Szymon Janc 9 siblings, 1 reply; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:20 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc Do not use C99 // comments. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/cmtp/cmtp.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/net/bluetooth/cmtp/cmtp.h b/net/bluetooth/cmtp/cmtp.h index 785e79e..c6f78f8 100644 --- a/net/bluetooth/cmtp/cmtp.h +++ b/net/bluetooth/cmtp/cmtp.h @@ -37,7 +37,7 @@ #define CMTP_LOOPBACK 0 struct cmtp_connadd_req { - int sock; // Connected socket + int sock; /* Connected socket */ __u32 flags; }; -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 09/10] Bluetooth: Fix checkpatch error in cmtp.h 2011-03-21 13:20 ` [PATCH 09/10] Bluetooth: Fix checkpatch error in cmtp.h Szymon Janc @ 2011-03-24 20:23 ` Gustavo F. Padovan 0 siblings, 0 replies; 16+ messages in thread From: Gustavo F. Padovan @ 2011-03-24 20:23 UTC (permalink / raw) To: Szymon Janc; +Cc: linux-bluetooth, par-gunnar.p.hjalmdahl, henrik.possung Hi Szymon, * Szymon Janc <szymon.janc@tieto.com> [2011-03-21 14:20:05 +0100]: > Do not use C99 // comments. > > Signed-off-by: Szymon Janc <szymon.janc@tieto.com> > --- > net/bluetooth/cmtp/cmtp.h | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) All patches applied, except the 3 kthread ones. I'll wait your reply on them. -- Gustavo F. Padovan http://profusion.mobi ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 10/10] Bluetooth: Use kthread API in cmtp 2011-03-21 13:19 Szymon Janc ` (8 preceding siblings ...) 2011-03-21 13:20 ` [PATCH 09/10] Bluetooth: Fix checkpatch error in cmtp.h Szymon Janc @ 2011-03-21 13:20 ` Szymon Janc 9 siblings, 0 replies; 16+ messages in thread From: Szymon Janc @ 2011-03-21 13:20 UTC (permalink / raw) To: linux-bluetooth; +Cc: par-gunnar.p.hjalmdahl, henrik.possung, Szymon Janc kernel_thread() is a low-level implementation detail and EXPORT_SYMBOL(kernel_thread) is scheduled for removal. Use the <linux/kthread.h> API instead. Signed-off-by: Szymon Janc <szymon.janc@tieto.com> --- net/bluetooth/cmtp/capi.c | 6 +++--- net/bluetooth/cmtp/cmtp.h | 9 +-------- net/bluetooth/cmtp/core.c | 16 +++++++++------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/net/bluetooth/cmtp/capi.c b/net/bluetooth/cmtp/capi.c index 67cff81..744233c 100644 --- a/net/bluetooth/cmtp/capi.c +++ b/net/bluetooth/cmtp/capi.c @@ -35,6 +35,7 @@ #include <linux/ioctl.h> #include <linux/file.h> #include <linux/wait.h> +#include <linux/kthread.h> #include <net/sock.h> #include <linux/isdn/capilli.h> @@ -143,7 +144,7 @@ static void cmtp_send_capimsg(struct cmtp_session *session, struct sk_buff *skb) skb_queue_tail(&session->transmit, skb); - cmtp_schedule(session); + wake_up_interruptible(sk_sleep(session->sock->sk)); } static void cmtp_send_interopmsg(struct cmtp_session *session, @@ -386,8 +387,7 @@ static void cmtp_reset_ctr(struct capi_ctr *ctrl) capi_ctr_down(ctrl); - atomic_inc(&session->terminate); - cmtp_schedule(session); + kthread_stop(session->task); } static void cmtp_register_appl(struct capi_ctr *ctrl, __u16 appl, capi_register_params *rp) diff --git a/net/bluetooth/cmtp/cmtp.h b/net/bluetooth/cmtp/cmtp.h index c6f78f8..db43b54 100644 --- a/net/bluetooth/cmtp/cmtp.h +++ b/net/bluetooth/cmtp/cmtp.h @@ -81,7 +81,7 @@ struct cmtp_session { char name[BTNAMSIZ]; - atomic_t terminate; + struct task_struct *task; wait_queue_head_t wait; @@ -121,13 +121,6 @@ void cmtp_detach_device(struct cmtp_session *session); void cmtp_recv_capimsg(struct cmtp_session *session, struct sk_buff *skb); -static inline void cmtp_schedule(struct cmtp_session *session) -{ - struct sock *sk = session->sock->sk; - - wake_up_interruptible(sk_sleep(sk)); -} - /* CMTP init defines */ int cmtp_init_sockets(void); void cmtp_cleanup_sockets(void); diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c index 16aa6bd..cce99b0 100644 --- a/net/bluetooth/cmtp/core.c +++ b/net/bluetooth/cmtp/core.c @@ -35,6 +35,7 @@ #include <linux/ioctl.h> #include <linux/file.h> #include <linux/init.h> +#include <linux/kthread.h> #include <net/sock.h> #include <linux/isdn/capilli.h> @@ -287,12 +288,11 @@ static int cmtp_session(void *arg) BT_DBG("session %p", session); - daemonize("kcmtpd_ctr_%d", session->num); set_user_nice(current, -15); init_waitqueue_entry(&wait, current); add_wait_queue(sk_sleep(sk), &wait); - while (!atomic_read(&session->terminate)) { + while (!kthread_should_stop()) { set_current_state(TASK_INTERRUPTIBLE); if (sk->sk_state != BT_CONNECTED) @@ -370,9 +370,12 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock) __cmtp_link_session(session); - err = kernel_thread(cmtp_session, session, CLONE_KERNEL); - if (err < 0) + session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d", + session->num); + if (IS_ERR(session->task)) { + err = PTR_ERR(session->task); goto unlink; + } if (!(session->flags & (1 << CMTP_LOOPBACK))) { err = cmtp_attach_device(session); @@ -409,9 +412,8 @@ int cmtp_del_connection(struct cmtp_conndel_req *req) /* Flush the transmit queue */ skb_queue_purge(&session->transmit); - /* Kill session thread */ - atomic_inc(&session->terminate); - cmtp_schedule(session); + /* Stop session thread */ + kthread_stop(session->task); } else err = -ENOENT; -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2011-04-05 15:39 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-03-21 13:19 Szymon Janc 2011-03-21 13:19 ` [PATCH 01/10] Bluetooth: Opencode macros in bnep/core.c Szymon Janc 2011-03-21 13:19 ` [PATCH 02/10] Bluetooth: Fix checkpatch errors and some code style issues in bnep Szymon Janc 2011-03-21 13:19 ` [PATCH 03/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> Szymon Janc 2011-03-21 13:20 ` [PATCH 04/10] Bluetooth: Use kthread API in bnep Szymon Janc 2011-03-24 20:12 ` Gustavo F. Padovan 2011-04-05 7:51 ` Szymon Janc 2011-04-05 13:37 ` [PATCH v2] Bluetooth: Use kthread API in hidp Szymon Janc 2011-04-05 15:39 ` [PATCH 04/10] Bluetooth: Use kthread API in bnep Gustavo F. Padovan 2011-03-21 13:20 ` [PATCH 05/10] Bluetooth: Fix checkpatch errors, code style issues and typos in hidp Szymon Janc 2011-03-21 13:20 ` [PATCH 06/10] Bluetooth: Use kthread API " Szymon Janc 2011-03-21 13:20 ` [PATCH 07/10] Bluetooth: Do not use assignments in IF conditions Szymon Janc 2011-03-21 13:20 ` [PATCH 08/10] Bluetooth: Use #include <linux/uaccess.h> instead of <asm/uaccess.h> Szymon Janc 2011-03-21 13:20 ` [PATCH 09/10] Bluetooth: Fix checkpatch error in cmtp.h Szymon Janc 2011-03-24 20:23 ` Gustavo F. Padovan 2011-03-21 13:20 ` [PATCH 10/10] Bluetooth: Use kthread API in cmtp Szymon Janc
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).