From patchwork Mon May 9 13:24:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 9046791 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 11250BF29F for ; Mon, 9 May 2016 13:27:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7FF6A20115 for ; Mon, 9 May 2016 13:27:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D1EE4200FF for ; Mon, 9 May 2016 13:27:34 +0000 (UTC) Received: from localhost ([::1]:41387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azlDg-000572-Uy for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 May 2016 09:27:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azlBb-00018N-NS for qemu-devel@nongnu.org; Mon, 09 May 2016 09:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azlBW-00042J-IP for qemu-devel@nongnu.org; Mon, 09 May 2016 09:25:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azlBW-00042B-8t; Mon, 09 May 2016 09:25:18 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8D4AC000417; Mon, 9 May 2016 13:25:17 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-28.ams2.redhat.com [10.36.112.28]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u49DP4ci017024; Mon, 9 May 2016 09:25:16 -0400 From: Laurent Vivier To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Date: Mon, 9 May 2016 15:24:59 +0200 Message-Id: <1462800299-12641-6-git-send-email-lvivier@redhat.com> In-Reply-To: <1462800299-12641-1-git-send-email-lvivier@redhat.com> References: <1462800299-12641-1-git-send-email-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 09 May 2016 13:25:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/5] ppc: Remove a potential overflow in muldiv64() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The coccinelle script: scripts/coccinelle/overflow_muldiv64.cocci gives us a list of potential overflows in muldiv64() (the two first parameters are 64bit values). This patch fixes one, as the fix seems obvious: replace muldiv64(a, b, c) by muldiv64(b, a, c) as "a" and "b" are 64bit values but a <= NANOSECONDS_PER_SECOND. (10^9 -> 30bit value). Signed-off-by: Laurent Vivier --- hw/ppc/ppc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 38ff2e1..07ea47c 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -880,7 +880,7 @@ static int timebase_post_load(void *opaque, int version_id) host_ns = qemu_clock_get_ns(QEMU_CLOCK_HOST); ns_diff = MAX(0, host_ns - tb_remote->time_of_the_day_ns); migration_duration_ns = MIN(NANOSECONDS_PER_SECOND, ns_diff); - migration_duration_tb = muldiv64(migration_duration_ns, freq, + migration_duration_tb = muldiv64(freq, migration_duration_ns, NANOSECONDS_PER_SECOND); guest_tb = tb_remote->guest_timebase + MIN(0, migration_duration_tb);