Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2024736pxa; Mon, 3 Aug 2020 05:41:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzWyABBAA0xVVOO5HViOy9We3X7YjOHEn6GVgueV1D9fxMhN9itn5xjR2NU0voh9+AIlS0 X-Received: by 2002:a17:906:7f05:: with SMTP id d5mr16104161ejr.122.1596458484728; Mon, 03 Aug 2020 05:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596458484; cv=none; d=google.com; s=arc-20160816; b=WjuLa+Q/wmYtXuJxFPO95TgM9oSzWmp4z74vJk88YHpen1HfVdav4DbZs3u4rnEDSj NHjjguDZvPvyhCIsACX/yqxrdJsgqxPqNkWkEliR0k3K/x0xIbZNBjIHeP5d/eKdNjrM nkJMSTZCmBVgmgRaxGPW68bwDKQbkmfNxQl0u8dPWB9HrDmJI7AmVqNwMYH0NuUV675f Qw/d0D58l5tqB7uZkQM4zLBc3Z4eRxPmKAUYlI+prRxM/Kwv2UhXwQPvhF63LN3M+uxY ac7kLut1ZSLmhmtPEu3XpnsMpl4++gxpjgve5y99mhn8zVsSDMzEcI5pVhb2R3UbCHJ9 MMfg== 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=SvqdoLUON60u2eEISocLlAEN3MChJIR5GtVfNJW75eg=; b=tqKHJVE6Ko5NjnOLdAMSwmR2null1inzCwnVjEsHnhXePEheX/5DQzCNbGmoPLHpo9 8ZmiY7uRN5MxlvSDROGT+NBpLOCfhYOCKKoPGP6wjIEwrW1tpLXCfzDBkyqKZPirRoLr Vmj2Y4IipXnexOReNTMMz27+XUc6wrgQ+D1Xnhw6XylH5dU2LDUSFd9oCJop9O7xdofO r1nT3VHiYMPlNTS/qvQJx5dSZYwceajLiVFeyshb8zpWcLf8g6z0Aaa9Dr3VlIL2RM3w m7vYV9vfyU+4280iW2q67sEyyn4x6YnsTMWIVg2tS8x8OxzBErnq4/jgd3PZkAsB6t8K uGjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YXCbffeK; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nm6si8625556ejb.336.2020.08.03.05.41.02; Mon, 03 Aug 2020 05:41:24 -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=@kernel.org header.s=default header.b=YXCbffeK; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728400AbgHCMkw (ORCPT + 99 others); Mon, 3 Aug 2020 08:40:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:60986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728592AbgHCMc5 (ORCPT ); Mon, 3 Aug 2020 08:32:57 -0400 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 F3FD62054F; Mon, 3 Aug 2020 12:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457976; bh=bgAddR/u870zWR7NHJFFnORjmWhzCSF1Zmk3C6mtp4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YXCbffeKbZEK6byME6mUEYifM8zgKOzfQleKqrkSY+CIGT+5A3dwnl4HpKS0sfVmR NdymAb7uXH0TXrrFqhWvJyH+khXloIqTCIThQ7vPn59ODkmwtqeZwC52/LmfsdK7Ra 6CtSllgZ68NRlncxX3JszMM7WaZ1g+8sUCApj1kk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dirk Behme , Yoshihiro Shimoda , Sergei Shtylyov , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 50/56] net: ethernet: ravb: exit if re-initialization fails in tx timeout Date: Mon, 3 Aug 2020 14:20:05 +0200 Message-Id: <20200803121852.769062363@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121850.306734207@linuxfoundation.org> References: <20200803121850.306734207@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: Yoshihiro Shimoda [ Upstream commit 015c5d5e6aa3523c758a70eb87b291cece2dbbb4 ] According to the report of [1], this driver is possible to cause the following error in ravb_tx_timeout_work(). ravb e6800000.ethernet ethernet: failed to switch device to config mode This error means that the hardware could not change the state from "Operation" to "Configuration" while some tx and/or rx queue are operating. After that, ravb_config() in ravb_dmac_init() will fail, and then any descriptors will be not allocaled anymore so that NULL pointer dereference happens after that on ravb_start_xmit(). To fix the issue, the ravb_tx_timeout_work() should check the return values of ravb_stop_dma() and ravb_dmac_init(). If ravb_stop_dma() fails, ravb_tx_timeout_work() re-enables TX and RX and just exits. If ravb_dmac_init() fails, just exits. [1] https://lore.kernel.org/linux-renesas-soc/20200518045452.2390-1-dirk.behme@de.bosch.com/ Reported-by: Dirk Behme Signed-off-by: Yoshihiro Shimoda Reviewed-by: Sergei Shtylyov Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/renesas/ravb_main.c | 26 ++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index faaf74073a120..569e698b5c807 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1445,6 +1445,7 @@ static void ravb_tx_timeout_work(struct work_struct *work) struct ravb_private *priv = container_of(work, struct ravb_private, work); struct net_device *ndev = priv->ndev; + int error; netif_tx_stop_all_queues(ndev); @@ -1453,15 +1454,36 @@ static void ravb_tx_timeout_work(struct work_struct *work) ravb_ptp_stop(ndev); /* Wait for DMA stopping */ - ravb_stop_dma(ndev); + if (ravb_stop_dma(ndev)) { + /* If ravb_stop_dma() fails, the hardware is still operating + * for TX and/or RX. So, this should not call the following + * functions because ravb_dmac_init() is possible to fail too. + * Also, this should not retry ravb_stop_dma() again and again + * here because it's possible to wait forever. So, this just + * re-enables the TX and RX and skip the following + * re-initialization procedure. + */ + ravb_rcv_snd_enable(ndev); + goto out; + } ravb_ring_free(ndev, RAVB_BE); ravb_ring_free(ndev, RAVB_NC); /* Device init */ - ravb_dmac_init(ndev); + error = ravb_dmac_init(ndev); + if (error) { + /* If ravb_dmac_init() fails, descriptors are freed. So, this + * should return here to avoid re-enabling the TX and RX in + * ravb_emac_init(). + */ + netdev_err(ndev, "%s: ravb_dmac_init() failed, error %d\n", + __func__, error); + return; + } ravb_emac_init(ndev); +out: /* Initialise PTP Clock driver */ if (priv->chip_id == RCAR_GEN2) ravb_ptp_init(ndev, priv->pdev); -- 2.25.1