Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8552463ybl; Thu, 16 Jan 2020 19:25:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzVz0i3q7b3EpG64rSZOmeZ8RAf4/BCixDU5h4e68Fx6Dm0L3zk6HmFswDBmLT+DNSW8wTP X-Received: by 2002:a05:6830:1e99:: with SMTP id n25mr4770204otr.67.1579231516148; Thu, 16 Jan 2020 19:25:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579231516; cv=none; d=google.com; s=arc-20160816; b=ex0rGeARdjhCrKWGBnLFCrDhlJ6Asvk95L+WNwSaA7UxavBoLnDMR2WjMfk4zVTs5g a+m3y9QmlgwSTp5KMnz2Mah4dOexWToOIDrT6MqFfQMWnZgnpHuD/OPseGbv201cdAOx tCkfhEesQZpBMZU5FBL7/raLwJRN9ni2OB1dPzM+pIE3zirlMidIAcbWWKrK9AJVvDXt BmktVO4vwXSzqzZ2ld0vCXGQy1ie7ehS2F3muDL7mBXnKl8RusVFgVHamVFGLDBOakY/ uwq/7IDPjweVk4Y8YLnIngP86ri6Q9KEue6FbJeb11xP/77lHENl87T7CYqwpwsrnAL4 tNAw== 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=odKCJEgbxOy6rZTNDSMVepwJTC6qROBOO8uRZZQfJI4=; b=lwufH13DJpDlcrDY9S5IXeZAdU+VZPv6bWdthWh4mO/aKCw67RCfFxK2aMxaOi5Jpp J+PyqNA2qa0xa6jJV1q6U2vkEdB+RAftXZk460ODyY/1Q5Oo1DRCBphuqjzgD6gwlUYu BwlV+RXaVmDwAsxG1dAjlYzoBmxFOIb3UjHc9MpeGvkkeYjyJm/BybSGalQdivij+Qgd zzqI7N2oHfS+LtP+0vIOVSGBoRz7ORCni00U6rx/1sOCOcHY7KLhGiE+d2OQFmr8/gRM BdaoupPL4E9mdzYYUXLx22cqmHRj5HSOEqZiUBk3XhPVas0Tf+JU0gjXpft7qHSWM36S dCXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OCj7lwHw; 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 s68si13659773oih.275.2020.01.16.19.25.03; Thu, 16 Jan 2020 19:25:16 -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=OCj7lwHw; 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 S2404353AbgAPXd1 (ORCPT + 99 others); Thu, 16 Jan 2020 18:33:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:43790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391515AbgAPXdZ (ORCPT ); Thu, 16 Jan 2020 18:33:25 -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 F11582072E; Thu, 16 Jan 2020 23:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579217605; bh=k7jLbKDGZ4iRjIZ4qzQ6bAEV+npIVuYrJOHBHWLt2XU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OCj7lwHwEscI7rhL8hRRoqUmD1hyGiSVxKW4dFplHlIYFE5pmjp2pq8kuqGD9X4ID P0rWajqH+1i/U27UEMEPKv3xgRLP1Fd2yLd67gpHwhqbIpzwS+NpEnxz3Rin08t8l4 L2S9a9usrb0sjGUZfk0AW8Owre71GvR5aabBFPew= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Stultz , Vinod Koul , Sasha Levin Subject: [PATCH 4.14 67/71] dmaengine: k3dma: Avoid null pointer traversal Date: Fri, 17 Jan 2020 00:19:05 +0100 Message-Id: <20200116231718.663178995@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200116231709.377772748@linuxfoundation.org> References: <20200116231709.377772748@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: John Stultz [ Upstream commit 2f42e05b942fe2fbfb9bbc6e34e1dd8c3ce4f3a4 ] In some cases we seem to submit two transactions in a row, which causes us to lose track of the first. If we then cancel the request, we may still get an interrupt, which traverses a null ds_run value. So try to avoid starting a new transaction if the ds_run value is set. While this patch avoids the null pointer crash, I've had some reports of the k3dma driver still getting confused, which suggests the ds_run/ds_done value handling still isn't quite right. However, I've not run into an issue recently with it so I think this patch is worth pushing upstream to avoid the crash. Signed-off-by: John Stultz [add ss tag] Link: https://lore.kernel.org/r/20191218190906.6641-1-john.stultz@linaro.org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/k3dma.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/dma/k3dma.c b/drivers/dma/k3dma.c index 219ae3b545db..803045c92f3b 100644 --- a/drivers/dma/k3dma.c +++ b/drivers/dma/k3dma.c @@ -222,9 +222,11 @@ static irqreturn_t k3_dma_int_handler(int irq, void *dev_id) c = p->vchan; if (c && (tc1 & BIT(i))) { spin_lock_irqsave(&c->vc.lock, flags); - vchan_cookie_complete(&p->ds_run->vd); - p->ds_done = p->ds_run; - p->ds_run = NULL; + if (p->ds_run != NULL) { + vchan_cookie_complete(&p->ds_run->vd); + p->ds_done = p->ds_run; + p->ds_run = NULL; + } spin_unlock_irqrestore(&c->vc.lock, flags); } if (c && (tc2 & BIT(i))) { @@ -264,6 +266,10 @@ static int k3_dma_start_txd(struct k3_dma_chan *c) if (BIT(c->phy->idx) & k3_dma_get_chan_stat(d)) return -EAGAIN; + /* Avoid losing track of ds_run if a transaction is in flight */ + if (c->phy->ds_run) + return -EAGAIN; + if (vd) { struct k3_dma_desc_sw *ds = container_of(vd, struct k3_dma_desc_sw, vd); -- 2.20.1