From patchwork Fri Oct 11 09:07:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 11185105 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA81514DB for ; Fri, 11 Oct 2019 09:12:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CB7C02084C for ; Fri, 11 Oct 2019 09:12:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB7C02084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIqy1-0004az-IC for patchwork-qemu-devel@patchwork.kernel.org; Fri, 11 Oct 2019 05:12:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49509) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIqtM-0005we-57 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 05:07:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIqtL-0004BC-5P for qemu-devel@nongnu.org; Fri, 11 Oct 2019 05:07:20 -0400 Received: from relay.sw.ru ([185.231.240.75]:60310) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIqtH-000476-OP; Fri, 11 Oct 2019 05:07:15 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIqtD-0000XM-Vc; Fri, 11 Oct 2019 12:07:12 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 1/5] hbitmap: handle set/reset with zero length Date: Fri, 11 Oct 2019 12:07:07 +0300 Message-Id: <20191011090711.19940-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011090711.19940-1-vsementsov@virtuozzo.com> References: <20191011090711.19940-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Passing zero length to these functions leads to unpredicted results. Zero-length set/reset may occur in active-mirror, on zero-length write (which is unlikely, but not guaranteed to never happen). Let's just do nothing on zero-length request. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- util/hbitmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/util/hbitmap.c b/util/hbitmap.c index fd44c897ab..86b0231046 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -387,6 +387,10 @@ void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t count) uint64_t first, n; uint64_t last = start + count - 1; + if (count == 0) { + return; + } + trace_hbitmap_set(hb, start, count, start >> hb->granularity, last >> hb->granularity); @@ -477,6 +481,10 @@ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count) uint64_t first; uint64_t last = start + count - 1; + if (count == 0) { + return; + } + trace_hbitmap_reset(hb, start, count, start >> hb->granularity, last >> hb->granularity);