Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db7aa1c2 authored by Marcel Holtmann's avatar Marcel Holtmann
Browse files

Bluetooth: Fix warnings for bt_key_strings and bt_slock_key_strings



After adding proper lockdep annotations for Bluetooth protocols the case
when lockdep is disabled produced two compiler warnings:

net/bluetooth/af_bluetooth.c:60: warning: ‘bt_key_strings’ defined but not used
net/bluetooth/af_bluetooth.c:71: warning: ‘bt_slock_key_strings’ defined but not used

Fix both of them by adding a CONFIG_DEBUG_LOCK_ALLOC conditional around
them and re-arranging the code a little bit.

Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent c6bf514c
Loading
Loading
Loading
Loading
+23 −18
Original line number Original line Diff line number Diff line
@@ -51,8 +51,9 @@
/* Bluetooth sockets */
/* Bluetooth sockets */
#define BT_MAX_PROTO	8
#define BT_MAX_PROTO	8
static struct net_proto_family *bt_proto[BT_MAX_PROTO];
static struct net_proto_family *bt_proto[BT_MAX_PROTO];
static DEFINE_RWLOCK(bt_proto_lock);


static struct lock_class_key bt_slock_key[BT_MAX_PROTO];
#ifdef CONFIG_DEBUG_LOCK_ALLOC
static struct lock_class_key bt_lock_key[BT_MAX_PROTO];
static struct lock_class_key bt_lock_key[BT_MAX_PROTO];
static const char *bt_key_strings[BT_MAX_PROTO] = {
static const char *bt_key_strings[BT_MAX_PROTO] = {
	"sk_lock-AF_BLUETOOTH-BTPROTO_L2CAP",
	"sk_lock-AF_BLUETOOTH-BTPROTO_L2CAP",
@@ -65,6 +66,7 @@ static const char *bt_key_strings[BT_MAX_PROTO] = {
	"sk_lock-AF_BLUETOOTH-BTPROTO_AVDTP",
	"sk_lock-AF_BLUETOOTH-BTPROTO_AVDTP",
};
};


static struct lock_class_key bt_slock_key[BT_MAX_PROTO];
static const char *bt_slock_key_strings[BT_MAX_PROTO] = {
static const char *bt_slock_key_strings[BT_MAX_PROTO] = {
	"slock-AF_BLUETOOTH-BTPROTO_L2CAP",
	"slock-AF_BLUETOOTH-BTPROTO_L2CAP",
	"slock-AF_BLUETOOTH-BTPROTO_HCI",
	"slock-AF_BLUETOOTH-BTPROTO_HCI",
@@ -75,7 +77,25 @@ static const char *bt_slock_key_strings[BT_MAX_PROTO] = {
	"slock-AF_BLUETOOTH-BTPROTO_HIDP",
	"slock-AF_BLUETOOTH-BTPROTO_HIDP",
	"slock-AF_BLUETOOTH-BTPROTO_AVDTP",
	"slock-AF_BLUETOOTH-BTPROTO_AVDTP",
};
};
static DEFINE_RWLOCK(bt_proto_lock);

static inline void bt_sock_reclassify_lock(struct socket *sock, int proto)
{
	struct sock *sk = sock->sk;

	if (!sk)
		return;

	BUG_ON(sock_owned_by_user(sk));

	sock_lock_init_class_and_name(sk,
			bt_slock_key_strings[proto], &bt_slock_key[proto],
				bt_key_strings[proto], &bt_lock_key[proto]);
}
#else
static inline void bt_sock_reclassify_lock(struct socket *sock, int proto)
{
}
#endif


int bt_sock_register(int proto, struct net_proto_family *ops)
int bt_sock_register(int proto, struct net_proto_family *ops)
{
{
@@ -117,21 +137,6 @@ int bt_sock_unregister(int proto)
}
}
EXPORT_SYMBOL(bt_sock_unregister);
EXPORT_SYMBOL(bt_sock_unregister);


static void bt_reclassify_sock_lock(struct socket *sock, int proto)
{
	struct sock *sk = sock->sk;

	if (!sk)
		return;
	BUG_ON(sock_owned_by_user(sk));

	sock_lock_init_class_and_name(sk,
			bt_slock_key_strings[proto],
			&bt_slock_key[proto],
			bt_key_strings[proto],
			&bt_lock_key[proto]);
}

static int bt_sock_create(struct net *net, struct socket *sock, int proto)
static int bt_sock_create(struct net *net, struct socket *sock, int proto)
{
{
	int err;
	int err;
@@ -151,7 +156,7 @@ static int bt_sock_create(struct net *net, struct socket *sock, int proto)


	if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) {
	if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) {
		err = bt_proto[proto]->create(net, sock, proto);
		err = bt_proto[proto]->create(net, sock, proto);
		bt_reclassify_sock_lock(sock, proto);
		bt_sock_reclassify_lock(sock, proto);
		module_put(bt_proto[proto]->owner);
		module_put(bt_proto[proto]->owner);
	}
	}