Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7994482ybl; Thu, 16 Jan 2020 08:57:00 -0800 (PST) X-Google-Smtp-Source: APXvYqz6eS8duLWHjMzjD3NOSgtVlhWsKlieUpfFdFVZTG0tQJBOcNKEWqCeBSCXHddNEEDjuqty X-Received: by 2002:aca:4306:: with SMTP id q6mr13093oia.54.1579193820415; Thu, 16 Jan 2020 08:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579193820; cv=none; d=google.com; s=arc-20160816; b=ID/MSavyymnKyXCg8PnGEqDUnojk0xchXAerOhI4ye7bMic8hBLLBViWCNSzyznWnj CzpOCgIYQUDqfcLmJUmAt72MSofXruYDoNW9dKYJf/sInMCI9XBT0hMkW7AmbK7cc7n0 lIzm6nkimiChP91MEzECs7j6OJ0wehwVad65P08BwhyjnEGPf3H8b/lRfGXYpo0TFy+O 2WfEy/CBOWIno7wgemmeqNAlbeE5BCAW6vJ4xyLZQdnZ9myDFT2qeKrhp/G8TIsZA9o8 rGiE1gXN+qY7oXOQLcj01HGq2UW25AjcCEbczhpJNUMqsuwzQreInkVJEw9vBezHj4r7 ThYA== 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=T//sThcXKSTre7JbuNkRu9aG73LLzu3DXSshmW5qXK0=; b=xc0Etx+LidCOV72yKaOccj6K7L3BCjyuJZCGvvO/Hmax91eOSumhBnfodsnHKhBFIs J7TN0O+j/9eQ0UX2pyj4YJbbD+GBU2MN05SLhOmyJdRKB3SrE0DGSWuf3UnyhTb5ZEKL z4viYKBdTaW824qc1dOJ3VSoiBDGPnsVtvPbb5/daxwSzrh5jIJajtIHwt3YmTQZo5YW JgHpP6qKaMLaGm1nGHneB831vp+xpvK4dRMCNj4goh2HgnYeEg7cGk48dRnhjlThvqnr pa2fVdpk7myM7xoWX50cb8pQ7Dyt9Q5XcNVq09+zA7NINWIN5bDfpF4f5oMzOWYtUBIN fKrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vk1VFZd/"; 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 q72si12411725oic.18.2020.01.16.08.56.48; Thu, 16 Jan 2020 08:57:00 -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="vk1VFZd/"; 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 S1733131AbgAPQz6 (ORCPT + 99 others); Thu, 16 Jan 2020 11:55:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:41224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbgAPQzk (ORCPT ); Thu, 16 Jan 2020 11:55:40 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 1D4DE214AF; Thu, 16 Jan 2020 16:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579193739; bh=LHmIffoarcO4UGzeOXpDU+X/XkVbG5AvRE/bVGXREaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vk1VFZd/wreID4VxEmxWG7v1NubeBw4+DkDRJaqeroHBy4rtHtkJcAELN8HjDN+Hn VcJohB08AVoll4Kg4AURlij3F36jJPxwH4cZxlyZL6rdZvutiQOCyq9DZ9PbuvAJcO M7ZD2yCFe6l+MbJcAc1lbl/FffE/dZELbRu1Lpoo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Spencer E. Olson" , Ian Abbott , Greg Kroah-Hartman , Sasha Levin , devel@driverdev.osuosl.org Subject: [PATCH AUTOSEL 4.19 031/671] staging: comedi: ni_mio_common: protect register write overflow Date: Thu, 16 Jan 2020 11:44:22 -0500 Message-Id: <20200116165502.8838-31-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116165502.8838-1-sashal@kernel.org> References: <20200116165502.8838-1-sashal@kernel.org> MIME-Version: 1.0 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: "Spencer E. Olson" [ Upstream commit 1cbca5852d6c16e85a21487a15d211195aacd4a1 ] Fixes two problems introduced as early as commit 03aef4b6dc12 ("Staging: comedi: add ni_mio_common code"): (1) Ensures that the last four bits of NISTC_RTSI_TRIGB_OUT_REG register is not unduly overwritten on e-series devices. On e-series devices, the first three of the last four bits are reserved. The last bit defines the output selection of the RGOUT0 pin, otherwise known as RTSI_Sub_Selection. For m-series devices, these last four bits are indeed used as the output selection of the RTSI7 pin (and the RTSI_Sub_Selection bit for the RGOUT0 pin is moved to the RTSI_Trig_Direction register. (2) Allows all 4 RTSI_BRD lines to be treated as valid sources for RTSI lines. This patch also cleans up the ni_get_rtsi_routing command for readability. Fixes: 03aef4b6dc12 ("Staging: comedi: add ni_mio_common code") Signed-off-by: Spencer E. Olson Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- .../staging/comedi/drivers/ni_mio_common.c | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index d799b1b55de3..747518c29542 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -4984,7 +4984,10 @@ static int ni_valid_rtsi_output_source(struct comedi_device *dev, case NI_RTSI_OUTPUT_G_SRC0: case NI_RTSI_OUTPUT_G_GATE0: case NI_RTSI_OUTPUT_RGOUT0: - case NI_RTSI_OUTPUT_RTSI_BRD_0: + case NI_RTSI_OUTPUT_RTSI_BRD(0): + case NI_RTSI_OUTPUT_RTSI_BRD(1): + case NI_RTSI_OUTPUT_RTSI_BRD(2): + case NI_RTSI_OUTPUT_RTSI_BRD(3): return 1; case NI_RTSI_OUTPUT_RTSI_OSC: return (devpriv->is_m_series) ? 1 : 0; @@ -5005,11 +5008,18 @@ static int ni_set_rtsi_routing(struct comedi_device *dev, devpriv->rtsi_trig_a_output_reg |= NISTC_RTSI_TRIG(chan, src); ni_stc_writew(dev, devpriv->rtsi_trig_a_output_reg, NISTC_RTSI_TRIGA_OUT_REG); - } else if (chan < 8) { + } else if (chan < NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series)) { devpriv->rtsi_trig_b_output_reg &= ~NISTC_RTSI_TRIG_MASK(chan); devpriv->rtsi_trig_b_output_reg |= NISTC_RTSI_TRIG(chan, src); ni_stc_writew(dev, devpriv->rtsi_trig_b_output_reg, NISTC_RTSI_TRIGB_OUT_REG); + } else if (chan != NISTC_RTSI_TRIG_OLD_CLK_CHAN) { + /* probably should never reach this, since the + * ni_valid_rtsi_output_source above errors out if chan is too + * high + */ + dev_err(dev->class_dev, "%s: unknown rtsi channel\n", __func__); + return -EINVAL; } return 2; } @@ -5025,12 +5035,12 @@ static unsigned int ni_get_rtsi_routing(struct comedi_device *dev, } else if (chan < NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series)) { return NISTC_RTSI_TRIG_TO_SRC(chan, devpriv->rtsi_trig_b_output_reg); - } else { - if (chan == NISTC_RTSI_TRIG_OLD_CLK_CHAN) - return NI_RTSI_OUTPUT_RTSI_OSC; - dev_err(dev->class_dev, "bug! should never get here?\n"); - return 0; + } else if (chan == NISTC_RTSI_TRIG_OLD_CLK_CHAN) { + return NI_RTSI_OUTPUT_RTSI_OSC; } + + dev_err(dev->class_dev, "%s: unknown rtsi channel\n", __func__); + return -EINVAL; } static int ni_rtsi_insn_config(struct comedi_device *dev, -- 2.20.1