Skip to content

Commit 18f8124

Browse files
holtmannJohan Hedberg
authored andcommitted
Bluetooth: Move {min,max}_key_size debugfs into hci_debugfs_create_le
The debugfs entries for {min,max}_key_size are created during SMP registration and thus it might lead to multiple attempts to create the same entries. Avoid this by moving them to the LE controller init section. Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Johan Hedberg <[email protected]>
1 parent cc97400 commit 18f8124

File tree

2 files changed

+61
-93
lines changed

2 files changed

+61
-93
lines changed

net/bluetooth/hci_debugfs.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <net/bluetooth/bluetooth.h>
2727
#include <net/bluetooth/hci_core.h>
2828

29+
#include "smp.h"
2930
#include "hci_debugfs.h"
3031

3132
#define DEFINE_QUIRK_ATTRIBUTE(__name, __quirk) \
@@ -989,6 +990,62 @@ static int adv_max_interval_get(void *data, u64 *val)
989990
DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
990991
adv_max_interval_set, "%llu\n");
991992

993+
static int min_key_size_set(void *data, u64 val)
994+
{
995+
struct hci_dev *hdev = data;
996+
997+
if (val > hdev->le_max_key_size || val < SMP_MIN_ENC_KEY_SIZE)
998+
return -EINVAL;
999+
1000+
hci_dev_lock(hdev);
1001+
hdev->le_min_key_size = val;
1002+
hci_dev_unlock(hdev);
1003+
1004+
return 0;
1005+
}
1006+
1007+
static int min_key_size_get(void *data, u64 *val)
1008+
{
1009+
struct hci_dev *hdev = data;
1010+
1011+
hci_dev_lock(hdev);
1012+
*val = hdev->le_min_key_size;
1013+
hci_dev_unlock(hdev);
1014+
1015+
return 0;
1016+
}
1017+
1018+
DEFINE_SIMPLE_ATTRIBUTE(min_key_size_fops, min_key_size_get,
1019+
min_key_size_set, "%llu\n");
1020+
1021+
static int max_key_size_set(void *data, u64 val)
1022+
{
1023+
struct hci_dev *hdev = data;
1024+
1025+
if (val > SMP_MAX_ENC_KEY_SIZE || val < hdev->le_min_key_size)
1026+
return -EINVAL;
1027+
1028+
hci_dev_lock(hdev);
1029+
hdev->le_max_key_size = val;
1030+
hci_dev_unlock(hdev);
1031+
1032+
return 0;
1033+
}
1034+
1035+
static int max_key_size_get(void *data, u64 *val)
1036+
{
1037+
struct hci_dev *hdev = data;
1038+
1039+
hci_dev_lock(hdev);
1040+
*val = hdev->le_max_key_size;
1041+
hci_dev_unlock(hdev);
1042+
1043+
return 0;
1044+
}
1045+
1046+
DEFINE_SIMPLE_ATTRIBUTE(max_key_size_fops, max_key_size_get,
1047+
max_key_size_set, "%llu\n");
1048+
9921049
static int auth_payload_timeout_set(void *data, u64 val)
9931050
{
9941051
struct hci_dev *hdev = data;
@@ -1071,6 +1128,10 @@ void hci_debugfs_create_le(struct hci_dev *hdev)
10711128
&adv_max_interval_fops);
10721129
debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
10731130
&hdev->discov_interleaved_timeout);
1131+
debugfs_create_file("min_key_size", 0644, hdev->debugfs, hdev,
1132+
&min_key_size_fops);
1133+
debugfs_create_file("max_key_size", 0644, hdev->debugfs, hdev,
1134+
&max_key_size_fops);
10741135
debugfs_create_file("auth_payload_timeout", 0644, hdev->debugfs, hdev,
10751136
&auth_payload_timeout_fops);
10761137

net/bluetooth/smp.c

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,94 +3373,6 @@ static const struct file_operations force_bredr_smp_fops = {
33733373
.llseek = default_llseek,
33743374
};
33753375

3376-
static ssize_t le_min_key_size_read(struct file *file,
3377-
char __user *user_buf,
3378-
size_t count, loff_t *ppos)
3379-
{
3380-
struct hci_dev *hdev = file->private_data;
3381-
char buf[4];
3382-
3383-
snprintf(buf, sizeof(buf), "%2u\n", hdev->le_min_key_size);
3384-
3385-
return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
3386-
}
3387-
3388-
static ssize_t le_min_key_size_write(struct file *file,
3389-
const char __user *user_buf,
3390-
size_t count, loff_t *ppos)
3391-
{
3392-
struct hci_dev *hdev = file->private_data;
3393-
char buf[32];
3394-
size_t buf_size = min(count, (sizeof(buf) - 1));
3395-
u8 key_size;
3396-
3397-
if (copy_from_user(buf, user_buf, buf_size))
3398-
return -EFAULT;
3399-
3400-
buf[buf_size] = '\0';
3401-
3402-
sscanf(buf, "%hhu", &key_size);
3403-
3404-
if (key_size > hdev->le_max_key_size ||
3405-
key_size < SMP_MIN_ENC_KEY_SIZE)
3406-
return -EINVAL;
3407-
3408-
hdev->le_min_key_size = key_size;
3409-
3410-
return count;
3411-
}
3412-
3413-
static const struct file_operations le_min_key_size_fops = {
3414-
.open = simple_open,
3415-
.read = le_min_key_size_read,
3416-
.write = le_min_key_size_write,
3417-
.llseek = default_llseek,
3418-
};
3419-
3420-
static ssize_t le_max_key_size_read(struct file *file,
3421-
char __user *user_buf,
3422-
size_t count, loff_t *ppos)
3423-
{
3424-
struct hci_dev *hdev = file->private_data;
3425-
char buf[4];
3426-
3427-
snprintf(buf, sizeof(buf), "%2u\n", hdev->le_max_key_size);
3428-
3429-
return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
3430-
}
3431-
3432-
static ssize_t le_max_key_size_write(struct file *file,
3433-
const char __user *user_buf,
3434-
size_t count, loff_t *ppos)
3435-
{
3436-
struct hci_dev *hdev = file->private_data;
3437-
char buf[32];
3438-
size_t buf_size = min(count, (sizeof(buf) - 1));
3439-
u8 key_size;
3440-
3441-
if (copy_from_user(buf, user_buf, buf_size))
3442-
return -EFAULT;
3443-
3444-
buf[buf_size] = '\0';
3445-
3446-
sscanf(buf, "%hhu", &key_size);
3447-
3448-
if (key_size > SMP_MAX_ENC_KEY_SIZE ||
3449-
key_size < hdev->le_min_key_size)
3450-
return -EINVAL;
3451-
3452-
hdev->le_max_key_size = key_size;
3453-
3454-
return count;
3455-
}
3456-
3457-
static const struct file_operations le_max_key_size_fops = {
3458-
.open = simple_open,
3459-
.read = le_max_key_size_read,
3460-
.write = le_max_key_size_write,
3461-
.llseek = default_llseek,
3462-
};
3463-
34643376
int smp_register(struct hci_dev *hdev)
34653377
{
34663378
struct l2cap_chan *chan;
@@ -3485,11 +3397,6 @@ int smp_register(struct hci_dev *hdev)
34853397

34863398
hdev->smp_data = chan;
34873399

3488-
debugfs_create_file("le_min_key_size", 0644, hdev->debugfs, hdev,
3489-
&le_min_key_size_fops);
3490-
debugfs_create_file("le_max_key_size", 0644, hdev->debugfs, hdev,
3491-
&le_max_key_size_fops);
3492-
34933400
/* If the controller does not support BR/EDR Secure Connections
34943401
* feature, then the BR/EDR SMP channel shall not be present.
34953402
*

0 commit comments

Comments
 (0)