Received: by 10.223.176.46 with SMTP id f43csp1242899wra; Fri, 26 Jan 2018 14:33:28 -0800 (PST) X-Google-Smtp-Source: AH8x224vwyjoZtTbSIA7n47oV8XWiQPkIfgWRoHPmuUCoOVzXsTsibHiIsUqn5gsrRDCFYz15mOJ X-Received: by 10.98.153.2 with SMTP id d2mr20687354pfe.44.1517006008479; Fri, 26 Jan 2018 14:33:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517006008; cv=none; d=google.com; s=arc-20160816; b=zXgKtAwGy4qrI2D7WkyfvdVq3n40lfBz2btqm+h6dXIQyeSsDOBumTb1gEgDInXdbP lDbDXIJAVRw6qNxB84gEGZcjZMANktYG1tm0Ewspad3fFs2kjDjip3hTZT6vyHHOd3AV B7q5NK3NgsU1PXF5J4dPMhEoJg1Aueedw31cYVbZpxSoiAEJ3aKQNEoSqengJaz/BPaW Gs8t/0rPRJdjElDhvx5wgH2vzTPsiTZRv1xUYSj4LB5guoXruL08IxlDBoaj8iW9DQh1 MRanMijDvDwQf4TXOX7ej3zUlP5FDM8uhztAIrgc02otJi5ov6W9GSwfRGTidVTIWgY0 giLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:message-id:date:subject:cc:to :from:arc-authentication-results; bh=5nzzICSKGXct+WGVDllzaHzM/+tKs/W7baflSMh5t0E=; b=tU6QKAJ66QPfE4qTXBkzcT6si/+x8Dg1bQwHS8D3rQjnH7LNm1SR1ZYGy4g/iSfXBd OERXQDW5DDsKPoVu5mohev7+t7IPYPD80y7C0GfAdxy3nbxrZhjsq28eLtorQA3DyPCw pUN9dPOrk7iy1BqyzdxdBwmY4KvdbJN6Jtk9rYz3gbkgvTt/8OkmbUhytn/g5cvL7Pqu nOfH34Z4ue6U7ZIHJE9bDCzvRR88s9foSaEcQLQvgvWb6xqAlz0Y+Av5g9U0L9PiaR/K nQ7GTtWuPaIB40hYXmxdCuVeE3KxYdalaDF3pyp3zoEfttZHyC4LvxMn5R0XjwSxny5n azmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16-v6si4273800plp.276.2018.01.26.14.33.12; Fri, 26 Jan 2018 14:33:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751771AbeAZWcq (ORCPT + 99 others); Fri, 26 Jan 2018 17:32:46 -0500 Received: from mail.ispras.ru ([83.149.199.45]:53078 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751509AbeAZWcp (ORCPT ); Fri, 26 Jan 2018 17:32:45 -0500 Received: from localhost.localdomain (ppp85-140-185-169.pppoe.mtu-net.ru [85.140.185.169]) by mail.ispras.ru (Postfix) with ESMTPSA id 67BB654006C; Sat, 27 Jan 2018 01:32:43 +0300 (MSK) From: Alexey Khoroshilov To: Boris Brezillon Cc: Alexey Khoroshilov , Stefan Agner , Richard Weinberger , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH v3] mtd: nand: vf610: fix error handling in vf610_nfc_probe() Date: Sat, 27 Jan 2018 01:32:41 +0300 Message-Id: <1517005961-7938-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20180106102541.75ff546d@bbrezillon> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vf610_nfc_probe() misses error handling of mtd_device_register() and contains unneeded of_node_put() on error path. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov --- v2: Add nand_cleanup() to undone nand_scan_tail() as Boris Brezillon noted. v3: Rename error labels, remove of_node_put() per Boris Brezillon request. drivers/mtd/nand/vf610_nfc.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/nand/vf610_nfc.c b/drivers/mtd/nand/vf610_nfc.c index 8037d4b48a05..7cdc6eed305d 100644 --- a/drivers/mtd/nand/vf610_nfc.c +++ b/drivers/mtd/nand/vf610_nfc.c @@ -682,7 +682,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) dev_err(nfc->dev, "Only one NAND chip supported!\n"); err = -EINVAL; - goto error; + goto err_disable_clk; } nand_set_flash_node(chip, child); @@ -692,7 +692,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) if (!nand_get_flash_node(chip)) { dev_err(nfc->dev, "NAND chip sub-node missing!\n"); err = -ENODEV; - goto err_clk; + goto err_disable_clk; } chip->dev_ready = vf610_nfc_dev_ready; @@ -712,7 +712,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, mtd); if (err) { dev_err(nfc->dev, "Error requesting IRQ!\n"); - goto error; + goto err_disable_clk; } vf610_nfc_preinit_controller(nfc); @@ -720,7 +720,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) /* first scan to find the device and get the page size */ err = nand_scan_ident(mtd, 1, NULL); if (err) - goto error; + goto err_disable_clk; vf610_nfc_init_controller(nfc); @@ -732,20 +732,20 @@ static int vf610_nfc_probe(struct platform_device *pdev) if (mtd->writesize + mtd->oobsize > PAGE_2K + OOB_MAX - 8) { dev_err(nfc->dev, "Unsupported flash page size\n"); err = -ENXIO; - goto error; + goto err_disable_clk; } if (chip->ecc.mode == NAND_ECC_HW) { if (mtd->writesize != PAGE_2K && mtd->oobsize < 64) { dev_err(nfc->dev, "Unsupported flash with hwecc\n"); err = -ENXIO; - goto error; + goto err_disable_clk; } if (chip->ecc.size != mtd->writesize) { dev_err(nfc->dev, "Step size needs to be page size\n"); err = -ENXIO; - goto error; + goto err_disable_clk; } /* Only 64 byte ECC layouts known */ @@ -765,7 +765,7 @@ static int vf610_nfc_probe(struct platform_device *pdev) } else { dev_err(nfc->dev, "Unsupported ECC strength\n"); err = -ENXIO; - goto error; + goto err_disable_clk; } chip->ecc.read_page = vf610_nfc_read_page; @@ -777,16 +777,19 @@ static int vf610_nfc_probe(struct platform_device *pdev) /* second phase scan */ err = nand_scan_tail(mtd); if (err) - goto error; + goto err_disable_clk; platform_set_drvdata(pdev, mtd); /* Register device in MTD */ - return mtd_device_register(mtd, NULL, 0); + err = mtd_device_register(mtd, NULL, 0); + if (err) + goto err_cleanup_nand; + return 0; -error: - of_node_put(nand_get_flash_node(chip)); -err_clk: +err_cleanup_nand: + nand_cleanup(chip); +err_disable_clk: clk_disable_unprepare(nfc->clk); return err; } -- 2.7.4