Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp945505pxf; Wed, 7 Apr 2021 15:46:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+UM24oAY2MB1pA45CJX2/HU/aAMKfrHSKc6GeOnV/8mxW5LADJ3ZawA4ErjqZ6+1PJLo9 X-Received: by 2002:a17:907:2666:: with SMTP id ci6mr6583362ejc.361.1617835572661; Wed, 07 Apr 2021 15:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617835572; cv=none; d=google.com; s=arc-20160816; b=t8T8Ky1nANpgE/bJnoZWFAcppbxtl5vGg1ErstA9hycsUxddYCamLYHuwyjggceYJs aZbKBhAkR2fKYSTVHRmOxS+Gs3daM5lCm4QxiQ1l5Dhkv6/iEWW507/vc82PrwbJbMOn GAVFb6CTau4X39HfOO9eiv4J3bbiIP7v8VSbRE6fmYz9hUyACdcEV6uTd2vwpNzgea9f GT8IJt6NhRihDzd4e+1fWNOLDQK4QbF+xsxQQDhuJ7K1tFKxfoo0X+ONR9f0SvmsWJYn qrWqrg5QRuhQLYEcMlHrLXuvHO9Apy0lymytoKKsTCxSJFf0RVVcX00FY7pxRs95g9jc /oEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0W0S+BklYkH2JwKgMoATRJz2kgJOT7a5wwQMUj1rys0=; b=S8pHE7q639Nlkz6woy7L1nEXQ6sePegpjQykl42q2/VVeQ+GwG3Ff8ajAy8Py37yoR 2fjk23BKDnWD23ynFk3XfbiRi5ELN/CYgjgbQWSevkbh0WsEBTiOw65odygFDhQiFWQf bw6C7dCa6uvUeiMnVjRMKx2cfnQ5QnAGV7Bg16+LhvKYYn9u1VZx+F4Y0bsl0Ijq3zUg K8QVY3I2d4orgm7dex2yIEUkJOn/zZ4DzbhWCUvgrFNRhJEGJNw37tXku5CaDnxwcNPD ke0cDtLiBg2EdRYc3HZ6JfrV0bQyiL770eQ6KXdRqeLSA85z/GyiExGA1rkM1Ok0ubDK j1Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kSgZfY3c; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si19127582ejf.345.2021.04.07.15.45.50; Wed, 07 Apr 2021 15:46:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kSgZfY3c; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230495AbhDGWfY (ORCPT + 99 others); Wed, 7 Apr 2021 18:35:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbhDGWfY (ORCPT ); Wed, 7 Apr 2021 18:35:24 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C8A9C061760 for ; Wed, 7 Apr 2021 15:35:14 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id y32so10938032pga.11 for ; Wed, 07 Apr 2021 15:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0W0S+BklYkH2JwKgMoATRJz2kgJOT7a5wwQMUj1rys0=; b=kSgZfY3cR/r/tZYgWssEPPA5LNxGbyAa6COL8dMlxnB6WYfmYxH/iWBEFn/SDBYGAo DW4W8DYFzlKPy1KznJgjXVYnjcuQ27ZO8cMjmrtiTmykXWs2fVan8wIC/KoVmG7ycIbi k3/++vZ091z9jjBBQyMDrd903j6ZBLQkpXE6A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0W0S+BklYkH2JwKgMoATRJz2kgJOT7a5wwQMUj1rys0=; b=uYTDITVDH8POk0noKZQ8rCURqDOeFWwAjx9rpJXKvzmbJ92fOyMbf7o4h+dbTWnO5T a1Aror2R263wTLY4VFtLE7gqk88bW7iCyGYiH4ZKSpv/v+OF/06G34WUi+2ldD+Yqsid s3DkNSp2gJKpQIo9KA9hF5ERy8NhQbHgmvzVQv4sT5euaAMlt4BuzLgGlN5TpU5CAARM j+2nCFYCtH7Ys5dnCJafzAlz3GyEmmstEnne90og4cxK+ev8CWMTZhdY1OWCo0/zoHD8 Xl+m1AmbrE7qKMpA2Vh0ARmvdYK71kNzeTa5EA/PjkVTWHYllBXq5WLPelqUYAZOwOts 7rEQ== X-Gm-Message-State: AOAM531IrODmW2h7VHUBHnnnjiu61/DO8eOLwCVaTnsuP3RRz8lb4s4P fUYopjftqNpmUI+PKHKlMG8pJMQEb/WJWw== X-Received: by 2002:aa7:9533:0:b029:241:9d92:92e1 with SMTP id c19-20020aa795330000b02902419d9292e1mr4890057pfp.14.1617834913464; Wed, 07 Apr 2021 15:35:13 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:c572:df03:d9fe:57c5]) by smtp.gmail.com with ESMTPSA id r26sm16382115pgn.15.2021.04.07.15.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Apr 2021 15:35:13 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Dmitry Torokhov Subject: [PATCH BlueZ] input/hog-lib: add error handling when calling into gatt Date: Wed, 7 Apr 2021 15:35:09 -0700 Message-Id: <20210407223509.28997-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Dmitry Torokhov When calling gatt_write_char(), gatt_read_char(), etc, id == 0 indicates error. Let's recognize this fact and log it instead of queueing request that will never be completed. --- profiles/input/hog-lib.c | 77 +++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 6ac14e401..668f8047a 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -166,13 +166,16 @@ static void write_char(struct bt_hog *hog, GAttrib *attrib, uint16_t handle, return; id = gatt_write_char(attrib, handle, value, vlen, func, req); - - if (set_and_store_gatt_req(hog, req, id)) + if (!id) { + error("hog: Could not write char"); return; + } - error("hog: Could not read char"); - g_attrib_cancel(attrib, id); - free(req); + if (!set_and_store_gatt_req(hog, req, id)) { + error("hog: Failed to queue write char req"); + g_attrib_cancel(attrib, id); + free(req); + } } static void read_char(struct bt_hog *hog, GAttrib *attrib, uint16_t handle, @@ -190,13 +193,16 @@ static void read_char(struct bt_hog *hog, GAttrib *attrib, uint16_t handle, return; id = gatt_read_char(attrib, handle, func, req); - - if (set_and_store_gatt_req(hog, req, id)) + if (!id) { + error("hog: Could not read char"); return; + } - error("hog: Could not read char"); - g_attrib_cancel(attrib, id); - free(req); + if (!set_and_store_gatt_req(hog, req, id)) { + error("hog: Failed to queue read char req"); + g_attrib_cancel(attrib, id); + free(req); + } } static void discover_desc(struct bt_hog *hog, GAttrib *attrib, @@ -211,12 +217,16 @@ static void discover_desc(struct bt_hog *hog, GAttrib *attrib, return; id = gatt_discover_desc(attrib, start, end, NULL, func, req); - if (set_and_store_gatt_req(hog, req, id)) + if (!id) { + error("hog: Could not discover descriptors"); return; + } - error("hog: Could not discover descriptors"); - g_attrib_cancel(attrib, id); - free(req); + if (!set_and_store_gatt_req(hog, req, id)) { + error("hog: Failed to queue discover descriptors req"); + g_attrib_cancel(attrib, id); + free(req); + } } static void discover_char(struct bt_hog *hog, GAttrib *attrib, @@ -232,13 +242,16 @@ static void discover_char(struct bt_hog *hog, GAttrib *attrib, return; id = gatt_discover_char(attrib, start, end, uuid, func, req); - - if (set_and_store_gatt_req(hog, req, id)) + if (!id) { + error("hog: Could not discover characteristic"); return; + } - error("hog: Could not discover characteristic"); - g_attrib_cancel(attrib, id); - free(req); + if (!set_and_store_gatt_req(hog, req, id)) { + error("hog: Failed to queue discover characteristic req"); + g_attrib_cancel(attrib, id); + free(req); + } } static void discover_primary(struct bt_hog *hog, GAttrib *attrib, @@ -253,13 +266,16 @@ static void discover_primary(struct bt_hog *hog, GAttrib *attrib, return; id = gatt_discover_primary(attrib, uuid, func, req); - - if (set_and_store_gatt_req(hog, req, id)) + if (!id) { + error("hog: Could not send discover primary"); return; + } - error("hog: Could not send discover primary"); - g_attrib_cancel(attrib, id); - free(req); + if (!set_and_store_gatt_req(hog, req, id)) { + error("hog: Failed to queue discover primary req"); + g_attrib_cancel(attrib, id); + free(req); + } } static void find_included(struct bt_hog *hog, GAttrib *attrib, @@ -274,13 +290,16 @@ static void find_included(struct bt_hog *hog, GAttrib *attrib, return; id = gatt_find_included(attrib, start, end, func, req); - - if (set_and_store_gatt_req(hog, req, id)) + if (!id) { + error("hog: Could not find included"); return; + } - error("Could not find included"); - g_attrib_cancel(attrib, id); - free(req); + if (!set_and_store_gatt_req(hog, req, id)) { + error("hog: Failed to queue find included req"); + g_attrib_cancel(attrib, id); + free(req); + } } static void report_value_cb(const guint8 *pdu, guint16 len, gpointer user_data) -- 2.31.0