From patchwork Wed Sep 21 09:56:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Walter X-Patchwork-Id: 672751 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 3sfFSW5Lzxz9sD6 for ; Wed, 21 Sep 2016 19:58:35 +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 1bmeHm-0007fx-SW; Wed, 21 Sep 2016 09:57:50 +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 1bmeGR-0006nH-VG for linux-mtd@lists.infradead.org; Wed, 21 Sep 2016 09:56:57 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id E4DAD24E0004; Wed, 21 Sep 2016 11:56: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 6648024E0001; Wed, 21 Sep 2016 11:56:05 +0200 (CEST) Received: by dw (sSMTP sendmail emulation); Wed, 21 Sep 2016 11:56:06 +0200 From: Daniel Walter To: linux-mtd@lists.infradead.org Subject: [PATCH v2 38/46] mtd: nandsim: Expose partition creation logic to user space Date: Wed, 21 Sep 2016 11:56:05 +0200 Message-Id: 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_025628_408193_65A0F9CD X-CRM114-Status: GOOD ( 15.55 ) 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 Signed-off-by: Richard Weinberger --- drivers/mtd/nand/nandsim.c | 12 +++++++++++- include/linux/mtd/nandsim.h | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index 615dde3..6b7570b 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c @@ -2585,6 +2585,16 @@ static int ns_ctrl_new_instance(struct ns_new_instance_req *req) 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; + } + + if (req->parts_num > 0) { + nsparam->parts_num = req->parts_num; + memcpy(nsparam->parts, req->parts, sizeof(nsparam->parts)); + } + switch (req->backend) { case NANDSIM_BACKEND_RAM: nsparam->bops = &ns_ram_bops; @@ -2979,7 +2989,7 @@ static int __init ns_init_default(void) nsparam->input_cycle = input_cycle; nsparam->bus_width = bus_width; nsparam->do_delays = do_delays; - nsparam->parts = parts; + memcpy(nsparam->parts, parts, sizeof(nsparam->parts)); nsparam->parts_num = parts_num; nsparam->badblocks = badblocks; nsparam->weakblocks = weakblocks; diff --git a/include/linux/mtd/nandsim.h b/include/linux/mtd/nandsim.h index 61ff5dd..07d32a9 100644 --- a/include/linux/mtd/nandsim.h +++ b/include/linux/mtd/nandsim.h @@ -12,7 +12,7 @@ struct nandsim_params { unsigned int input_cycle; unsigned int bus_width; unsigned int do_delays; - unsigned int *parts; + unsigned int parts[NANDSIM_MAX_PARTS]; unsigned int parts_num; char *badblocks; char *weakblocks;