Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5999400ybc; Wed, 27 Nov 2019 13:09:52 -0800 (PST) X-Google-Smtp-Source: APXvYqwmMg4Dj0VpRW+oCsiwD8dHD7rqfPJOwejJRbmQqVKRYii1S3wea2tC+K/4+3iqZPt0hERZ X-Received: by 2002:a17:906:394:: with SMTP id b20mr26776601eja.188.1574888991933; Wed, 27 Nov 2019 13:09:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888991; cv=none; d=google.com; s=arc-20160816; b=xB0POdBCaIcKodbkemM683cYjPw5dE4kX3gZVPx42O2rOuSSXs+qF1xLFFpxwQqLHD qXCgmkH/EA/IBgX88h4zfbhk8P9yONsPRPEN1IljUv8w/fZZOhWmofBLqRH3dTXjTSmI aT/Tm75dII9QJuBNNlrYXHFtC8jzo+oFIXIKGDKTI6aVJTMBsNgz0xeJkrdeHs8ZLD6O p4DBfBnorPH7ctPBut4NdNbCFbMX3RFhlZ4wIu5YHTcyaYajXvWTGoFt1t+KOX7SuSps Bwv2NnkDLFCBK3AKfXYx76wpTmdzPWPihvrFiEucNLSE57rpSed303bOv9fGzqPoORHs pMkw== 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=5Fwjzz1GFH31z5J+PSlecDs+whJO48w+BgDipA8aOro=; b=mxzJZ7h9m2b13lfM2+NdSvg20tC+w1QmCF04dTLqfYESEYxStyDy4NjbcxJElVK59C 7x4yQ/T+ntQGZUEGDg6a4TvtAHL7gwBq4Q7aXLCXaGP55OGXd607yznTtmhZlrLoP9yU sfVFAlV7x2b5ZLVgXjuWbN6nMopEwwMtoUwbXUgdjcuMGWbYDjBUb6z6R4yJ0+v7zyR4 dEm4d7m0w5/T6QMg80jqVnZ955ZOH736r2+xb91Xc31MlAcgfYtp80kQBjQc40GCas7a TLUhi3iV8ws5VMaVmE90OAFihaGksvr9ScBwc0o3jrqngdPiAXKDxhfAicn8ncB5R5Yz 1Rdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DrhGNOy9; 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 t30si12433422edi.207.2019.11.27.13.09.28; Wed, 27 Nov 2019 13:09:51 -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=DrhGNOy9; 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 S1732673AbfK0VHz (ORCPT + 99 others); Wed, 27 Nov 2019 16:07:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:34186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732664AbfK0VHy (ORCPT ); Wed, 27 Nov 2019 16:07:54 -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 41AF4217AB; Wed, 27 Nov 2019 21:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888873; bh=LbTcu3fT1fR+3pBF+m5MvIQGLlUtoffzpz127ClyU+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DrhGNOy9mLZieI3GPUbJ5yDF06fHkIlPwQIkrX2PPkQmxl/E4G727PzehaU4ew46n flEo3nGRXJNw2YO0sUWVaaVB8XGG2K7suCcLI+SAzTaX7EpY+neRO7exghATdFVesV SvPdjDVNBnbz5habLflcr8H1yBsxP8GMZBLrD0N8= 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.19 303/306] staging: comedi: usbduxfast: usbduxfast_ai_cmdtest rounding error Date: Wed, 27 Nov 2019 21:32:33 +0100 Message-Id: <20191127203136.861195377@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2004-2014 Bernd Porr, mail@berndporr.me.uk + * Copyright (C) 2004-2019 Bernd Porr, mail@berndporr.me.uk */ /* @@ -8,7 +8,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 */ @@ -22,6 +22,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. @@ -350,6 +351,7 @@ static int usbduxfast_ai_cmdtest(struct struct comedi_cmd *cmd) { int err = 0; + int err2 = 0; unsigned int steps; unsigned int arg; @@ -399,11 +401,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);