lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200516215057.392609-3-paul@crapouillou.net>
Date:   Sat, 16 May 2020 23:50:48 +0200
From:   Paul Cercueil <paul@...pouillou.net>
To:     David Airlie <airlied@...ux.ie>, Daniel Vetter <daniel@...ll.ch>,
        Rob Herring <robh+dt@...nel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "Rafael J . Wysocki" <rafael@...nel.org>
Cc:     od@...c.me, dri-devel@...ts.freedesktop.org,
        devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
        Paul Cercueil <paul@...pouillou.net>
Subject: [PATCH 03/12] component: Support binding with no matches

Support binding the master even though no components have been
registered.

This permits to support cases where components are optional.

Signed-off-by: Paul Cercueil <paul@...pouillou.net>
---
 drivers/base/component.c | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/base/component.c b/drivers/base/component.c
index e97704104784..a9de7ee1677f 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -100,7 +100,7 @@ static int component_devices_show(struct seq_file *s, void *data)
 
 	seq_printf(s, "%-40s %20s\n", "device name", "status");
 	seq_puts(s, "-------------------------------------------------------------\n");
-	for (i = 0; i < match->num; i++) {
+	for (i = 0; !!match && i < match->num; i++) {
 		struct component *component = match->compare[i].component;
 
 		seq_printf(s, "%-40s %20s\n",
@@ -184,6 +184,11 @@ static int find_components(struct master *master)
 	size_t i;
 	int ret = 0;
 
+	if (!match) {
+		dev_dbg(master->dev, "No components\n");
+		return 0;
+	}
+
 	/*
 	 * Scan the array of match functions and attach
 	 * any components which are found to this master.
@@ -218,10 +223,12 @@ static void remove_component(struct master *master, struct component *c)
 {
 	size_t i;
 
-	/* Detach the component from this master. */
-	for (i = 0; i < master->match->num; i++)
-		if (master->match->compare[i].component == c)
-			master->match->compare[i].component = NULL;
+	if (master->match) {
+		/* Detach the component from this master. */
+		for (i = 0; i < master->match->num; i++)
+			if (master->match->compare[i].component == c)
+				master->match->compare[i].component = NULL;
+	}
 }
 
 /*
@@ -470,10 +477,12 @@ int component_master_add_with_match(struct device *dev,
 	struct master *master;
 	int ret;
 
-	/* Reallocate the match array for its true size */
-	ret = component_match_realloc(dev, match, match->num);
-	if (ret)
-		return ret;
+	if (match) {
+		/* Reallocate the match array for its true size */
+		ret = component_match_realloc(dev, match, match->num);
+		if (ret)
+			return ret;
+	}
 
 	master = kzalloc(sizeof(*master), GFP_KERNEL);
 	if (!master)
@@ -557,6 +566,10 @@ void component_unbind_all(struct device *master_dev, void *data)
 	if (!master)
 		return;
 
+	/* No match, nothing to unbind */
+	if (!master->match)
+		return;
+
 	/* Unbind components in reverse order */
 	for (i = master->match->num; i--; )
 		if (!master->match->compare[i].duplicate) {
@@ -640,6 +653,10 @@ int component_bind_all(struct device *master_dev, void *data)
 	if (!master)
 		return -EINVAL;
 
+	/* No match, nothing to bind */
+	if (!master->match)
+		return 0;
+
 	/* Bind components in match order */
 	for (i = 0; i < master->match->num; i++)
 		if (!master->match->compare[i].duplicate) {
-- 
2.26.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ