From patchwork Sun Mar 12 21:34:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Baatz X-Patchwork-Id: 9619557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D5DFA60417 for ; Sun, 12 Mar 2017 21:44:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE3F927D13 for ; Sun, 12 Mar 2017 21:44:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1D9D28449; Sun, 12 Mar 2017 21:44:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CC51F27D13 for ; Sun, 12 Mar 2017 21:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=df7Ys6OwhJKPq8B4aEUeYZxBP6AHMD9IBwHa0HlP4ak=; b=q9C J1Ru1JMbBxplX5jx2W1xWUrkJuJj97wvcnXcql4agXs/oshmmrHMLkzQEB+XPKzx3TtRFLvl5K/yR Vuv+IB9FXBpUpQpYIdb9u8PBeo5oq5+6FA4LO+G2ulicJmJbuaXC3ZLpPWOgY04dWrDILKMygUqV0 n+bekQb431on41YbbZHO4iGvwADMyjHxybqinSvog6Ym34IQLhZAlToJuU9BO85zID5Z6NFGsZhJl q77Nwtwxqz82CIEvra8wcrjsfd53w5x+yZ8j79fSGUMk0Bp7xLgJYGaOblxbrrojXYyl204PI37CR yAIbTsQ+XCFHfubqGQ4M7NSgvlaNDmQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cnBHw-0005Wi-6J; Sun, 12 Mar 2017 21:44:28 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cnBHr-0005Ua-SI; Sun, 12 Mar 2017 21:44:26 +0000 Received: by mail-wm0-x242.google.com with SMTP id z63so7189376wmg.2; Sun, 12 Mar 2017 14:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=tC1x2EJP7lh8nY56tn+RybZaoaQO/GFeERG39AHGOz4=; b=ga5Ru4BWXUIbIAcbtKAJs6fSIWg8/rxSd7cs3V4bGniQJQKYDAIBqN4qEETLqYrXXp td7EcggYybLqauvula9Vs36PePSNWZ6zVwkXpfbP7C15jV6nz9Nc551uxGYbsrsvpxSS CsZ8dV7+q+3NaQUdHA0ZBsTnND33LTBGEjNEWHPGXhyeiH0Ut9uUTWlxTW7RC9l6I5au 26TTGr6VJlJPbXmtB0eifWrF1i/2maqxL79LNN8apsgmgA444qSVcFxooCUcGJPR9yMm RtSIq87E7P/NMbwvUmqSdxL1pCCh4JIFYwWdekDYgQXPbwVnQSO1vgi4TBRcCt4+OZYT X0Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tC1x2EJP7lh8nY56tn+RybZaoaQO/GFeERG39AHGOz4=; b=tnfS80KblhlVUbfTBoYVVf1U8gc8t4cH7z0sB4NLeDeJ+S9mFhRgQQCEF7Dfc1WpnZ K5HNh0Y0ZKVT1Lqb4CWwr+6qCw6aLlvQ5UIt2u9KgtpWAKN2tzz+wQuEjvUMLvU6A/40 XNtQ3ts2QHmbh1U0ImlQtplR+wmb0IrHFunRyhDmPvG7W9zi/GAskcCM5RK8mSOU3yuo IhakaoDxv+HAF2xUodkeZ1X+FDS2raoUJ46m2C0xeU4fmeR3pQ0KZn2eNeh5mCDYP/tX IMzMe7pmwYEUDq9l0LGeUZgoFhJeynGkNAdNhdhhlSI7eUN9vOjqYN1K4ItS+UeHFPel s0tw== X-Gm-Message-State: AFeK/H3pjAoE8hFqO7fUhx116wwGqc/NlQvyLeo25GGgrAv4G4JhaF0GtFWm0O1DH3FndQ== X-Received: by 10.28.212.79 with SMTP id l76mr7453208wmg.6.1489355040987; Sun, 12 Mar 2017 14:44:00 -0700 (PDT) Received: from gandalf.schnuecks.de (p5DE8E1DE.dip0.t-ipconnect.de. [93.232.225.222]) by smtp.gmail.com with ESMTPSA id t103sm22544990wrc.43.2017.03.12.14.44.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Mar 2017 14:44:00 -0700 (PDT) Received: by gandalf.schnuecks.de (Postfix, from userid 500) id A6F4A25F61B; Sun, 12 Mar 2017 22:43:59 +0100 (CET) From: Simon Baatz To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: nand: orion: fix clk handling Date: Sun, 12 Mar 2017 22:34:06 +0100 Message-Id: <20170312213406.20987-1-gmbnomis@gmail.com> X-Mailer: git-send-email 2.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170312_144424_082859_31C3FE02 X-CRM114-Status: GOOD ( 16.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@free-electrons.com, jason@lakedaemon.net, andrew@lunn.ch, richard@nod.at, linux-arm-kernel@lists.infradead.org, dan.carpenter@oracle.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The clk handling in orion_nand.c had two problems: - In the probe function, clk_put() was called for an enabled clock, which violates the API (see documentation for clk_put() in include/linux/clk.h) - In the error path of the probe function, clk_put() could be called twice for the same clock. In order to clean this up, use the managed function devm_clk_get() and store the pointer to the clk in the driver data. Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk') Cc: # v4.5+ Signed-off-by: Simon Baatz --- drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c index 4a91c5d000be..b355aa738fae 100644 --- a/drivers/mtd/nand/orion_nand.c +++ b/drivers/mtd/nand/orion_nand.c @@ -23,6 +23,11 @@ #include #include +struct orion_nand_info { + struct nand_chip chip; + struct clk *clk; +}; + static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) { struct nand_chip *nc = mtd_to_nand(mtd); @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) static int __init orion_nand_probe(struct platform_device *pdev) { + struct orion_nand_info *info; struct mtd_info *mtd; struct nand_chip *nc; struct orion_nand_data *board; struct resource *res; - struct clk *clk; void __iomem *io_base; int ret = 0; u32 val = 0; - nc = devm_kzalloc(&pdev->dev, - sizeof(struct nand_chip), + info = devm_kzalloc(&pdev->dev, + sizeof(struct orion_nand_info), GFP_KERNEL); - if (!nc) + if (!info) return -ENOMEM; + nc = &info->chip; mtd = nand_to_mtd(nc); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev) if (board->dev_ready) nc->dev_ready = board->dev_ready; - platform_set_drvdata(pdev, mtd); + platform_set_drvdata(pdev, info); /* Not all platforms can gate the clock, so it is not an error if the clock does not exists. */ - clk = clk_get(&pdev->dev, NULL); - if (!IS_ERR(clk)) { - clk_prepare_enable(clk); - clk_put(clk); - } + info->clk = devm_clk_get(&pdev->dev, NULL); + if (!IS_ERR(info->clk)) + clk_prepare_enable(info->clk); ret = nand_scan(mtd, 1); if (ret) @@ -169,26 +173,22 @@ static int __init orion_nand_probe(struct platform_device *pdev) return 0; no_dev: - if (!IS_ERR(clk)) { - clk_disable_unprepare(clk); - clk_put(clk); - } + if (!IS_ERR(info->clk)) + clk_disable_unprepare(info->clk); return ret; } static int orion_nand_remove(struct platform_device *pdev) { - struct mtd_info *mtd = platform_get_drvdata(pdev); - struct clk *clk; + struct orion_nand_info *info = platform_get_drvdata(pdev); + struct nand_chip *chip = &info->chip; + struct mtd_info *mtd = nand_to_mtd(chip); nand_release(mtd); - clk = clk_get(&pdev->dev, NULL); - if (!IS_ERR(clk)) { - clk_disable_unprepare(clk); - clk_put(clk); - } + if (!IS_ERR(info->clk)) + clk_disable_unprepare(info->clk); return 0; }