From patchwork Wed Jun 21 06:26:45 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: 778659 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 3wsvtB0Wv4z9s2s for ; Wed, 21 Jun 2017 16:28:34 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BKiY+hO7"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="T9gI4vik"; 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=TQNB04kVGQA7axPrq/a0nAAbQqhItRe8Utuvhnb5PRQ=; b=BKiY+hO7YtozS1 cVBSvCctSYrd4Tm2mETaq9Lvzj4KbR6dxNtPWNowBkjlTc1SLZUJEGDV+tSCJ60vRvHJobA/YbpGf Cl+IUJG7BY0d/eP51ovaE40phYSEIaUV+Bup1mFYSvDuJU0hL/siLPPoe6v63oajif1as0UkzkeF7 kQAPoJOAPNnjq7YoEUfSIUxz37UbOxDH0sEIakQhUKjEFqKdl3FAcowNJa2s2vSLuyec/L7eCHRFt brF+b+RNhCvWf42WF0SKyTFeMXsF/MbUMSzX+X4tMAZKRtVHdaP/It8CYhQd4BFQ5BuR19EBO0pms LRLv3kVVcliPfDu6Tr7A==; 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 1dNZ7q-0004gt-Pm; Wed, 21 Jun 2017 06:28:26 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dNZ7C-0003ca-1V for linux-mtd@lists.infradead.org; Wed, 21 Jun 2017 06:27:50 +0000 Received: by mail-lf0-x241.google.com with SMTP id u62so18684166lfg.0 for ; Tue, 20 Jun 2017 23:27:26 -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=eo5qzEk0ONjBXb1YyurQgo9JsXz7duTXxFOXFEb9OEY=; b=T9gI4vikJO5qap4Exb/QvtQHIZuZ6fZIqrj+wkko2omCxmksVNLk7BhR3M5rXabtBI q0amBFKuuwZrVIs1chvYuMtGP9SL0MpGOev+fvVgfm+MmH1Z8LyYdnw1Tros8U1QCg1i 3ouY8LAi9ec4H0wAL74VL7UCu4CVGdmwhjHVeVoEkBhxqbMQq8fQD7e73QA6PyZgqfcV BcjQR62iH2QFAOApZF965UnyjSOJ1sHQdID9XMHeZRuCgGGQhWSS7cSCBvJrDU7FKbm+ AChqzXMGWnCZb9YzDupXM4k2ORz7xSC2VJhj+c2gNdNgGrS2RaD5OcbmVZc2CYgzKIy4 NFwA== 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=eo5qzEk0ONjBXb1YyurQgo9JsXz7duTXxFOXFEb9OEY=; b=ThNG2ab4bM5BzxCjmCEoBEVoKQLl427mQDTeOnE0/ISIESJEnANj5qJyBvxQSFp+cW DN7/lizlUQWlo76oQQ/xPCkDLC9KBrQ8BBb2deGHbi3fyP34ZIYpKSuLzg1nLhiyKwFp YZTvMWHRUve2GDRhXwM+huZuckIWpX/26PhkXVKrpzh8ZEy0A+RiceI1FXF4xgHZWlkE jYxkTgEzJ+Y10oYfz4vgn+L2yU5u/crRowOvHimvKagbXCA0RqRqe4pw8xfnu5sbTTmY zSUqE2knvqJUf6ZuNQN4MGhfWCXenGUNU4+Z4Syx1mPD6Ryjtm2/8Ou0x77bNmWAc95V DDvw== X-Gm-Message-State: AKS2vOxsEkDsNPf9UmkB/XZQcXNORKfE8A2xFzN6YQhjOKOpUQwv/IAe OAKwPcCtO+kUjDPe X-Received: by 10.46.33.164 with SMTP id h36mr9092277lji.86.1498026445376; Tue, 20 Jun 2017 23:27:25 -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 x13sm3444596ljd.64.2017.06.20.23.27.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 23:27:24 -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 V7 4/6] mtd: partitions: add support for subpartitions Date: Wed, 21 Jun 2017 08:26:45 +0200 Message-Id: <20170621062647.6072-5-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170621062647.6072-1-zajec5@gmail.com> References: <20170526131415.27186-1-zajec5@gmail.com> <20170621062647.6072-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170620_232747_943082_15124F8B X-CRM114-Status: GOOD ( 14.58 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -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.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 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). All callbacks are already capable of this additional level of indirection. This patch makes sure we always display subpartitions using a tree structure and takes care of deleting subpartitions when parent gets removed. 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. V6: Rework patch to support tree structure. --- drivers/mtd/mtdpart.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 208822040735..c0d464d192ee 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -413,7 +413,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent, * parent conditional on that option. Note, this is a way to * distinguish between the master and the partition in sysfs. */ - slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ? + slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ? &parent->dev : parent->dev.parent; slave->mtd.dev.of_node = part->of_node; @@ -664,8 +664,17 @@ EXPORT_SYMBOL_GPL(mtd_add_partition); */ static int __mtd_del_partition(struct mtd_part *priv) { + struct mtd_part *child, *next; int err; + list_for_each_entry_safe(child, next, &mtd_partitions, list) { + if (child->parent == &priv->mtd) { + err = __mtd_del_partition(child); + if (err) + return err; + } + } + sysfs_remove_files(&priv->mtd.dev.kobj, mtd_partition_attrs); err = del_mtd_device(&priv->mtd); @@ -680,16 +689,16 @@ static int __mtd_del_partition(struct mtd_part *priv) /* * This function unregisters and destroy all slave MTD objects which are - * attached to the given master MTD object. + * attached to the given MTD object. */ -int del_mtd_partitions(struct mtd_info *master) +int del_mtd_partitions(struct mtd_info *mtd) { struct mtd_part *slave, *next; int ret, err = 0; mutex_lock(&mtd_partitions_mutex); list_for_each_entry_safe(slave, next, &mtd_partitions, list) - if (slave->parent == master) { + if (slave->parent == mtd) { ret = __mtd_del_partition(slave); if (ret < 0) err = ret; @@ -699,14 +708,14 @@ int del_mtd_partitions(struct mtd_info *master) return err; } -int mtd_del_partition(struct mtd_info *master, int partno) +int mtd_del_partition(struct mtd_info *mtd, int partno) { struct mtd_part *slave, *next; int ret = -EINVAL; mutex_lock(&mtd_partitions_mutex); list_for_each_entry_safe(slave, next, &mtd_partitions, list) - if ((slave->parent == master) && + if ((slave->parent == mtd) && (slave->mtd.index == partno)) { ret = __mtd_del_partition(slave); break; @@ -939,6 +948,6 @@ uint64_t mtd_get_device_size(const struct mtd_info *mtd) if (!mtd_is_partition(mtd)) return mtd->size; - return mtd_to_part(mtd)->parent->size; + return mtd_get_device_size(mtd_to_part(mtd)->parent); } EXPORT_SYMBOL_GPL(mtd_get_device_size);