Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1238978pxu; Mon, 23 Nov 2020 15:37:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNXUAltp7PNtRWrmM+U7JKUw8GhfWh8F9idsm2kbxwQ2X/eUHO0XMMsGeTqiJjeL/ei24D X-Received: by 2002:aa7:cb4c:: with SMTP id w12mr1498957edt.309.1606174674301; Mon, 23 Nov 2020 15:37:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174674; cv=none; d=google.com; s=arc-20160816; b=DZmAF1l2jxUkz/7EFrf0MyfV9j00ULMbFCLa2Dg00M9q/n4Pj4FjFwMXc2GSDWFLmx yqo+R0wPcWJlUis54c/ma5wq6wDHCF0OAdr9q5BBhga3D1ltYluaGnTkmp/MRB4Wfl+i +B11qjTyzdTl3qjshrVqGwRoRDTWB3f2JEDORGQEloUfQLGj+GQrOpABVCqBBwCCb5BH rvkHiK9ofYrwQc76ZtpuI2SN6+C1sP2vyn0YDoou4RnlE8e2nf7QYcuGndaMSHR63CdW cen0gM/fO6ztTDedlseSK0ZWCUrqOHDCK5CUiEBJVbDzyR3XGuBho6Yk4pFhmTNnB0ep M/7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zYzt8LUmY2Z+ajhjgClkR2UhLYJAS7Izy06HvsIcVM8=; b=ft8jpBWtv3ydTo0kZ+mXWizRvQfPLdd/IY5BCAhpYZYWuhwTXiXHuHSbE7aPyfwT8k LIoPDiY/ozdHihj94iMipUG4MwSBuji+1oYlcuadxrAOg/SShQyD+Q9BmwsiZOqVpukB MqMaPfF8L4fhWXqzWecB5M48LC2oFus+QtDOpkJ61zSnVclkrfeTP8e2apx7YqoSFg/M rFRidbnDettBHH0xdIOn01EoIL802iItenRVXc6yuGQU/l+a6FpSoZC9Ek0DBwzEzdwz o8J1V1RfIDvd4hAIPWLFQ1FbIycgi08o5jo4EEDEKNcnd+nnMbds6rA8366UtwzKbRXB Nb4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TQZ7b6rZ; 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 d5si7231158ejr.394.2020.11.23.15.37.31; Mon, 23 Nov 2020 15:37:54 -0800 (PST) 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=TQZ7b6rZ; 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 S1732100AbgKWMia (ORCPT + 99 others); Mon, 23 Nov 2020 07:38:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:50528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732049AbgKWMiG (ORCPT ); Mon, 23 Nov 2020 07:38:06 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 6DC1D20732; Mon, 23 Nov 2020 12:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135084; bh=DrJb/ry/H3aPSpWFoAtR8cOM79J66ZPdh5HPDRRvztY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TQZ7b6rZjNYmXM0ibYS46E2Mtg/sU4FXUqq0CzXcoSTtUvSn4szW57u1N9dDTRodU 6TxT1K2juyxxvreUwMW8isAuM97ii1TnDa1u7QfHgSF89PJ6kgYQOS4x14Vn7cQi1y IA/DgAyXCTfN8WSR85J5OhkB8bzTEkJ2PPJgaPx0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.4 099/158] can: flexcan: flexcan_chip_start(): fix erroneous flexcan_transceiver_enable() during bus-off recovery Date: Mon, 23 Nov 2020 13:22:07 +0100 Message-Id: <20201123121824.710096846@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Kleine-Budde [ Upstream commit cd9f13c59461351d7a5fd07924264fb49b287359 ] If the CAN controller goes into bus off, the do_set_mode() callback with CAN_MODE_START can be used to recover the controller, which then calls flexcan_chip_start(). If configured, this is done automatically by the framework or manually by the user. In flexcan_chip_start() there is an explicit call to flexcan_transceiver_enable(), which does a regulator_enable() on the transceiver regulator. This results in a net usage counter increase, as there is no corresponding flexcan_transceiver_disable() in the bus off code path. This further leads to the transceiver stuck enabled, even if the CAN interface is shut down. To fix this problem the flexcan_transceiver_enable()/flexcan_transceiver_disable() are moved out of flexcan_chip_start()/flexcan_chip_stop() into flexcan_open()/flexcan_close(). Fixes: e955cead0311 ("CAN: Add Flexcan CAN controller driver") Link: https://lore.kernel.org/r/20201118150148.2664024-1-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/flexcan.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index b22cd8d14716a..1bd955e4c7d66 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -1202,14 +1202,10 @@ static int flexcan_chip_start(struct net_device *dev) priv->write(reg_mecr, ®s->mecr); } - err = flexcan_transceiver_enable(priv); - if (err) - goto out_chip_disable; - /* synchronize with the can bus */ err = flexcan_chip_unfreeze(priv); if (err) - goto out_transceiver_disable; + goto out_chip_disable; priv->can.state = CAN_STATE_ERROR_ACTIVE; @@ -1226,8 +1222,6 @@ static int flexcan_chip_start(struct net_device *dev) return 0; - out_transceiver_disable: - flexcan_transceiver_disable(priv); out_chip_disable: flexcan_chip_disable(priv); return err; @@ -1257,7 +1251,6 @@ static int __flexcan_chip_stop(struct net_device *dev, bool disable_on_error) priv->write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL, ®s->ctrl); - flexcan_transceiver_disable(priv); priv->can.state = CAN_STATE_STOPPED; return 0; @@ -1293,10 +1286,14 @@ static int flexcan_open(struct net_device *dev) if (err) goto out_runtime_put; - err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev); + err = flexcan_transceiver_enable(priv); if (err) goto out_close; + err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev); + if (err) + goto out_transceiver_disable; + priv->mb_size = sizeof(struct flexcan_mb) + CAN_MAX_DLEN; priv->mb_count = (sizeof(priv->regs->mb[0]) / priv->mb_size) + (sizeof(priv->regs->mb[1]) / priv->mb_size); @@ -1352,6 +1349,8 @@ static int flexcan_open(struct net_device *dev) can_rx_offload_del(&priv->offload); out_free_irq: free_irq(dev->irq, dev); + out_transceiver_disable: + flexcan_transceiver_disable(priv); out_close: close_candev(dev); out_runtime_put: @@ -1370,6 +1369,7 @@ static int flexcan_close(struct net_device *dev) can_rx_offload_del(&priv->offload); free_irq(dev->irq, dev); + flexcan_transceiver_disable(priv); close_candev(dev); pm_runtime_put(priv->dev); -- 2.27.0