From patchwork Sat Jun 24 23:10:24 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: 780424 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 3ww9zs2glNz9s3s for ; Sun, 25 Jun 2017 09:11:19 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="a8pd6n5a"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lxIgap/2"; 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: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:In-Reply-To:References: List-Owner; bh=bW/Vta9tUaAXhtmAxHSNSvVUzUhqO5UF1QEW5exmZYQ=; b=a8pd6n5ar6FIal VSXTbTWkhrlERO42B4W3558h5LnqJIThu1rpMy5DEQYa7Lxyt58Re3MGJVG39sgQjHbMRpVhGNMxm fzEuq5rvMpJ3D+CvygVVs26EG9Ci5IKXyGgJEoa939s8656g+wtM4Y9TDxe2g4FG6iSyh4PlVXije m40t0Df+KgggZTVIoaVU4I8sSDbugXy9qPyxNZFa9b8LCV4O+Wm2aEYiBhENqHvlS0+QG390QZaj2 xGRvI1JdapqEBvqyj88K0M7C/qe7/DD9f6lrE06kbmhmmRxfCshii8MR9jhjOU4hwBSKY6dvzc50t F7PzkWwmmY0fuLmGkFgg==; 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 1dOuCp-0003GU-9a; Sat, 24 Jun 2017 23:11:07 +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 1dOuCl-0003Fe-PB for linux-mtd@lists.infradead.org; Sat, 24 Jun 2017 23:11:06 +0000 Received: by mail-lf0-x241.google.com with SMTP id n136so9879033lfn.2 for ; Sat, 24 Jun 2017 16:10:42 -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:mime-version :content-transfer-encoding; bh=hfChFLL1NYIzCYFmjvkg6OBz3NsMu0QJe4Lp2abeMIk=; b=lxIgap/2HGyF23L2BSMegcER6NrSl9O47Ml69uaTHFjpjw6C/RdUt+fAURW73xkq0m jcnzonfhwiMdgv46ht86DosiN1OvIJQbXws81v3zZYknQRd/wCXA4lWmaxr92xP8SXwo hIDaM04EM/Ht9JA7vssM2fXnHvv8lZa49hSuDddTUHYkUQFgYqAl/+ZoZqSW9nOX8BB4 A2ZSXY+v6o2wa0Sg2arkR2lr0BhX+SuZfTOXGUsx9bProXGjLvFM9iFPg3/Naa7oAevs pVqIZvpo3ISgxh4NfqGYLoOf5tIFU84vT+rzTsyGRC+8s0mMKiMBbUl/dEaQ2VoLSWnw iekw== 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:mime-version :content-transfer-encoding; bh=hfChFLL1NYIzCYFmjvkg6OBz3NsMu0QJe4Lp2abeMIk=; b=k2J4hjmrOV9qF/2KV8zn2DbtX6pnuovHfdkauUTwxBpKrkaxcP2CrhutvtPPmoVfNp EBpu+njFe2Hlu7gK1hqEjp6q3O/4Tks2yC1uWUOxmStP48EcAsQWULRDJPnffc7HoYae qRxz6FFNU11APfrk2jJhMQRX9mDh2CS1y28Hc2kUaRfQgHMZ4urSpv8z3NhSyGsm9D+x iJ/AcifBecXp4TBiD7UQ2VOFB2QUkzkf/CZ3u4G4xEUVd3Kgue0cjZp44KSuJuc81Gwh 4GFEKYk9JghwPFCk41uyJUMmRqcl3O1jo7/BAMbLR5/T4l0sY9eoT168C4pdTFmj+dFZ tHtA== X-Gm-Message-State: AKS2vOxYf3wYVOx9Dtmh8ZzSZF1WisLIS6lVJ6unXC77p2tSRz6esqdJ fvKd9UxZ809RAA== X-Received: by 10.46.0.77 with SMTP id 74mr4194056lja.109.1498345840807; Sat, 24 Jun 2017 16:10:40 -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 b17sm2426848lfg.32.2017.06.24.16.10.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Jun 2017 16:10:40 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen , Rob Herring Subject: [PATCH V4 1/2] mtd: partitions: add of_match_table parser matching Date: Sun, 25 Jun 2017 01:10:24 +0200 Message-Id: <20170624231025.23292-1-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170624_161104_002334_5FA2A36D X-CRM114-Status: GOOD ( 17.17 ) 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.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) 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 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: Mark Rutland , devicetree@vger.kernel.org, Florian Fainelli , Geert Uytterhoeven , Linus Walleij , linux-mtd@lists.infradead.org, Jonas Gorski , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Frank Rowand Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Brian Norris Partition parsers can now provide an of_match_table to enable flash<-->parser matching via device tree. This support is currently limited to built-in parsers as it uses request_module() and friends. This should be sufficient for most cases though as compiling parsers as modules isn't a common choice. Signed-off-by: Brian Norris Signed-off-by: Rafał Miłecki Tested-by: Jonas Gorski --- This is based on Brian's patches: [RFC PATCH 4/7] mtd: add of_match_mtd_parser() and of_mtd_match_mtd_parser() helpers [RFC PATCH 6/7] RFC: mtd: partitions: enable of_match_table matching V1: Put helpers in mtdpart.c instead of drivers/of/of_mtd.c Merge helpers into a single of_mtd_match_mtd_parser V3: Add a simple comment to note we will need the best match in the future V4: Rework new functions to pick parser with the best match Move new code in parse_mtd_partitions up so it has precedence over flash driver defaults and MTD defaults --- drivers/mtd/mtdpart.c | 65 ++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/partitions.h | 1 + 2 files changed, 66 insertions(+) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 2ad9493703f9..239d5e6e62ed 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "mtdcore.h" @@ -885,6 +886,60 @@ static int mtd_part_do_parse(struct mtd_part_parser *parser, return ret; } +static int of_mtd_match_mtd_parser(struct mtd_info *mtd, + struct mtd_part_parser *parser) +{ + const struct of_device_id *matches; + struct device_node *np; + int score = 0; + + matches = parser->of_match_table; + if (!matches) + return false; + + np = mtd_get_of_node(mtd); + np = of_get_child_by_name(np, "partitions"); + if (!np) + return false; + + for (; matches->name[0] || matches->type[0] || matches->compatible[0]; + matches++) { + if (!matches->compatible[0]) + continue; + score = max(score, + of_device_is_compatible(np, matches->compatible)); + } + + of_node_put(np); + + return score; +} + +static struct mtd_part_parser *mtd_part_get_parser_by_of(struct mtd_info *mtd) +{ + struct mtd_part_parser *p, *ret = NULL; + struct mtd_part_parser *best_parser = NULL; + int best_score = 0; + + spin_lock(&part_parser_lock); + + list_for_each_entry(p, &part_parsers, list) { + int score = of_mtd_match_mtd_parser(mtd, p); + + if (score > best_score) { + best_score = score; + best_parser = p; + } + } + + if (best_parser && try_module_get(best_parser->owner)) + ret = best_parser; + + spin_unlock(&part_parser_lock); + + return ret; +} + /** * parse_mtd_partitions - parse MTD partitions * @master: the master partition (describes whole MTD device) @@ -913,6 +968,16 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types, struct mtd_part_parser *parser; int ret, err = 0; + parser = mtd_part_get_parser_by_of(master); + if (parser) { + ret = mtd_part_do_parse(parser, master, pparts, data); + if (ret > 0) + return 0; + mtd_part_parser_put(parser); + if (ret < 0) + err = ret; + } + if (!types) types = default_mtd_part_types; diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h index c4beb70dacbd..11cb0c50cd84 100644 --- a/include/linux/mtd/partitions.h +++ b/include/linux/mtd/partitions.h @@ -77,6 +77,7 @@ struct mtd_part_parser { struct list_head list; struct module *owner; const char *name; + const struct of_device_id *of_match_table; int (*parse_fn)(struct mtd_info *, const struct mtd_partition **, struct mtd_part_parser_data *); void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);