From patchwork Wed Sep 21 09:48:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Walter X-Patchwork-Id: 672730 X-Patchwork-Delegate: boris.brezillon@free-electrons.com 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-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sfFGh3qt5z9sQw for ; Wed, 21 Sep 2016 19:50:04 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bme8v-0007Lq-RI; Wed, 21 Sep 2016 09:48:41 +0000 Received: from mail.sigma-star.at ([95.130.255.111]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bme8l-00075M-0Z for linux-mtd@lists.infradead.org; Wed, 21 Sep 2016 09:48:38 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id 8940016B4D8C; Wed, 21 Sep 2016 11:48:12 +0200 (CEST) X-Virus-Scanned: amavisd-new at mail.sigma-star.at Received: from dw (unknown [82.150.214.13]) by mail.sigma-star.at (Postfix) with ESMTPSA id 70DA216B4335; Wed, 21 Sep 2016 11:48:10 +0200 (CEST) Received: by dw (sSMTP sendmail emulation); Wed, 21 Sep 2016 11:48:11 +0200 From: Daniel Walter To: linux-mtd@lists.infradead.org Subject: [PATCH v2 10/46] mtd: nandsim: Add helper functions for pointer magic Date: Wed, 21 Sep 2016 11:48:10 +0200 Message-Id: <2ff286b19b872f4f234ee42c217d7a2e0c1e326d.1474450296.git.dwalter@sigma-star.at> X-Mailer: git-send-email 2.8.3 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160921_024831_382995_CACE2F04 X-CRM114-Status: GOOD ( 15.06 ) X-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@free-electrons.com, computersforpeace@gmail.com, dwmw2@infradead.org, linux-kernel@vger.kernel.org, Richard Weinberger MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Richard Weinberger Add chip_to_ns() and ns_to_mtd() helper functions Signed-off-by: Richard Weinberger --- drivers/mtd/nand/nandsim.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index fda670b..f26e983 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c @@ -461,6 +461,18 @@ struct grave_page { /* MTD structure for NAND controller */ static struct mtd_info *ns_mtds[NS_MAX_DEVICES]; +static inline struct nandsim *chip_to_ns(struct nand_chip *chip) +{ + return (struct nandsim *)(chip + 1); +} + +static inline struct mtd_info *ns_to_mtd(struct nandsim *ns) +{ + struct nand_chip *chip = ((struct nand_chip *)ns - 1); + + return nand_to_mtd(chip); +} + static int nandsim_debugfs_show(struct seq_file *m, void *private) { struct nandsim *ns = (struct nandsim *)m->private; @@ -1462,8 +1474,7 @@ static int do_read_error(struct nandsim *ns, int num) static void do_bit_flips(struct nandsim *ns, int num) { - struct nand_chip *chip = ((struct nand_chip *)ns - 1); - struct mtd_info *nsmtd = nand_to_mtd(chip); + struct mtd_info *nsmtd = ns_to_mtd(ns); if (ns->bitflips && prandom_u32() < (1 << 22)) { int flips = 1; @@ -2300,7 +2311,7 @@ static int __init ns_init_default(void) WARN_ON(ns_mtds[0]); nsmtd = ns_mtds[0] = nand_to_mtd(chip); - nand = (struct nandsim *)(chip + 1); + nand = chip_to_ns(chip); nand_set_controller_data(chip, (void *)nand); INIT_LIST_HEAD(&nand->weak_blocks);