From patchwork Mon Mar 27 18:02:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Baatz X-Patchwork-Id: 9647313 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 A2AF6602BF for ; Mon, 27 Mar 2017 18:02:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89D82283FB for ; Mon, 27 Mar 2017 18:02:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A64228403; Mon, 27 Mar 2017 18:02:54 +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 D4B8E283FB for ; Mon, 27 Mar 2017 18:02:53 +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=lPknT7OdF+dBQPBHj1cURAQM5lMM25ktROs7SCH4xH4=; b=KJw IBlXrcsj36PQ7ehMMt7lmB9SoH/k0fKUp/lhxXnp8JfQSqXmyr3IduMBCxJs2igWLQNMIx98Drq3x 08ofE6dZe/2Y600MAxLZjdBav47w/B+cx2ZdQCRvs/pxwPT45jf9cz06HQRxVHVisqg34U+kKFhj0 WmzClws0FZGSEDWp/uTS8WfpKXtFYHM22ahAC14nyCWcffoEFlY6vQeXV6sEypvEGBYeqDplk4CH1 Y1gS4NrOy5w1Xx5w1Drz0RpuAteg31wHYx/XdM5WR9lMNgdR+Hmu20NjC1Uh6TSkJP37dTMt4Q2a3 E53osoxP2+ug99Mxm+qkqUGSxAsw6fg==; 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 1csYyd-0004VF-64; Mon, 27 Mar 2017 18:02:47 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1csYyZ-0004TH-5x; Mon, 27 Mar 2017 18:02:45 +0000 Received: by mail-wr0-x241.google.com with SMTP id p52so12588144wrc.2; Mon, 27 Mar 2017 11:02:22 -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=1PjNoSL+/zieLeNgVkU8rjVMeTbazi9JQ92DHe9nxVw=; b=Gy4HQCWRN+KcSi2wBf+gUoHLmDAsH21piGbkF0o5J4ec7hY56ROhsw/B/1rKzHfReZ VEQ2jujkViT/L4ZRde5XNz9+6HtALIK8M+qNpCQrBkohxWxkQvASb+IuBVP6WXKXQ1fQ DARf0BbHSPUvXER9/QATNyyB8ngaXzWeV+LmBXdbQr2PJu/FFmuJzFj7ToAaC98vBPbd 8mCH4ACnDfLGRcXxB732QrACP0XTfUOF3kVIm70CV/jqxbJAHi33MlRyvzvzqNvBsQ3U hqhUNqkwMc1vcV4DepzLIaOXQozw0hRe2y1qdqMeCfVpVtbY6/EujFh4y503DqPgjfdo 4sOA== 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=1PjNoSL+/zieLeNgVkU8rjVMeTbazi9JQ92DHe9nxVw=; b=R7Yavz7OInfOQPSOqCcbuj8yblFF0uwkfUo3iEGCsrQvKFm4HjrT0DyHMk9S1WQIgE rWSHnnznZCGtzzqbpPqjFfmp7SpuFj2i9P66k7D9yQwXELh5YrMusQuphttohZNupV/b vsFszu+zTiSLG0muiD6kKqHOTDoVff1WxLn8pARpncjEkl8oTvcNv5JExWzpLb0I7WmG JcNNWRIFmz6OKweA2kbH+/LFbPuSt2X/KBwmWRBmpnfDQVeGWQgxompL3JtKjWX1GPZ1 evgOsb62BoE5bkBkxGkRb59rQinbKqLMhNiMRo/MC0l+o2brwhzvcczHy2Rii7uVeY4R UxcA== X-Gm-Message-State: AFeK/H2p4v57x/2mXs5rVD575SMKHRkxxnBEbpOgb6OEOWWwh5AsePO5L8ZTZEUa8rGzhw== X-Received: by 10.223.148.35 with SMTP id 32mr21833403wrq.82.1490637739059; Mon, 27 Mar 2017 11:02:19 -0700 (PDT) Received: from gandalf.schnuecks.de (p57A5677B.dip0.t-ipconnect.de. [87.165.103.123]) by smtp.gmail.com with ESMTPSA id o196sm369282wmg.12.2017.03.27.11.02.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 11:02:18 -0700 (PDT) Received: by gandalf.schnuecks.de (Postfix, from userid 500) id B4B02271956; Mon, 27 Mar 2017 20:02:17 +0200 (CEST) From: Simon Baatz To: linux-mtd@lists.infradead.org Subject: [PATCH v2 1/2] mtd: nand: orion: fix clk handling Date: Mon, 27 Mar 2017 20:02:07 +0200 Message-Id: <20170327180208.13414-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-20170327_110243_418054_95D08D0D X-CRM114-Status: GOOD ( 16.53 ) 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: andrew@lunn.ch, jason@lakedaemon.net, boris.brezillon@free-electrons.com, richard@nod.at, dan.carpenter@oracle.com, u.kleine-koenig@pengutronix.de, linux-arm-kernel@lists.infradead.org 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 --- Changes in v2: * changed whitespace alignment in orion_nand_info struct definition 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..3acdc20485f1 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; }