Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1480559ybl; Thu, 22 Aug 2019 15:32:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7jWGykk8uev/Gb0d+5A32QQXiyqZ0wTjzRgi29FC8E7J1k7VxpI2h8LbcxqHeQrbkw6W8 X-Received: by 2002:a62:640e:: with SMTP id y14mr1612652pfb.222.1566513125031; Thu, 22 Aug 2019 15:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566513125; cv=none; d=google.com; s=arc-20160816; b=q5gffMyy/ITZEl3EZlWTUt3E4QxRtYXNpP6uWyOhjGe2hlvO1BDnEURmOKBtTCJuqT FENxq/zVWSwwGbshVBhRCI+DTlxUKPNrmNPk9H/UF2A0sGzzXHCyf81j5SxGlFrbbLgR DfIDb4dQQ5V5rdAMNAs1N3JMCXkV/IRj8F0ey+aMjPLYW9DuerJ1zuTLuEkL++lJhv/r zSStfPWpm3cQXGmhik+b4m4vf9FFRv8DVmAqie8OCwfwppcdPUBXRDEIRwYmCAL4namL sM2krqhzVt42b07x3atIlKjAXWDu2IodU74fcBF0p38ZtqidhKrESb3pGJCzGqjRN8x8 nHXw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xqOcYi9xlL8UP9DSgO30TNWzHWqU6a3vOCgwPcmp9/Q=; b=dI/lW0P43mUfAaoc7pajDh6XqM/uub9G0oiCmt4NwkStHEa/uel5SBJT/xSF6Lb8Ac UFOm3jjW02GpMiQDbXhXh8W6wgnCiDEoJZtL6lP/vdvcijCh7cWbGHNBG47t70nLk9wq 6tWZGyj3YGjPepGczEBSGbtiPxwW2jnrTA1uCOxw0dMuIJUrD+87XRO68cVHBBvdjOGA hCtfnQF1L0iFRnddeBUGRbybnpU9h9RdMnDpMLL8C1dOurFtNIaEk0ZJFkCNGYbkED1s ynOMNVNO9rHqVDQZYGpyiEAjg8Jcb3y6e3T6xHE/ph8umKOnswwsRAFm3urcIAEEg9bx WFtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="aWHd/DeT"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13si651246plz.242.2019.08.22.15.31.50; Thu, 22 Aug 2019 15:32:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b="aWHd/DeT"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391084AbfHVRMt (ORCPT + 99 others); Thu, 22 Aug 2019 13:12:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:59306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390654AbfHVRJG (ORCPT ); Thu, 22 Aug 2019 13:09:06 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 230A72342A; Thu, 22 Aug 2019 17:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493745; bh=yoK6E85K/l2xZlICnFSN1g8SzZTgncSSZLt/CSFHhmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aWHd/DeT/dd3eqJbYoyG8AmRUDXRDOLOC77kW4XKncclaUAIUO5OWLKbMj8KD/oxi sFb7EN2Q8yHu3tFKVpIxPdeY6Ixn4PaCnffnBYtcUjWkdO+0ijuVVXfLZXRNt9V/dS YlNfNwrW8aoDzViejEHYjZsOgVXHsGszwbHTydsc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ian Abbott , Greg Kroah-Hartman Subject: [PATCH 5.2 093/135] staging: comedi: dt3000: Fix rounding up of timer divisor Date: Thu, 22 Aug 2019 13:07:29 -0400 Message-Id: <20190822170811.13303-94-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Abbott commit 8e2a589a3fc36ce858d42e767c3bcd8fc62a512b upstream. `dt3k_ns_to_timer()` determines the prescaler and divisor to use to produce a desired timing period. It is influenced by a rounding mode and can round the divisor up, down, or to the nearest value. However, the code for rounding up currently does the same as rounding down! Fix ir by using the `DIV_ROUND_UP()` macro to calculate the divisor when rounding up. Also, change the types of the `divider`, `base` and `prescale` variables from `int` to `unsigned int` to avoid mixing signed and unsigned types in the calculations. Also fix a typo in a nearby comment: "improvment" => "improvement". Signed-off-by: Ian Abbott Cc: stable Link: https://lore.kernel.org/r/20190812120814.21188-1-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/dt3000.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c index 4ad176fc14ad1..caf4d4df4bd30 100644 --- a/drivers/staging/comedi/drivers/dt3000.c +++ b/drivers/staging/comedi/drivers/dt3000.c @@ -342,9 +342,9 @@ static irqreturn_t dt3k_interrupt(int irq, void *d) static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, unsigned int flags) { - int divider, base, prescale; + unsigned int divider, base, prescale; - /* This function needs improvment */ + /* This function needs improvement */ /* Don't know if divider==0 works. */ for (prescale = 0; prescale < 16; prescale++) { @@ -358,7 +358,7 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, divider = (*nanosec) / base; break; case CMDF_ROUND_UP: - divider = (*nanosec) / base; + divider = DIV_ROUND_UP(*nanosec, base); break; } if (divider < 65536) { -- 2.20.1