Skip to content

Commit aef7d97

Browse files
committed
Bluetooth: Convert debug files to actually use debugfs instead of sysfs
Some of the debug files ended up wrongly in sysfs, because at that point of time, debugfs didn't exist. Convert these files to use debugfs and also seq_file. This patch converts all of these files at once and then removes the exported symbol for the Bluetooth sysfs class. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 101545f commit aef7d97

6 files changed

Lines changed: 114 additions & 88 deletions

File tree

‎include/net/bluetooth/bluetooth.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ extern void hci_sock_cleanup(void);
176176
extern int bt_sysfs_init(void);
177177
extern void bt_sysfs_cleanup(void);
178178

179-
extern struct class *bt_class;
179+
extern struct dentry *bt_debugfs;
180180

181181
#endif /* __BLUETOOTH_H */

‎net/bluetooth/hci_sysfs.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <net/bluetooth/bluetooth.h>
99
#include <net/bluetooth/hci_core.h>
1010

11-
struct class *bt_class = NULL;
12-
EXPORT_SYMBOL_GPL(bt_class);
11+
static struct class *bt_class;
1312

1413
struct dentry *bt_debugfs = NULL;
1514
EXPORT_SYMBOL_GPL(bt_debugfs);

‎net/bluetooth/l2cap.c‎

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <linux/skbuff.h>
4141
#include <linux/list.h>
4242
#include <linux/device.h>
43+
#include <linux/debugfs.h>
44+
#include <linux/seq_file.h>
4345
#include <linux/uaccess.h>
4446
#include <linux/crc16.h>
4547
#include <net/sock.h>
@@ -3937,39 +3939,42 @@ static int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 fl
39373939
return 0;
39383940
}
39393941

3940-
static ssize_t l2cap_sysfs_show(struct class *dev,
3941-
struct class_attribute *attr,
3942-
char *buf)
3942+
static int l2cap_debugfs_show(struct seq_file *f, void *p)
39433943
{
39443944
struct sock *sk;
39453945
struct hlist_node *node;
3946-
char *str = buf;
3947-
int size = PAGE_SIZE;
39483946

39493947
read_lock_bh(&l2cap_sk_list.lock);
39503948

39513949
sk_for_each(sk, node, &l2cap_sk_list.head) {
39523950
struct l2cap_pinfo *pi = l2cap_pi(sk);
3953-
int len;
3954-
3955-
len = snprintf(str, size, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d\n",
3956-
batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
3957-
sk->sk_state, __le16_to_cpu(pi->psm), pi->scid,
3958-
pi->dcid, pi->imtu, pi->omtu, pi->sec_level);
3959-
3960-
size -= len;
3961-
if (size <= 0)
3962-
break;
39633951

3964-
str += len;
3952+
seq_printf(f, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d\n",
3953+
batostr(&bt_sk(sk)->src),
3954+
batostr(&bt_sk(sk)->dst),
3955+
sk->sk_state, __le16_to_cpu(pi->psm),
3956+
pi->scid, pi->dcid,
3957+
pi->imtu, pi->omtu, pi->sec_level);
39653958
}
39663959

39673960
read_unlock_bh(&l2cap_sk_list.lock);
39683961

3969-
return str - buf;
3962+
return 0;
39703963
}
39713964

3972-
static CLASS_ATTR(l2cap, S_IRUGO, l2cap_sysfs_show, NULL);
3965+
static int l2cap_debugfs_open(struct inode *inode, struct file *file)
3966+
{
3967+
return single_open(file, l2cap_debugfs_show, inode->i_private);
3968+
}
3969+
3970+
static const struct file_operations l2cap_debugfs_fops = {
3971+
.open = l2cap_debugfs_open,
3972+
.read = seq_read,
3973+
.llseek = seq_lseek,
3974+
.release = single_release,
3975+
};
3976+
3977+
static struct dentry *l2cap_debugfs;
39733978

39743979
static const struct proto_ops l2cap_sock_ops = {
39753980
.family = PF_BLUETOOTH,
@@ -4029,8 +4034,12 @@ static int __init l2cap_init(void)
40294034
goto error;
40304035
}
40314036

4032-
if (class_create_file(bt_class, &class_attr_l2cap) < 0)
4033-
BT_ERR("Failed to create L2CAP info file");
4037+
if (bt_debugfs) {
4038+
l2cap_debugfs = debugfs_create_file("l2cap", 0444,
4039+
bt_debugfs, NULL, &l2cap_debugfs_fops);
4040+
if (!l2cap_debugfs)
4041+
BT_ERR("Failed to create L2CAP debug file");
4042+
}
40344043

40354044
BT_INFO("L2CAP ver %s", VERSION);
40364045
BT_INFO("L2CAP socket layer initialized");
@@ -4044,7 +4053,7 @@ static int __init l2cap_init(void)
40444053

40454054
static void __exit l2cap_exit(void)
40464055
{
4047-
class_remove_file(bt_class, &class_attr_l2cap);
4056+
debugfs_remove(l2cap_debugfs);
40484057

40494058
if (bt_sock_unregister(BTPROTO_L2CAP) < 0)
40504059
BT_ERR("L2CAP socket unregistration failed");

‎net/bluetooth/rfcomm/core.c‎

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <linux/init.h>
3434
#include <linux/wait.h>
3535
#include <linux/device.h>
36+
#include <linux/debugfs.h>
37+
#include <linux/seq_file.h>
3638
#include <linux/net.h>
3739
#include <linux/mutex.h>
3840
#include <linux/kthread.h>
@@ -2098,14 +2100,10 @@ static struct hci_cb rfcomm_cb = {
20982100
.security_cfm = rfcomm_security_cfm
20992101
};
21002102

2101-
static ssize_t rfcomm_dlc_sysfs_show(struct class *dev,
2102-
struct class_attribute *attr,
2103-
char *buf)
2103+
static int rfcomm_dlc_debugfs_show(struct seq_file *f, void *x)
21042104
{
21052105
struct rfcomm_session *s;
21062106
struct list_head *pp, *p;
2107-
char *str = buf;
2108-
int size = PAGE_SIZE;
21092107

21102108
rfcomm_lock();
21112109

@@ -2114,29 +2112,33 @@ static ssize_t rfcomm_dlc_sysfs_show(struct class *dev,
21142112
list_for_each(pp, &s->dlcs) {
21152113
struct sock *sk = s->sock->sk;
21162114
struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list);
2117-
int len;
21182115

2119-
len = snprintf(str, size, "%s %s %ld %d %d %d %d\n",
2120-
batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
2121-
d->state, d->dlci, d->mtu, d->rx_credits, d->tx_credits);
2122-
2123-
size -= len;
2124-
if (size <= 0)
2125-
break;
2126-
2127-
str += len;
2116+
seq_printf(f, "%s %s %ld %d %d %d %d\n",
2117+
batostr(&bt_sk(sk)->src),
2118+
batostr(&bt_sk(sk)->dst),
2119+
d->state, d->dlci, d->mtu,
2120+
d->rx_credits, d->tx_credits);
21282121
}
2129-
2130-
if (size <= 0)
2131-
break;
21322122
}
21332123

21342124
rfcomm_unlock();
21352125

2136-
return (str - buf);
2126+
return 0;
2127+
}
2128+
2129+
static int rfcomm_dlc_debugfs_open(struct inode *inode, struct file *file)
2130+
{
2131+
return single_open(file, rfcomm_dlc_debugfs_show, inode->i_private);
21372132
}
21382133

2139-
static CLASS_ATTR(rfcomm_dlc, S_IRUGO, rfcomm_dlc_sysfs_show, NULL);
2134+
static const struct file_operations rfcomm_dlc_debugfs_fops = {
2135+
.open = rfcomm_dlc_debugfs_open,
2136+
.read = seq_read,
2137+
.llseek = seq_lseek,
2138+
.release = single_release,
2139+
};
2140+
2141+
static struct dentry *rfcomm_dlc_debugfs;
21402142

21412143
/* ---- Initialization ---- */
21422144
static int __init rfcomm_init(void)
@@ -2153,8 +2155,12 @@ static int __init rfcomm_init(void)
21532155
goto unregister;
21542156
}
21552157

2156-
if (class_create_file(bt_class, &class_attr_rfcomm_dlc) < 0)
2157-
BT_ERR("Failed to create RFCOMM info file");
2158+
if (bt_debugfs) {
2159+
rfcomm_dlc_debugfs = debugfs_create_file("rfcomm_dlc", 0444,
2160+
bt_debugfs, NULL, &rfcomm_dlc_debugfs_fops);
2161+
if (!rfcomm_dlc_debugfs)
2162+
BT_ERR("Failed to create RFCOMM debug file");
2163+
}
21582164

21592165
err = rfcomm_init_ttys();
21602166
if (err < 0)
@@ -2182,7 +2188,7 @@ static int __init rfcomm_init(void)
21822188

21832189
static void __exit rfcomm_exit(void)
21842190
{
2185-
class_remove_file(bt_class, &class_attr_rfcomm_dlc);
2191+
debugfs_remove(rfcomm_dlc_debugfs);
21862192

21872193
hci_unregister_cb(&rfcomm_cb);
21882194

‎net/bluetooth/rfcomm/sock.c‎

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <linux/skbuff.h>
4141
#include <linux/list.h>
4242
#include <linux/device.h>
43+
#include <linux/debugfs.h>
44+
#include <linux/seq_file.h>
4345
#include <net/sock.h>
4446

4547
#include <asm/system.h>
@@ -1061,37 +1063,38 @@ int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc *
10611063
return result;
10621064
}
10631065

1064-
static ssize_t rfcomm_sock_sysfs_show(struct class *dev,
1065-
struct class_attribute *attr,
1066-
char *buf)
1066+
static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
10671067
{
10681068
struct sock *sk;
10691069
struct hlist_node *node;
1070-
char *str = buf;
1071-
int size = PAGE_SIZE;
10721070

10731071
read_lock_bh(&rfcomm_sk_list.lock);
10741072

10751073
sk_for_each(sk, node, &rfcomm_sk_list.head) {
1076-
int len;
1077-
1078-
len = snprintf(str, size, "%s %s %d %d\n",
1079-
batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
1074+
seq_printf(f, "%s %s %d %d\n",
1075+
batostr(&bt_sk(sk)->src),
1076+
batostr(&bt_sk(sk)->dst),
10801077
sk->sk_state, rfcomm_pi(sk)->channel);
1081-
1082-
size -= len;
1083-
if (size <= 0)
1084-
break;
1085-
1086-
str += len;
10871078
}
10881079

10891080
read_unlock_bh(&rfcomm_sk_list.lock);
10901081

1091-
return (str - buf);
1082+
return 0;
10921083
}
10931084

1094-
static CLASS_ATTR(rfcomm, S_IRUGO, rfcomm_sock_sysfs_show, NULL);
1085+
static int rfcomm_sock_debugfs_open(struct inode *inode, struct file *file)
1086+
{
1087+
return single_open(file, rfcomm_sock_debugfs_show, inode->i_private);
1088+
}
1089+
1090+
static const struct file_operations rfcomm_sock_debugfs_fops = {
1091+
.open = rfcomm_sock_debugfs_open,
1092+
.read = seq_read,
1093+
.llseek = seq_lseek,
1094+
.release = single_release,
1095+
};
1096+
1097+
static struct dentry *rfcomm_sock_debugfs;
10951098

10961099
static const struct proto_ops rfcomm_sock_ops = {
10971100
.family = PF_BLUETOOTH,
@@ -1131,8 +1134,12 @@ int __init rfcomm_init_sockets(void)
11311134
if (err < 0)
11321135
goto error;
11331136

1134-
if (class_create_file(bt_class, &class_attr_rfcomm) < 0)
1135-
BT_ERR("Failed to create RFCOMM info file");
1137+
if (bt_debugfs) {
1138+
rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444,
1139+
bt_debugfs, NULL, &rfcomm_sock_debugfs_fops);
1140+
if (!rfcomm_sock_debugfs)
1141+
BT_ERR("Failed to create RFCOMM debug file");
1142+
}
11361143

11371144
BT_INFO("RFCOMM socket layer initialized");
11381145

@@ -1146,7 +1153,7 @@ int __init rfcomm_init_sockets(void)
11461153

11471154
void rfcomm_cleanup_sockets(void)
11481155
{
1149-
class_remove_file(bt_class, &class_attr_rfcomm);
1156+
debugfs_remove(rfcomm_sock_debugfs);
11501157

11511158
if (bt_sock_unregister(BTPROTO_RFCOMM) < 0)
11521159
BT_ERR("RFCOMM socket layer unregistration failed");

‎net/bluetooth/sco.c‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <linux/socket.h>
3939
#include <linux/skbuff.h>
4040
#include <linux/device.h>
41+
#include <linux/debugfs.h>
42+
#include <linux/seq_file.h>
4143
#include <linux/list.h>
4244
#include <net/sock.h>
4345

@@ -953,37 +955,36 @@ static int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
953955
return 0;
954956
}
955957

956-
static ssize_t sco_sysfs_show(struct class *dev,
957-
struct class_attribute *attr,
958-
char *buf)
958+
static int sco_debugfs_show(struct seq_file *f, void *p)
959959
{
960960
struct sock *sk;
961961
struct hlist_node *node;
962-
char *str = buf;
963-
int size = PAGE_SIZE;
964962

965963
read_lock_bh(&sco_sk_list.lock);
966964

967965
sk_for_each(sk, node, &sco_sk_list.head) {
968-
int len;
969-
970-
len = snprintf(str, size, "%s %s %d\n",
971-
batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
972-
sk->sk_state);
973-
974-
size -= len;
975-
if (size <= 0)
976-
break;
977-
978-
str += len;
966+
seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src),
967+
batostr(&bt_sk(sk)->dst), sk->sk_state);
979968
}
980969

981970
read_unlock_bh(&sco_sk_list.lock);
982971

983-
return (str - buf);
972+
return 0;
984973
}
985974

986-
static CLASS_ATTR(sco, S_IRUGO, sco_sysfs_show, NULL);
975+
static int sco_debugfs_open(struct inode *inode, struct file *file)
976+
{
977+
return single_open(file, sco_debugfs_show, inode->i_private);
978+
}
979+
980+
static const struct file_operations sco_debugfs_fops = {
981+
.open = sco_debugfs_open,
982+
.read = seq_read,
983+
.llseek = seq_lseek,
984+
.release = single_release,
985+
};
986+
987+
static struct dentry *sco_debugfs;
987988

988989
static const struct proto_ops sco_sock_ops = {
989990
.family = PF_BLUETOOTH,
@@ -1041,8 +1042,12 @@ static int __init sco_init(void)
10411042
goto error;
10421043
}
10431044

1044-
if (class_create_file(bt_class, &class_attr_sco) < 0)
1045-
BT_ERR("Failed to create SCO info file");
1045+
if (bt_debugfs) {
1046+
sco_debugfs = debugfs_create_file("sco", 0444,
1047+
bt_debugfs, NULL, &sco_debugfs_fops);
1048+
if (!sco_debugfs)
1049+
BT_ERR("Failed to create SCO debug file");
1050+
}
10461051

10471052
BT_INFO("SCO (Voice Link) ver %s", VERSION);
10481053
BT_INFO("SCO socket layer initialized");
@@ -1056,7 +1061,7 @@ static int __init sco_init(void)
10561061

10571062
static void __exit sco_exit(void)
10581063
{
1059-
class_remove_file(bt_class, &class_attr_sco);
1064+
debugfs_remove(sco_debugfs);
10601065

10611066
if (bt_sock_unregister(BTPROTO_SCO) < 0)
10621067
BT_ERR("SCO socket unregistration failed");

0 commit comments

Comments
 (0)