Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5367917pxv; Wed, 21 Jul 2021 03:54:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTvVBMtRmZZQvALw7z8AFfcuF6arhnKzi3smuuTcvG4PppjEVdHQE3gKPh00OF5txVPMDB X-Received: by 2002:a92:3206:: with SMTP id z6mr23821688ile.201.1626864858859; Wed, 21 Jul 2021 03:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626864858; cv=none; d=google.com; s=arc-20160816; b=Lyg93zE6M2Dk6xvKsKHAnmOWK4lJqqkZ3rdKdttc6w0YtuWyQcI6XMfdTOcRvAsDWZ 7HKWadS6LJgan84H37d4IcLRkWYDeIq5mXMJuqE2wmt/4EwmkhyAg4AVcnxrWyS18aNg JDQsOlVq/zar/fFIby95tDbH8VW6iC8Gj1j0QsdMerbbpJywAuROoEJOWluDlWsI1/w7 2Nixq4ERWwVlvk0g1kGWnWyWr5JBMiM9bjanuqKEFOc4rj0VN0F5OlnW/zrODDmtG9df P5yks/NE6s340FNGnVlPtz1dBQlUEA+wyEgg9yk6Y2YbWKTZR/BGvnAr/q886IC0j57U /RmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8gOOcc1q9g9RGsPpjKAoexnRgkwfh92smZiAJgShg5w=; b=R/PHzIaIuSdpGYjco2d9dYlUFacby3c5YHdiXEe9aUSlOpEWG35UiDuIB17F4LDqNf onBORlP9dsmjvwdUDtG+imG3+VG42JZne8IRCMCXFsF/Z3Z0GM0B1YZ1NrAf47qhSlm2 GaQF8oOFXXe7c9M5wqsMe0sRlAjeb+xGbqzs9Fr3Yq3kLa/SWhk4kMP4REa4zhReyxtj ylfOfaMobcn4Snw8p0N07wQ9CKgJ75sXlNmTIVpbIjKa6sQzm9raR+kBFU4kD+2I5xPS bYmGA8riVas+1C9lnVw7/sNwVpy67+tVD1MMVVWs07kEpqiJkzi4TsIcyYV6WWl3bVhc nxFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I3WtQXqE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si15968254jan.106.2021.07.21.03.54.07; Wed, 21 Jul 2021 03:54:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I3WtQXqE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238632AbhGUKIs (ORCPT + 99 others); Wed, 21 Jul 2021 06:08:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:58690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239487AbhGUKFd (ORCPT ); Wed, 21 Jul 2021 06:05:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 851FC60238; Wed, 21 Jul 2021 10:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626864369; bh=lekz1x8Vr+mtj6/j1CLlcAW/8TwIhmgKM8+wU/jnTd4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I3WtQXqEESn30zVXhTZ7Rf7axCV+VRasQnprlkR/u7LSKrlVylGYfkUewLhoVp/fD IJedpcadAQ0QHFTl0SxxRdlu3rgGAekSV4pzAQKudjBQLW1i2XbfTFGXtpKAp6cjKL fgNulM80bhGQechPnYIiFF3/dCAs0n+WaEjdVWuE= Date: Wed, 21 Jul 2021 12:46:06 +0200 From: Greg KH To: Zhiyong Tao Cc: timur@kernel.org, linux@armlinux.org.uk, alcooperx@gmail.com, tklauser@distanz.ch, sean.wang@kernel.org, srv_heupstream@mediatek.com, hui.liu@mediatek.com, yuchen.huang@mediatek.com, huihui.wang@mediatek.com, eddie.huang@mediatek.com, sean.wang@mediatek.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-serial@vger.kernel.org Subject: Re: [PATCH] uart: mediatek: fix memory corruption issue Message-ID: References: <20210710090103.2643-1-zhiyong.tao@mediatek.com> <20210710090103.2643-2-zhiyong.tao@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210710090103.2643-2-zhiyong.tao@mediatek.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 10, 2021 at 05:01:03PM +0800, Zhiyong Tao wrote: > This patch is used to fix memory corruption issue when rx power off. > 1. add spin lock in mtk8250_dma_rx_complete function in APDMA mode. What does a lock protect from? Please be explicit and detailed. > 2. add processing mechanism which count value is 0 What does this do? And why is it needed? > > Signed-off-by: Zhiyong Tao What commit does this fix? Does this need to go to stable kernel trees? If so, how far back? > --- > drivers/tty/serial/8250/8250_mtk.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c > index f7d3023f860f..09f7d2166315 100644 > --- a/drivers/tty/serial/8250/8250_mtk.c > +++ b/drivers/tty/serial/8250/8250_mtk.c > @@ -91,12 +91,15 @@ static void mtk8250_dma_rx_complete(void *param) > struct mtk8250_data *data = up->port.private_data; > struct tty_port *tty_port = &up->port.state->port; > struct dma_tx_state state; > - int copied, total, cnt; > + unsigned int copied, total, cnt; > unsigned char *ptr; > + unsigned long flags; > > if (data->rx_status == DMA_RX_SHUTDOWN) > return; > > + spin_lock_irqsave(&up->port.lock, flags); > + > dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); > total = dma->rx_size - state.residue; > cnt = total; > @@ -104,9 +107,11 @@ static void mtk8250_dma_rx_complete(void *param) > if ((data->rx_pos + cnt) > dma->rx_size) > cnt = dma->rx_size - data->rx_pos; > > - ptr = (unsigned char *)(data->rx_pos + dma->rx_buf); > - copied = tty_insert_flip_string(tty_port, ptr, cnt); > - data->rx_pos += cnt; > + if (cnt != 0) { Why does cnt matter here? If cnt is 0, the code above should not do anything at all, right? Or if it does, should we change tty_insert_flip_string() to always check for cnt != 0 before it does the first loop? Hm, it looks like it will abort if cnt is 0, so what is this change really doing? Why do you need it? What is it "fixing"? thanks, greg k-h