From patchwork Fri Dec 5 21:14:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 418307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A5110140119 for ; Sat, 6 Dec 2014 08:16:31 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xx0Dm-0001me-BM; Fri, 05 Dec 2014 21:15:26 +0000 Received: from mail-qc0-x229.google.com ([2607:f8b0:400d:c01::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xx0Dk-0000nG-5f for linux-mtd@lists.infradead.org; Fri, 05 Dec 2014 21:15:24 +0000 Received: by mail-qc0-f169.google.com with SMTP id w7so1137067qcr.28 for ; Fri, 05 Dec 2014 13:15:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=+IE9ncxwtTY0ay1jL3wxHgO90wNDD56l+IYQZgf3Zc8=; b=QVPid05GTSNCtF/LHeMjKMFBb5lHKYckd6AAiGjhYUD+Au27OzKTnPLbTh//g2u9RI twB1tM0sv4mbwJ0kDuIEfdxpO0Q14+ajJbVE5GpYr5LptAr5USA2d1DC+2+ggaJwj7b/ 1hjbQlGKS5bglMX2DtOJCFgpDuWjmLMj7hxQOHfUCukTL/9DwCu2kKPslKyy9farecmB YM7LeDxoEfZhyRC5S0r35y0UXI+R9kuxqG18rnK32RVgscmT/1NETHGI7wjtl7B+M2pj v2ubIZVr+7jXnV5W/hzejiqaOUcHh+TiFZG5rqRokBZydU822gwiKHutrvICg6YCHBjl HaQA== X-Received: by 10.229.251.200 with SMTP id mt8mr29392098qcb.13.1417814102881; Fri, 05 Dec 2014 13:15:02 -0800 (PST) Received: from localhost.localdomain ([201.82.52.106]) by mx.google.com with ESMTPSA id o30sm30746926qge.33.2014.12.05.13.15.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Dec 2014 13:15:01 -0800 (PST) From: Fabio Estevam To: computersforpeace@gmail.com Subject: [PATCH] mtd: fsl-quadspi: Fix module unbound Date: Fri, 5 Dec 2014 19:14:46 -0200 Message-Id: <1417814086-30512-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141205_131524_358302_207FFA0F X-CRM114-Status: GOOD ( 16.83 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (festevam[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Fabio Estevam , Frank.Li@freescale.com, shijie8@gmail.com, linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Fabio Estevam When removing the fsl-quadspi module and running 'cat /proc/mtd' afterwards, we see garbage data like: $ rmmod fsl-quadspi $ cat /proc/mtd dev: size erasesize name mtd0: 00000000 00000000 "(null)" mtd0: 00000000 00000000 "(null)" mtd0: 00000000 00000000 "(null)" ... mtd0: a22296c6c756e28 00000000 "(null)" mtd0: a22296c6c756e28 3064746d "(null)" The reason for this is due to the wrong mtd index used in mtd_device_unregister() in the remove function. We need to keep the mtd index aligned with the one used in the probe function, which means we need to take into account the 'has_second_chip' property. Signed-off-by: Fabio Estevam --- drivers/mtd/spi-nor/fsl-quadspi.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c index 39763b9..4b468a9 100644 --- a/drivers/mtd/spi-nor/fsl-quadspi.c +++ b/drivers/mtd/spi-nor/fsl-quadspi.c @@ -227,6 +227,7 @@ struct fsl_qspi { u32 nor_num; u32 clk_rate; unsigned int chip_base_addr; /* We may support two chips. */ + bool has_second_chip; }; static inline int is_vybrid_qspi(struct fsl_qspi *q) @@ -783,7 +784,6 @@ static int fsl_qspi_probe(struct platform_device *pdev) struct spi_nor *nor; struct mtd_info *mtd; int ret, i = 0; - bool has_second_chip = false; const struct of_device_id *of_id = of_match_device(fsl_qspi_dt_ids, &pdev->dev); @@ -860,14 +860,14 @@ static int fsl_qspi_probe(struct platform_device *pdev) goto irq_failed; if (of_get_property(np, "fsl,qspi-has-second-chip", NULL)) - has_second_chip = true; + q->has_second_chip = true; /* iterate the subnodes. */ for_each_available_child_of_node(dev->of_node, np) { char modalias[40]; /* skip the holes */ - if (!has_second_chip) + if (!q->has_second_chip) i *= 2; nor = &q->nor[i]; @@ -943,9 +943,12 @@ static int fsl_qspi_probe(struct platform_device *pdev) return 0; last_init_failed: - for (i = 0; i < q->nor_num; i++) + for (i = 0; i < q->nor_num; i++) { + /* skip the holes */ + if (!q->has_second_chip) + i *= 2; mtd_device_unregister(&q->mtd[i]); - + } irq_failed: clk_disable_unprepare(q->clk); clk_failed: @@ -960,8 +963,12 @@ static int fsl_qspi_remove(struct platform_device *pdev) struct fsl_qspi *q = platform_get_drvdata(pdev); int i; - for (i = 0; i < q->nor_num; i++) + for (i = 0; i < q->nor_num; i++) { + /* skip the holes */ + if (!q->has_second_chip) + i *= 2; mtd_device_unregister(&q->mtd[i]); + } /* disable the hardware */ writel(QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);