Received: by 2002:aa6:c429:0:b029:98:93ff:f56f with SMTP id g9csp3394010lkq; Mon, 23 Nov 2020 04:42:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRAZkm8jutDBHMOerAl5VWVptQI5MUra7O8mgjNdNGsfK1WcDb2U/hKMf8YxY5UiOBNfkf X-Received: by 2002:a17:906:2b81:: with SMTP id m1mr4203750ejg.251.1606135355591; Mon, 23 Nov 2020 04:42:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606135355; cv=none; d=google.com; s=arc-20160816; b=R018uwbfDPvvbUdtuz8RZ2OZPAjjRebxn3Ai5JRL9OVXEbGzGrIKBU5Ked3yY5RVnS HU07u/WW8V3kpr3tYFe1HzqhgaIxX5HsYeOtrIOc+YA2UeV70rWgGRt+YhEDvCg0s8DG q8d1Cx2glUpzO1xLD2mQZakZ0Of12GyaEdJpYTHrr30h2XcZRiFRquhRQZ8l7KpGbJG9 IPXRt0YNAHTk93CMd9/Ptb6hwx77bARLirD2R6trfo5jhVw+Q3NgeBW1ZrJJn9ukf9Fv kWp2gI5vrc7NreGEyrLLwunmWQpyfwWc2t86N6+ALv6ZftvTcYBVAIHQdk6GW8Akoh32 8wYg== 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=FC432S5TurMPsHdGmjQskIh5jEV59vp050uM73xfqjE=; b=H07mu6rbFxBqF1r3L26nRSppoK0I9xQ1C4CjtafSkr8ZE+ie9svYBM8mYmHPQ9nwrv M0IXg3+9CS9iqhtp8FXr3RFaZVY+7TP6AS2/XMnpTFSMaRcRbngbMpiwsUcBkRGfsnjm DtFe4QcUzxvLUi4h5RzjY+Q5lVhJ9dPHlelATjv0kCQrN46uqS/fB9gyawCnOie+rnWJ NKXgJH3trfIDStPta5Hz/YAKz11zy9RUTBdGEIiK2XxoYq1QnGWUDCNGitFy1KyAu5PG zbCnJLgQwVJ5XrpTzGu4Jpi0xa0PmDhQ8WlkS4XqwR82fYg8UB23a7OY/CNq4wYA+yON m3jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TZrRsAxO; 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 pj7si6188623ejb.254.2020.11.23.04.42.12; Mon, 23 Nov 2020 04:42:35 -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=TZrRsAxO; 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 S1731918AbgKWMhW (ORCPT + 99 others); Mon, 23 Nov 2020 07:37:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:49586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731901AbgKWMhR (ORCPT ); Mon, 23 Nov 2020 07:37:17 -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 40DC72076E; Mon, 23 Nov 2020 12:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135036; bh=S/vGdyUBSIet9wkp1y1hSa15PkXBOLfclbHDU1OECCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZrRsAxOMu9ylBrdKsMkq9eOJnHtYTifA4SjCCw7gcSHIbs/Na2DjEQxyUKRf/xrG aysX0Zl/vc8qycB9iHF3AkUv9rl2E6CRdVL/oX9RxAYjSaoaOlTzJ2dOPteojHlpQp ek4bKxBylsk319/3lNCicgj2oJnOCdYy9WOmx/zM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Qilong , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.4 081/158] can: flexcan: fix failure handling of pm_runtime_get_sync() Date: Mon, 23 Nov 2020 13:21:49 +0100 Message-Id: <20201123121823.838877636@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: Zhang Qilong [ Upstream commit b7ee5bc3e1006433601a058a6a7c24c5272635f4 ] pm_runtime_get_sync() will increment pm usage at first and it will resume the device later. If runtime of the device has error or device is in inaccessible state(or other error state), resume operation will fail. If we do not call put operation to decrease the reference, it will result in reference leak in the two functions flexcan_get_berr_counter() and flexcan_open(). Moreover, this device cannot enter the idle state and always stay busy or other non-idle state later. So we should fix it through adding pm_runtime_put_noidle(). Fixes: ca10989632d88 ("can: flexcan: implement can Runtime PM") Signed-off-by: Zhang Qilong Link: https://lore.kernel.org/r/20201108083000.2599705-1-zhangqilong3@huawei.com Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/flexcan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index 130f3022d3396..b22cd8d14716a 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -614,8 +614,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev, int err; err = pm_runtime_get_sync(priv->dev); - if (err < 0) + if (err < 0) { + pm_runtime_put_noidle(priv->dev); return err; + } err = __flexcan_get_berr_counter(dev, bec); @@ -1282,8 +1284,10 @@ static int flexcan_open(struct net_device *dev) int err; err = pm_runtime_get_sync(priv->dev); - if (err < 0) + if (err < 0) { + pm_runtime_put_noidle(priv->dev); return err; + } err = open_candev(dev); if (err) -- 2.27.0