From patchwork Wed Oct 29 17:48:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tina Ruchandani X-Patchwork-Id: 5193881 X-Patchwork-Delegate: tiwai@suse.de Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 508F4C11AC for ; Thu, 30 Oct 2014 06:30:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 853AD20351 for ; Thu, 30 Oct 2014 06:30:40 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 813DA2034B for ; Thu, 30 Oct 2014 06:30:35 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 85E122651FC; Thu, 30 Oct 2014 07:30:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 3BFEA260521; Thu, 30 Oct 2014 07:29:56 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 3C59E260511; Wed, 29 Oct 2014 18:48:24 +0100 (CET) Received: from mail-ie0-f175.google.com (mail-ie0-f175.google.com [209.85.223.175]) by alsa0.perex.cz (Postfix) with ESMTP id F24472604D4 for ; Wed, 29 Oct 2014 18:48:14 +0100 (CET) Received: by mail-ie0-f175.google.com with SMTP id y20so1125648ier.34 for ; Wed, 29 Oct 2014 10:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=9QXp5Col8hjh6OaUvIgLlkAjfTvvS3iT47bEYRw84BA=; b=cywfS0OZFjuCBu9py0HBAzzjpzuwkwQ5rgdoJpNWESpe1FUEuaivcf7VqhS6yg1cGp 6LIB/mkz/mlrIiQ+kmXEA36sRY+/h88Hc4QZShuNx+neXrCIRetw2TfXy+IXIZ1ko6wr h+uAArhCLt3ShPmLUfkF19BlBvTsyHiFHvj6Rs6t9g0Bf4vsGCo/bPWrJtzKc7wuQaXN qddWyRf7BhyBZyNjbfx4YTcJcJM49bdPs/baSIeQZffg3mQWzBpfB+cMFYdkPjoqZ7+H Phydy0ypItxipKk3dsAWTKgBOa8xXLpcBnmtMPAl9wp+x6Z/903GJobiex2fmSwRa4vU qDIg== X-Received: by 10.107.31.202 with SMTP id f193mr13820001iof.16.1414604893449; Wed, 29 Oct 2014 10:48:13 -0700 (PDT) Received: from localhost ([100.100.98.187]) by mx.google.com with ESMTPSA id gb12sm8239844igd.0.2014.10.29.10.48.12 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 29 Oct 2014 10:48:12 -0700 (PDT) Date: Wed, 29 Oct 2014 10:48:10 -0700 From: Tina Ruchandani To: tiwai@suse.de, arnd@arndb.de Message-ID: <20141029174810.GA48058@localhost> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Mailman-Approved-At: Thu, 30 Oct 2014 07:29:54 +0100 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [alsa-devel] [PATCH] ALSA: es1968: Replace timeval with ktime_t X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP es1968_measure_clock uses struct timeval, which on 32-bit systems will overflow in 2038, leading to incorrect interpretation of time.This patch changes the function to use ktime_t instead of struct timeval, which implies: - no y2038: ktime_t uses a 64-bit datatype explicitly. - efficent subtraction: The earlier version computes the difference in usecs while dealing with secs and nsecs. It requires checks to see if the nsecs of stop is less than start. This patch uses a direct subtract of ktime_t and converts to usecs. - use of monotonic clock (ktime_get) over real time (do_gettimeofday), which simplifies timekeeping, as it does not have to deal with cases where stop_time is less than start_time. Signed-off-by: Tina Ruchandani Reviewed-by: Arnd Bergmann --- sound/pci/es1968.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c index a9956a7..6039700 100644 --- a/sound/pci/es1968.c +++ b/sound/pci/es1968.c @@ -1710,7 +1710,8 @@ static void es1968_measure_clock(struct es1968 *chip) int i, apu; unsigned int pa, offset, t; struct esm_memory *memory; - struct timeval start_time, stop_time; + ktime_t start_time, stop_time; + ktime_t diff; if (chip->clock == 0) chip->clock = 48000; /* default clock value */ @@ -1761,12 +1762,12 @@ static void es1968_measure_clock(struct es1968 *chip) snd_es1968_bob_inc(chip, ESM_BOB_FREQ); __apu_set_register(chip, apu, 5, pa & 0xffff); snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR); - do_gettimeofday(&start_time); + start_time = ktime_get(); spin_unlock_irq(&chip->reg_lock); msleep(50); spin_lock_irq(&chip->reg_lock); offset = __apu_get_register(chip, apu, 5); - do_gettimeofday(&stop_time); + stop_time = ktime_get(); snd_es1968_trigger_apu(chip, apu, 0); /* stop */ snd_es1968_bob_dec(chip); chip->in_measurement = 0; @@ -1777,12 +1778,8 @@ static void es1968_measure_clock(struct es1968 *chip) offset &= 0xfffe; offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2); - t = stop_time.tv_sec - start_time.tv_sec; - t *= 1000000; - if (stop_time.tv_usec < start_time.tv_usec) - t -= start_time.tv_usec - stop_time.tv_usec; - else - t += stop_time.tv_usec - start_time.tv_usec; + diff = ktime_sub(stop_time, start_time); + t = ktime_to_us(diff); if (t == 0) { dev_err(chip->card->dev, "?? calculation error..\n"); } else {