Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5985648ybc; Wed, 27 Nov 2019 12:56:17 -0800 (PST) X-Google-Smtp-Source: APXvYqyX2hXTxbaNDZdKhIi4jDuIEZIbXAR7NJlZfSK7sahQlODVJKQo0bYqEWn1V0b9w1/4Px5r X-Received: by 2002:a05:6402:1692:: with SMTP id a18mr34792039edv.297.1574888177732; Wed, 27 Nov 2019 12:56:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888177; cv=none; d=google.com; s=arc-20160816; b=fBgpATMPIiQ0CP0rlbNDhbOH9xH4P2e5D3myFGNVlLa8vjnYb4wOCH7ZwCZblSd1xG B0RFGZyR55wK+EPwmf9TCvRgrB/uq8jYXN+BLj+fdZGs4XlMIu+7DRfnom6Ag4AqEsBU yAxmP0wEUYsVIzlmo8jCPWErf5lOQTbZvNBm903sxYF33RutJYbR11h+VXcsyZr36ZAv 1xnk7tWDXcZ/imPuB+cG9ri5FIUNaLgu6ZUTs07GPG4ogLOtBEkk+uQbwuE4DAHS8uhW mJH+tj/tQKn8+43+016rlg3jfKuuAjVwf4VNPqgr8w0w2c3/IWiD7sT+xxt9wM1F7Znl DmsA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JdCpQDs2t7KlAk9aN6SVwbPFjFURnP7hCiuw2mMaixU=; b=buwnndSwW8qNFQIMZRiI3Q4PHeobRmcXvvOGIP1NAHrAD+10qRxDbF+DGn2ypEfZ6U oqBt/qXE+5xTXZ/XCvycaBfh7J1E2OH61FCEdaAIQf3Gnnp2tdjwWYFd2vXHAYE+FB0U zbdmrH3MXzJEjpWUwd7kIFbDv41AudvG2uT0NVs4T30Lz2ym6CK3nAqCmGZNZU9yiS3c FWctqm7+IJYagCvmvPNeuGTt+EzY7k97yZs4IbLwbtUe9S56OluM5iwMTdKmiH1eqTle XqzfLVPSjxt64D+OQXHEo9GAcRTpMpP+yKhSyFijXLLbEYQkeOJKkztxTuXIR4d++YBm kuPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ovZki9SJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z40si11411610edz.114.2019.11.27.12.55.54; Wed, 27 Nov 2019 12:56:17 -0800 (PST) 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=ovZki9SJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730850AbfK0Uyn (ORCPT + 99 others); Wed, 27 Nov 2019 15:54:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:44734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730847AbfK0Uyi (ORCPT ); Wed, 27 Nov 2019 15:54:38 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 11B882068E; Wed, 27 Nov 2019 20:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888077; bh=gla/T9epZxieOxWiss8ElTZqXZOTcBewGKHUizRHzyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ovZki9SJ8+9gv14VYj+44wsZ3xAOemxCNWFfYNNqF1I6k6qiZFLA8+98NXtYQujz6 czjWGuxaaKyRJHdyfD9o0Wfg0L5vcyrFA8j6ajhqQ/VZ1QRzbVKUUP/IAZAOKSxJMO 5v89TP11ecbBaPxps5P3VJF0VQ+JsF/2u+OrXlMY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bernd Porr , Ian Abbott Subject: [PATCH 4.14 207/211] staging: comedi: usbduxfast: usbduxfast_ai_cmdtest rounding error Date: Wed, 27 Nov 2019 21:32:20 +0100 Message-Id: <20191127203113.085267201@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bernd Porr commit 5618332e5b955b4bff06d0b88146b971c8dd7b32 upstream. The userspace comedilib function 'get_cmd_generic_timed' fills the cmd structure with an informed guess and then calls the function 'usbduxfast_ai_cmdtest' in this driver repeatedly while 'usbduxfast_ai_cmdtest' is modifying the cmd struct until it no longer changes. However, because of rounding errors this never converged because 'steps = (cmd->convert_arg * 30) / 1000' and then back to 'cmd->convert_arg = (steps * 1000) / 30' won't be the same because of rounding errors. 'Steps' should only be converted back to the 'convert_arg' if 'steps' has actually been modified. In addition the case of steps being 0 wasn't checked which is also now done. Signed-off-by: Bernd Porr Cc: # 4.4+ Reviewed-by: Ian Abbott Link: https://lore.kernel.org/r/20191118230759.1727-1-mail@berndporr.me.uk Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/usbduxfast.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) --- a/drivers/staging/comedi/drivers/usbduxfast.c +++ b/drivers/staging/comedi/drivers/usbduxfast.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2014 Bernd Porr, mail@berndporr.me.uk + * Copyright (C) 2004-2019 Bernd Porr, mail@berndporr.me.uk * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ * Description: University of Stirling USB DAQ & INCITE Technology Limited * Devices: [ITL] USB-DUX-FAST (usbduxfast) * Author: Bernd Porr - * Updated: 10 Oct 2014 + * Updated: 16 Nov 2019 * Status: stable */ @@ -31,6 +31,7 @@ * * * Revision history: + * 1.0: Fixed a rounding error in usbduxfast_ai_cmdtest * 0.9: Dropping the first data packet which seems to be from the last transfer. * Buffer overflows in the FX2 are handed over to comedi. * 0.92: Dropping now 4 packets. The quad buffer has to be emptied. @@ -359,6 +360,7 @@ static int usbduxfast_ai_cmdtest(struct struct comedi_cmd *cmd) { int err = 0; + int err2 = 0; unsigned int steps; unsigned int arg; @@ -408,11 +410,16 @@ static int usbduxfast_ai_cmdtest(struct */ steps = (cmd->convert_arg * 30) / 1000; if (cmd->chanlist_len != 1) - err |= comedi_check_trigger_arg_min(&steps, - MIN_SAMPLING_PERIOD); - err |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD); - arg = (steps * 1000) / 30; - err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg); + err2 |= comedi_check_trigger_arg_min(&steps, + MIN_SAMPLING_PERIOD); + else + err2 |= comedi_check_trigger_arg_min(&steps, 1); + err2 |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD); + if (err2) { + err |= err2; + arg = (steps * 1000) / 30; + err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg); + } if (cmd->stop_src == TRIG_COUNT) err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);