From patchwork Thu Jan 17 20:20:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 259 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 883B060C99 for ; Thu, 17 Jan 2019 21:20:49 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1585C53E; Thu, 17 Jan 2019 21:20:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547756449; bh=6eiqsPmV12U1svjkzaXOSeM2wvyiYx1BHjNTRtf1rwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lw1shtIAaJrMRneOwA9P9DjCjnRPBPXmHyAb3OZ1i4u9hkJwhcI/jPkIooZwftxFd 9st0kZJS+VTBgWofi6QW4oHOQifo8AkKVsDbn8kC2W+rjGFLPzoQaFpXhB6p1DmmnZ 1F6BDpY5a6lNgGDYSXy3ywdw4uuybKnOyxl3gh2c= From: Kieran Bingham To: LibCamera Devel Date: Thu, 17 Jan 2019 20:20:41 +0000 Message-Id: <20190117202043.21420-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190117202043.21420-1-kieran.bingham@ideasonboard.com> References: <20190117202043.21420-1-kieran.bingham@ideasonboard.com> Subject: [libcamera-devel] [PATCH 3/5] libcamera: timer: Fix 32 bit wrap X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2019 20:20:49 -0000 The msec parameter was multiplied as a 32 bit value when converting to nanosecond resolution. This wraps at 4.2949 seconds, and causes timers longer than this to fail. Fix the multiplication to upcast to 64 bit using an unsigned long long specifier on the multiplier. While we're here, initialise the two integer class members in the constructor initialiser list. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/timer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index b5212ba26869..306825fde3c0 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -36,6 +36,7 @@ namespace libcamera { * \brief Construct a timer */ Timer::Timer() + : interval_(0), deadline_(0) { } @@ -51,7 +52,7 @@ void Timer::start(unsigned int msec) clock_gettime(CLOCK_MONOTONIC, &tp); interval_ = msec; - deadline_ = tp.tv_sec * 1000000000ULL + tp.tv_nsec + msec * 1000000; + deadline_ = tp.tv_sec * 1000000000ULL + tp.tv_nsec + msec * 1000000ULL; LOG(Debug) << "Starting timer " << this << " with interval " << msec << ": deadline " << deadline_;