ChangeSet 1.2229.1.3, 2005/03/18 15:10:40+01:00, [EMAIL PROTECTED]
[Bluetooth] Kill bt_sock_alloc() and its usage
Kill bt_sock_alloc() function and make the derived socks have
a struct bt_sock as its first member, so that the _pi() functions
can just cast the struct sock pointer to its respective types,
taking advantage of the fact that sk_alloc() now use kmalloc()
when no slab is passed.
This is another step, close to the final one, to kill sk_protinfo
and make further planned changes possible.
Signed-off-by: Arnaldo Carvalho de Melo <[EMAIL PROTECTED]>
Signed-off-by: David S. Miller <[EMAIL PROTECTED]>
Signed-off-by: Marcel Holtmann <[EMAIL PROTECTED]>
include/net/bluetooth/bluetooth.h | 1
include/net/bluetooth/hci_core.h | 4 ++-
include/net/bluetooth/l2cap.h | 3 +-
include/net/bluetooth/rfcomm.h | 3 +-
include/net/bluetooth/sco.h | 3 +-
net/bluetooth/af_bluetooth.c | 43 --------------------------------------
net/bluetooth/bnep/sock.c | 11 +++++++--
net/bluetooth/cmtp/sock.c | 8 +++++--
net/bluetooth/hci_sock.c | 8 ++++++-
net/bluetooth/hidp/sock.c | 8 +++++--
net/bluetooth/l2cap.c | 7 +++++-
net/bluetooth/rfcomm/sock.c | 10 +++++++-
net/bluetooth/sco.c | 9 +++++++
13 files changed, 58 insertions(+), 60 deletions(-)
diff -Nru a/include/net/bluetooth/bluetooth.h
b/include/net/bluetooth/bluetooth.h
--- a/include/net/bluetooth/bluetooth.h 2005-03-18 14:08:46 -08:00
+++ b/include/net/bluetooth/bluetooth.h 2005-03-18 14:08:46 -08:00
@@ -125,7 +125,6 @@
int bt_sock_register(int proto, struct net_proto_family *ops);
int bt_sock_unregister(int proto);
-struct sock *bt_sock_alloc(struct socket *sock, int proto, int pi_size, int
prio);
void bt_sock_link(struct bt_sock_list *l, struct sock *s);
void bt_sock_unlink(struct bt_sock_list *l, struct sock *s);
int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
*msg, size_t len, int flags);
diff -Nru a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
--- a/include/net/bluetooth/hci_core.h 2005-03-18 14:08:46 -08:00
+++ b/include/net/bluetooth/hci_core.h 2005-03-18 14:08:46 -08:00
@@ -595,8 +595,10 @@
void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
/* HCI info for socket */
-#define hci_pi(sk) ((struct hci_pinfo *)sk->sk_protinfo)
+#define hci_pi(sk) ((struct hci_pinfo *) sk)
+
struct hci_pinfo {
+ struct bt_sock bt;
struct hci_dev *hdev;
struct hci_filter filter;
__u32 cmsg_mask;
diff -Nru a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
--- a/include/net/bluetooth/l2cap.h 2005-03-18 14:08:46 -08:00
+++ b/include/net/bluetooth/l2cap.h 2005-03-18 14:08:46 -08:00
@@ -201,9 +201,10 @@
};
/* ----- L2CAP channel and socket info ----- */
-#define l2cap_pi(sk) ((struct l2cap_pinfo *)sk->sk_protinfo)
+#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
struct l2cap_pinfo {
+ struct bt_sock bt;
__u16 psm;
__u16 dcid;
__u16 scid;
diff -Nru a/include/net/bluetooth/rfcomm.h b/include/net/bluetooth/rfcomm.h
--- a/include/net/bluetooth/rfcomm.h 2005-03-18 14:08:46 -08:00
+++ b/include/net/bluetooth/rfcomm.h 2005-03-18 14:08:46 -08:00
@@ -293,9 +293,10 @@
#define RFCOMM_LM_RELIABLE 0x0010
#define RFCOMM_LM_SECURE 0x0020
-#define rfcomm_pi(sk) ((struct rfcomm_pinfo *)sk->sk_protinfo)
+#define rfcomm_pi(sk) ((struct rfcomm_pinfo *) sk)
struct rfcomm_pinfo {
+ struct bt_sock bt;
struct rfcomm_dlc *dlc;
u8 channel;
u32 link_mode;
diff -Nru a/include/net/bluetooth/sco.h b/include/net/bluetooth/sco.h
--- a/include/net/bluetooth/sco.h 2005-03-18 14:08:46 -08:00
+++ b/include/net/bluetooth/sco.h 2005-03-18 14:08:46 -08:00
@@ -68,9 +68,10 @@
#define sco_conn_unlock(c) spin_unlock(&c->lock);
/* ----- SCO socket info ----- */
-#define sco_pi(sk) ((struct sco_pinfo *)sk->sk_protinfo)
+#define sco_pi(sk) ((struct sco_pinfo *) sk)
struct sco_pinfo {
+ struct bt_sock bt;
__u32 flags;
struct sco_conn *conn;
};
diff -Nru a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
--- a/net/bluetooth/af_bluetooth.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/af_bluetooth.c 2005-03-18 14:08:46 -08:00
@@ -60,8 +60,6 @@
#define BT_MAX_PROTO 8
static struct net_proto_family *bt_proto[BT_MAX_PROTO];
-static kmem_cache_t *bt_sock_cache;
-
int bt_sock_register(int proto, struct net_proto_family *ops)
{
if (proto >= BT_MAX_PROTO)
@@ -108,36 +106,6 @@
return err;
}
-struct sock *bt_sock_alloc(struct socket *sock, int proto, int pi_size, int
prio)
-{
- struct sock *sk;
- void *pi;
-
- sk = sk_alloc(PF_BLUETOOTH, prio, sizeof(struct bt_sock),
bt_sock_cache);
- if (!sk)
- return NULL;
-
- if (pi_size) {
- pi = kmalloc(pi_size, prio);
- if (!pi) {
- sk_free(sk);
- return NULL;
- }
- memset(pi, 0, pi_size);
- sk->sk_protinfo = pi;
- }
-
- sock_init_data(sock, sk);
- INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
-
- sock_reset_flag(sk, SOCK_ZAPPED);
- sk->sk_protocol = proto;
- sk->sk_state = BT_OPEN;
-
- return sk;
-}
-EXPORT_SYMBOL(bt_sock_alloc);
-
void bt_sock_link(struct bt_sock_list *l, struct sock *sk)
{
write_lock_bh(&l->lock);
@@ -355,16 +323,6 @@
if (proc_bt)
proc_bt->owner = THIS_MODULE;
- /* Init socket cache */
- bt_sock_cache = kmem_cache_create("bt_sock",
- sizeof(struct bt_sock), 0,
- SLAB_HWCACHE_ALIGN, NULL, NULL);
-
- if (!bt_sock_cache) {
- BT_ERR("Socket cache creation failed");
- return -ENOMEM;
- }
-
sock_register(&bt_sock_family_ops);
BT_INFO("HCI device and connection manager initialized");
@@ -383,7 +341,6 @@
bt_sysfs_cleanup();
sock_unregister(PF_BLUETOOTH);
- kmem_cache_destroy(bt_sock_cache);
remove_proc_entry("bluetooth", NULL);
}
diff -Nru a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
--- a/net/bluetooth/bnep/sock.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/bnep/sock.c 2005-03-18 14:08:46 -08:00
@@ -176,17 +176,22 @@
if (sock->type != SOCK_RAW)
return -ESOCKTNOSUPPORT;
- if (!(sk = bt_sock_alloc(sock, PF_BLUETOOTH, 0, GFP_KERNEL)))
+ if (!(sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, sizeof(struct bt_sock),
NULL)))
return -ENOMEM;
+ sock_init_data(sock, sk);
+
sk_set_owner(sk, THIS_MODULE);
sock->ops = &bnep_sock_ops;
- sock->state = SS_UNCONNECTED;
+ sock->state = SS_UNCONNECTED;
+
+ sock_reset_flag(sk, SOCK_ZAPPED);
- sk->sk_destruct = NULL;
sk->sk_protocol = protocol;
+ sk->sk_state = BT_OPEN;
+
return 0;
}
diff -Nru a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
--- a/net/bluetooth/cmtp/sock.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/cmtp/sock.c 2005-03-18 14:08:46 -08:00
@@ -167,17 +167,21 @@
if (sock->type != SOCK_RAW)
return -ESOCKTNOSUPPORT;
- if (!(sk = bt_sock_alloc(sock, PF_BLUETOOTH, 0, GFP_KERNEL)))
+ if (!(sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, sizeof(struct bt_sock),
NULL)))
return -ENOMEM;
+ sock_init_data(sock, sk);
+
sk_set_owner(sk, THIS_MODULE);
sock->ops = &cmtp_sock_ops;
sock->state = SS_UNCONNECTED;
- sk->sk_destruct = NULL;
+ sock_reset_flag(sk, SOCK_ZAPPED);
+
sk->sk_protocol = protocol;
+ sk->sk_state = BT_OPEN;
return 0;
}
diff -Nru a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
--- a/net/bluetooth/hci_sock.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/hci_sock.c 2005-03-18 14:08:46 -08:00
@@ -601,9 +601,15 @@
sock->ops = &hci_sock_ops;
- sk = bt_sock_alloc(sock, protocol, sizeof(struct hci_pinfo),
GFP_KERNEL);
+ sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, sizeof(struct hci_pinfo), NULL);
if (!sk)
return -ENOMEM;
+
+ sock_init_data(sock, sk);
+
+ sock_reset_flag(sk, SOCK_ZAPPED);
+
+ sk->sk_protocol = protocol;
sk_set_owner(sk, THIS_MODULE);
diff -Nru a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
--- a/net/bluetooth/hidp/sock.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/hidp/sock.c 2005-03-18 14:08:46 -08:00
@@ -173,17 +173,21 @@
if (sock->type != SOCK_RAW)
return -ESOCKTNOSUPPORT;
- if (!(sk = bt_sock_alloc(sock, PF_BLUETOOTH, 0, GFP_KERNEL)))
+ if (!(sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, sizeof(struct bt_sock),
NULL)))
return -ENOMEM;
+ sock_init_data(sock, sk);
+
sk_set_owner(sk, THIS_MODULE);
sock->ops = &hidp_sock_ops;
sock->state = SS_UNCONNECTED;
- sk->sk_destruct = NULL;
+ sock_reset_flag(sk, SOCK_ZAPPED);
+
sk->sk_protocol = protocol;
+ sk->sk_state = BT_OPEN;
return 0;
}
diff -Nru a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
--- a/net/bluetooth/l2cap.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/l2cap.c 2005-03-18 14:08:46 -08:00
@@ -374,14 +374,19 @@
{
struct sock *sk;
- sk = bt_sock_alloc(sock, proto, sizeof(struct l2cap_pinfo), prio);
+ sk = sk_alloc(PF_BLUETOOTH, prio, sizeof(struct l2cap_pinfo), NULL);
if (!sk)
return NULL;
+ sock_init_data(sock, sk);
+ INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
+
sk_set_owner(sk, THIS_MODULE);
sk->sk_destruct = l2cap_sock_destruct;
sk->sk_sndtimeo = L2CAP_CONN_TIMEOUT;
+
+ sock_reset_flag(sk, SOCK_ZAPPED);
sk->sk_protocol = proto;
sk->sk_state = BT_OPEN;
diff -Nru a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
--- a/net/bluetooth/rfcomm/sock.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/rfcomm/sock.c 2005-03-18 14:08:46 -08:00
@@ -287,10 +287,13 @@
struct rfcomm_dlc *d;
struct sock *sk;
- sk = bt_sock_alloc(sock, BTPROTO_RFCOMM, sizeof(struct rfcomm_pinfo),
prio);
+ sk = sk_alloc(PF_BLUETOOTH, prio, sizeof(struct rfcomm_pinfo), NULL);
if (!sk)
return NULL;
+ sock_init_data(sock, sk);
+ INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
+
sk_set_owner(sk, THIS_MODULE);
d = rfcomm_dlc_alloc(prio);
@@ -298,6 +301,7 @@
sk_free(sk);
return NULL;
}
+
d->data_ready = rfcomm_sk_data_ready;
d->state_change = rfcomm_sk_state_change;
@@ -310,8 +314,10 @@
sk->sk_sndbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10;
sk->sk_rcvbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10;
+ sock_reset_flag(sk, SOCK_ZAPPED);
+
sk->sk_protocol = proto;
- sk->sk_state = BT_OPEN;
+ sk->sk_state = BT_OPEN;
bt_sock_link(&rfcomm_sk_list, sk);
diff -Nru a/net/bluetooth/sco.c b/net/bluetooth/sco.c
--- a/net/bluetooth/sco.c 2005-03-18 14:08:46 -08:00
+++ b/net/bluetooth/sco.c 2005-03-18 14:08:46 -08:00
@@ -420,14 +420,21 @@
{
struct sock *sk;
- sk = bt_sock_alloc(sock, proto, sizeof(struct sco_pinfo), prio);
+ sk = sk_alloc(PF_BLUETOOTH, prio, sizeof(struct sco_pinfo), NULL);
if (!sk)
return NULL;
+ sock_init_data(sock, sk);
+ INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
+
sk_set_owner(sk, THIS_MODULE);
sk->sk_destruct = sco_sock_destruct;
sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
+
+ sock_reset_flag(sk, SOCK_ZAPPED);
+
+ sk->sk_protocol = proto;
sk->sk_state = BT_OPEN;
sco_sock_init_timer(sk);
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html