From patchwork Wed Aug 31 07:28:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Walter X-Patchwork-Id: 664401 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 3sPHJ25qvBz9s9W for ; Wed, 31 Aug 2016 17:36:18 +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 1bf02J-0000dl-4Z; Wed, 31 Aug 2016 07:34:15 +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 1bezyR-0004t4-4L for linux-mtd@lists.infradead.org; Wed, 31 Aug 2016 07:30:20 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id C2F6824E000E; Wed, 31 Aug 2016 09:30:06 +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 4C29124E0007; Wed, 31 Aug 2016 09:30:05 +0200 (CEST) Received: by dw (sSMTP sendmail emulation); Wed, 31 Aug 2016 09:30:06 +0200 From: Daniel Walter To: linux-mtd@lists.infradead.org Subject: [PATCH 40/46] mtd: nandsim: Expose BBT, delays, etc.. to userspace Date: Wed, 31 Aug 2016 09:28:47 +0200 Message-Id: <20160831072853.27822-41-dwalter@sigma-star.at> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160831072853.27822-1-dwalter@sigma-star.at> References: <20160831072853.27822-1-dwalter@sigma-star.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160831_003015_674744_366D0D92 X-CRM114-Status: GOOD ( 15.82 ) 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: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Richard Weinberger Signed-off-by: Richard Weinberger --- drivers/mtd/nand/nandsim.c | 43 ++++++++++++++++++++++++++++++++++++------- include/linux/mtd/nandsim.h | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index 027b15d..222b2b8 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c @@ -2593,11 +2593,37 @@ static int ns_ctrl_new_instance(struct ns_new_instance_req *req) nsparam->bus_width = req->bus_width; nsparam->file_fd = req->file_fd; nsparam->no_oob = !!req->no_oob; - - if (req->parts_num > NANDSIM_MAX_PARTS || req->parts_num < 0) { - kfree(nsparam); - return -EINVAL; - } + nsparam->bbt = req->bbt_mode; + nsparam->bch = req->bch_strength; + nsparam->bitflips = req->bitflips; + nsparam->overridesize = req->overridesize; + + if (req->bch_strength && req->no_oob) + goto err_inval; + + if (req->access_delay && req->program_delay && req->erase_delay && + req->output_cycle && req->input_cycle) { + if (req->access_delay > MAX_UDELAY_MS * 1000) + goto err_inval; + if (req->program_delay > MAX_UDELAY_MS * 1000) + goto err_inval; + if (req->erase_delay > 1000) + goto err_inval; + if (req->output_cycle > MAX_UDELAY_MS * 1000) + goto err_inval; + if (req->input_cycle > MAX_UDELAY_MS * 1000) + goto err_inval; + + nsparam->access_delay = req->access_delay; + nsparam->program_delay = req->program_delay; + nsparam->erase_delay = req->erase_delay; + nsparam->output_cycle = req->output_cycle; + nsparam->input_cycle = req->input_cycle; + nsparam->do_delays = true; + } + + if (req->parts_num > NANDSIM_MAX_PARTS || req->parts_num < 0) + goto err_inval; if (req->parts_num > 0) { nsparam->parts_num = req->parts_num; @@ -2618,8 +2644,7 @@ static int ns_ctrl_new_instance(struct ns_new_instance_req *req) break; default: - kfree(nsparam); - return -EINVAL; + goto err_inval; } nsmtd = ns_new_instance(nsparam); @@ -2632,6 +2657,10 @@ static int ns_ctrl_new_instance(struct ns_new_instance_req *req) ns = nand_get_controller_data(chip); return ns->index; + +err_inval: + kfree(nsparam); + return -EINVAL; } static int ns_ctrl_destroy_instance(struct ns_destroy_instance_req *req) diff --git a/include/linux/mtd/nandsim.h b/include/linux/mtd/nandsim.h index 07d32a9..880c0b1 100644 --- a/include/linux/mtd/nandsim.h +++ b/include/linux/mtd/nandsim.h @@ -11,7 +11,7 @@ struct nandsim_params { unsigned int output_cycle; unsigned int input_cycle; unsigned int bus_width; - unsigned int do_delays; + bool do_delays; unsigned int parts[NANDSIM_MAX_PARTS]; unsigned int parts_num; char *badblocks;