From patchwork Wed May 24 09:44:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 766403 X-Patchwork-Delegate: computersforpeace@gmail.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 [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wXnZJ0NhWz9s06 for ; Wed, 24 May 2017 19:45:28 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Vk27I6DS"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="qJk1y4Xw"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O9sWuzH1"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n48Hs/aa9DL1l5Z27g1KG5k/e1O5L4ZHvI6XjQcwpU0=; b=Vk27I6DSuwfJP8 865xYUXCEIBUYj8Jfsq9yBRXfl0H5WFdkfBXdBnLXXCtnewk0PqSXI/ki00BU2a/KB0syynNJF75y qq0iX9fCZGUZwPlYHlYMcCZu5uT98XKnwixocy+leBB0XdGziWfyqWWTEbYRkIzA42JhBNLQxNKdy BQhEFHjfjbZIZVAPM/IV6W5o8J8e+Ymm7yVEVI0ebO8iQtcFbkqlCl2dlZqQ1z4tUMTxGJJmJCdez gnPiIMnGdOzPLZoyGeG2RAyzUctBdD8b0tSl1/eaA+YATyYATVYi4qNyDC36ILleZBjDOWXUJ/AfL ch/5vfWI1NjgW91MZXKw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dDSr7-00086k-T0; Wed, 24 May 2017 09:45:25 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDSqz-0007xL-Mp for linux-mtd@bombadil.infradead.org; Wed, 24 May 2017 09:45:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PNav3VAd6CZZ2zum8OP2reNVaQKO/SIL9wsgxhG405s=; b=qJk1y4XwX5+0P8fqX/w5wv5Iqc 03L1oVJgxDGCbRUhsuvlHEK13krtqpcIoeMbVFMW46OUrrvh5eGxuMnds1iA9qKZToUtKFbW73iB5 Nit6/R0tZSDrXSlijwiFnFQZZICPMu1SuwxiowCQVgLCPy6O4D1s00uSkx/oMtON8N4y8EwJnL6Dh nrPz6+AilHFO0ISpVMmT6llpwbLyXEOxFDgUUVebQRz8SuSUviQ3OQ0f9OQnsl9C9yDNJ4TiHDCX+ CX6Q3MnzhcP5LsCn1mwS82UAV1EWy3oY581znIUvLf5Vaos9O2pOJUqWj/XAHcqk5/7GW3zrQd+Ts m5Ii0krQ==; Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDSqx-0006oi-Tf for linux-mtd@lists.infradead.org; Wed, 24 May 2017 09:45:16 +0000 Received: by mail-lf0-x241.google.com with SMTP id h4so10426139lfj.3 for ; Wed, 24 May 2017 02:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PNav3VAd6CZZ2zum8OP2reNVaQKO/SIL9wsgxhG405s=; b=O9sWuzH1RscIotOTDI3jyfx8M3UBF19bzr36sbTWgWeRUM4GpI0xd6aPYX6v/rmZgu rPnAvwZRl9a3B9Fzp6SgBJIFwjE5RaMogFPyX3FSqZzGS2NFwyRo9/rj6zOL5k8v1CpE z0lchCOAZzWb1SrXAyTCY9eaqjrb2IsRhN0JYGeq8uydr8erSu9wxdseCvq1iG8pBMTp oLEzlvfAuEDn1Rb5PEtccV0j5PGJFbBQ9yzzf3MLH5o1ea0uPHp8BILh0VIqvUVUtcqY Dl82TZpYNMRx960UTdG1TZ3i6CFmSoLNnvsKzHCRMbflAgbDRTS2rrDDfX0JX4EnhiTd draw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PNav3VAd6CZZ2zum8OP2reNVaQKO/SIL9wsgxhG405s=; b=t+QBz9m1U7me07NYZIBbkVXTWrCfM732NwMWp5JseG5CXwzARI47dt4VJYH49uP7au Z5bZTe2W212Q5AEzWXBVlssjCdKU8OqDkJ1mYJzQJvekcwEm6NPMldKZNQea6Chqf9Zd K+WSjSOttTSFD5Z/YBf6xFy/9E5KDQ5sDArtBRBEIIU6i5bwdxRgQjqkAbwLByY6MN+m 4Hw9p8Vk/A2q+kd1F4fM/Z+nbtlAqHEV/gqecAfkzq7YUT7r6o0ikTbUFEs0hLBaIFL9 5Ld/Y2ruMjszqcL1b53qWk40z0wCgVdD+DoKTXFqm453z1wIT/hFyYGi/DtiK8L/3ZB5 So6A== X-Gm-Message-State: AODbwcCneBNesMJlFsmbDbbr6ImQtInOr9K7VPrrW7/BKuLnGKyMSddt oTvJvjn/kW0Mug== X-Received: by 10.25.181.131 with SMTP id g3mr9085281lfk.135.1495619092909; Wed, 24 May 2017 02:44:52 -0700 (PDT) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id o7sm691208lfe.29.2017.05.24.02.44.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 May 2017 02:44:52 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger Subject: [PATCH V5 2/4] mtd: partitions: add support for allocating subpartition Date: Wed, 24 May 2017 11:44:35 +0200 Message-Id: <20170524094437.2174-3-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170524094437.2174-1-zajec5@gmail.com> References: <20170524094437.2174-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170524_054516_127321_B6919516 X-CRM114-Status: GOOD ( 19.12 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c07:0:0:0:241 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , devicetree@vger.kernel.org, linux-mtd@lists.infradead.org, Cyrille Pitchen Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rafał Miłecki Some flash device partitions can be containers with extra subpartitions (volumes). When allocating subpartition it should be validated against its parent but its master pointer has to point flash device. It's needed to make all callbacks like part_read work as expected. It also has to have offset calculated correctly. This patch modifies allocate_partition to detect if provided parent is an existing partition and sets "master" and "offset" correctly if so. Signed-off-by: Rafał Miłecki --- V5: Introduction of this patch to handle offset in allocate_partition and avoid casting const to non-const in mtd_parse_part. --- drivers/mtd/mtdpart.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 92acd89e07cb..8a0629449804 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -37,7 +37,13 @@ static LIST_HEAD(mtd_partitions); static DEFINE_MUTEX(mtd_partitions_mutex); -/* Our partition node structure */ +/** + * struct mtd_part - our partition node structure + * + * @mtd: struct holding partition details + * @master: pointer to the flash device MTD struct + * @offset: partition offset relative to the *flash device* + */ struct mtd_part { struct mtd_info mtd; struct mtd_info *master; @@ -393,9 +399,18 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent, const struct mtd_partition *part, int partno, uint64_t cur_offset) { + struct mtd_info *master = parent; struct mtd_part *slave; + uint64_t parent_offset = 0; char *name; + if (mtd_is_partition(parent)) { + struct mtd_part *parent_part = mtd_to_part(parent); + + master = parent_part->master; + parent_offset = parent_part->offset; + } + /* allocate the partition structure */ slave = kzalloc(sizeof(*slave), GFP_KERNEL); name = kstrdup(part->name, GFP_KERNEL); @@ -493,12 +508,12 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent, slave->mtd._put_device = part_put_device; slave->mtd._erase = part_erase; - slave->master = parent; - slave->offset = part->offset; + slave->master = master; + slave->offset = parent_offset + part->offset; - if (slave->offset == MTDPART_OFS_APPEND) + if (part->offset == MTDPART_OFS_APPEND) slave->offset = cur_offset; - if (slave->offset == MTDPART_OFS_NXTBLK) { + if (part->offset == MTDPART_OFS_NXTBLK) { slave->offset = cur_offset; if (mtd_mod_by_eb(cur_offset, parent) != 0) { /* Round up to next erasesize */ @@ -508,7 +523,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent, (unsigned long long)cur_offset, (unsigned long long)slave->offset); } } - if (slave->offset == MTDPART_OFS_RETAIN) { + if (part->offset == MTDPART_OFS_RETAIN) { slave->offset = cur_offset; if (parent->size - slave->offset >= slave->mtd.size) { slave->mtd.size = parent->size - slave->offset @@ -536,8 +551,8 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent, part->name); goto out_register; } - if (slave->offset + slave->mtd.size > parent->size) { - slave->mtd.size = parent->size - slave->offset; + if (slave->offset + slave->mtd.size > parent_offset + parent->size) { + slave->mtd.size = parent_offset + parent->size - slave->offset; printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n", part->name, parent->name, (unsigned long long)slave->mtd.size); }