Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3300546ybb; Tue, 31 Mar 2020 02:25:14 -0700 (PDT) X-Google-Smtp-Source: ADFU+vskmuDgNRcOgNko9ZKk3dKVcnb/bs8qOgVS36JV0/UlJoGvouOaa6Jp+kKgzqu5mQso6YXw X-Received: by 2002:a4a:3306:: with SMTP id q6mr10019237ooq.81.1585646714217; Tue, 31 Mar 2020 02:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585646714; cv=none; d=google.com; s=arc-20160816; b=jhQI9R/6GmzejZDrNJ0FtQPcDaxX+JoLdnPqhtIq3+HMmjOhHgNSv7b7vshC59zkSL GY5ESDyNSIB8s5diBcl3bvFO4YLMxln6BGUPfBeounKlKSlicPjx7cjAaAEYGICQJ6Zl XnDplfPEZ/YPgKq/jLwqG+qyqMcw1KYSrzvXZZ3CyrX5my7fF1+Dve/hw3Ss+EC5AFRZ aGSipCD/5/7TYi8pA21MxDXqX+J5EzeV5P6d4eEvn2IM8X4CW3pvxBRdFKBkQIoHExRd 1n7HsCtZcj6bIbwBtoIzWlshBI+UHqOIxQLBhnuhTgnmidVnB3vjhHhz/Ixcf8K2xyQI AG4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=kN5+s+x9+6gdWCPe/jaSQAx6k7/V/+KKt5W9BglApCo=; b=erwqt3BOSakZaQz8alTNPmCX+/zHlfiG8mcn70JEp1JW3kMwWjckenHJSrm3xUDF9R IDchXV3NXNwuQNiIgQQ3G8ytYCfEGCRQdmdRFXUmQQ3slBgEG8XTbu91XJs9EDD1cRwA Q1L5oGpugAD9fTqpOuBz7KaVRXGLwjJKjvzjzZzT7atnlECqUZg8K9szeRMbYnEBZuvP JwL33q5ntB8ijG8iBxn364OwYQSi1Yq3/K2YqzwposYuIZKvxc746Id86C3KKQ2Ex7k+ NyiS/weKnyIvhpit3M+Aor4Fx8kYhnmy5DblzKw4cpWir+/ZZO/2oOzE6q5TVUMgE8Jn W8wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=QbfqucLX; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a128si7078447oif.202.2020.03.31.02.24.50; Tue, 31 Mar 2020 02:25:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=QbfqucLX; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730284AbgCaJXH (ORCPT + 99 others); Tue, 31 Mar 2020 05:23:07 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:47098 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730559AbgCaJD4 (ORCPT ); Tue, 31 Mar 2020 05:03:56 -0400 Received: by mail-lj1-f195.google.com with SMTP id r7so13471082ljg.13 for ; Tue, 31 Mar 2020 02:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=kN5+s+x9+6gdWCPe/jaSQAx6k7/V/+KKt5W9BglApCo=; b=QbfqucLXgVw4s0z1Ut8WN9zRY0xUTOGDADbjoql/cX8tapIV1nvyzoEqu/e0+CLev3 AH7jaXdz21D9AhRDRxPZfdFO0ModNU5W029geLtwu/s6jZ9nxojTMg5d4UjfqML3p6wa 18NWVEDGWG/k8cEOStRvXmTGWLptILxuwCHoJRst/FV011wHZ4bOzgJ28CYn7QyHYfn1 /h2EpuoTpfnlPR+RWp+Gp8uRJKwhbdZIJCZV2gCUZOIdUAcImcNvv2uuNLiCk1lvACf4 GlA9saORyF+GGUjzQQ66utghkb4oOZdiVBzYellpuvHm0z/mlcGpUoKJkr6ncN0aA4e2 0NMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=kN5+s+x9+6gdWCPe/jaSQAx6k7/V/+KKt5W9BglApCo=; b=bfNqhL0ERz7ov7MnPL5c5CTKZ1cLmyeJH1KVAmxuE93/GpNEVPLn0z3Cm+u3WhwPmE oA9zkyO4loYBzP/kwo8XwQQFBWVI+YPWY9Ie7fY3IpzCSbcasiGebSSxZZBc7X/08qda +oZlljt4EigUbEK4h1rBxLbMA4He9ndH5sOK4gCS98cyYsrnqpCjuqrdyCb7DfxMvBeU jI89B5DQg6b5AUPo5QsrYDj/S+tKZGlBMW4YCGqPj6hXzwliTbX6mknO2cPBOFLePVL9 5407d3ZFpOIiU/HRh/GVXMhBq3Q5O9PYl7wpKiDaPxgSBK3+Z05jFY0YL9fPFDMl67dI EtiA== X-Gm-Message-State: AGi0PuZeqAyXVaeN3oLXYH2Sp24N2Oa4FxVJDAy0wkrwAdJjS8LZ8mnx H72cb5d1HTd4DuBf/YtbvHCHg5jXe0HbuQ== X-Received: by 2002:a2e:b4e9:: with SMTP id s9mr9537587ljm.108.1585645434008; Tue, 31 Mar 2020 02:03:54 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id j13sm2603668lfb.6.2020.03.31.02.03.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 02:03:53 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2] mesh: Fix FPE in overcommit logic. Date: Tue, 31 Mar 2020 11:04:00 +0200 Message-Id: <20200331090400.18379-1-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org During overcommit, mesh_config_save is called in asynchronous mode to avoid blocking Send() calls. This means that update of cfg->write_time is scheduled via l_idle_oneshot, so if the next Send() gets scheduled first, the code may see elapsed time of zero. If this happens, then the overcommit logic was already executed and the overcommit is pending, so we can just return. --- Fixed the commit log, sorry. mesh/mesh-config-json.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index ad2d4d0f8..21f2cfc37 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -2014,6 +2014,12 @@ bool mesh_config_write_seq_number(struct mesh_config *cfg, uint32_t seq, timersub(&now, &cfg->write_time, &elapsed); elapsed_ms = elapsed.tv_sec * 1000 + elapsed.tv_usec / 1000; + /* If time since last write is zero, this means that + * idle_save_config is already pending, so we don't need to do + * anything. */ + if (!elapsed_ms) + return true; + cached = seq + (seq - cfg->write_seq) * 1000 * MIN_SEQ_CACHE_TIME / elapsed_ms; -- 2.20.1