bt_gatt_client_set_security could fail if the security level is already BT_ATT_SECURITY_MEDIUM. So, get and check the security level before setting it. Signed-off-by: Jiayang Mao <quic_jiaymao@xxxxxxxxxxx> --- profiles/input/hog.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/profiles/input/hog.c b/profiles/input/hog.c index 017e320f0..011cc0a88 100644 --- a/profiles/input/hog.c +++ b/profiles/input/hog.c @@ -191,8 +191,10 @@ static int hog_accept(struct btd_service *service) return -ECONNREFUSED; client = btd_device_get_gatt_client(device); - if (!bt_gatt_client_set_security(client, - BT_ATT_SECURITY_MEDIUM)) + if (BT_ATT_SECURITY_MEDIUM != + bt_gatt_client_get_security(client) && + !bt_gatt_client_set_security(client, + BT_ATT_SECURITY_MEDIUM)) return -ECONNREFUSED; } -- 2.25.1