mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Johannes Zink <j.zink@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Johannes Zink <j.zink@pengutronix.de>
Subject: [PATCH] base: driver: store probe deferred reason in device structure
Date: Thu,  7 Jul 2022 10:25:08 +0200	[thread overview]
Message-ID: <20220707082506.2367374-1-j.zink@pengutronix.de> (raw)

This ignores prevents probe deferred warnings in the log output and stores the
probe deferred reason in the device structure. 

If a probe is permanently deferred, the last deferral reason why it was displayed. 

Other dev_err_probe outputs are displayed as before.

Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
---
 drivers/base/driver.c | 53 +++++++++++++++++++++++++++++++++++++------
 include/driver.h      |  6 +++++
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 303ca061c..8eb68306f 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -283,6 +283,8 @@ void free_device_res(struct device_d *dev)
 	dev->name = NULL;
 	free(dev->unique_name);
 	dev->unique_name = NULL;
+	if (dev->deferred_probe_reason)
+		kfree(dev->deferred_probe_reason);
 }
 EXPORT_SYMBOL(free_device_res);
 
@@ -300,6 +302,16 @@ void free_device(struct device_d *dev)
 }
 EXPORT_SYMBOL(free_device);
 
+
+static int device_get_deferred_probe_reason(const struct device_d *dev, char **reason)
+{
+	if (dev->deferred_probe_reason) {
+		*reason = dev->deferred_probe_reason;
+		return 0;
+	} else
+		return 1;
+}
+
 /*
  * Loop over list of deferred devices as long as at least one
  * device is successfully probed. Devices that again request
@@ -312,6 +324,7 @@ static int device_probe_deferred(void)
 	struct device_d *dev, *tmp;
 	struct driver_d *drv;
 	bool success;
+	char *reason;
 
 	do {
 		success = false;
@@ -333,9 +346,12 @@ static int device_probe_deferred(void)
 		}
 	} while (success);
 
-	list_for_each_entry(dev, &deferred, active)
-		dev_err(dev, "probe permanently deferred\n");
-
+	list_for_each_entry(dev, &deferred, active) {
+		if (device_get_deferred_probe_reason(dev, &reason))
+			dev_err(dev, "probe permanently deferred\n");
+		else
+			dev_err(dev, "probe permanently deferred (%s)\n", reason);
+	}
 	return 0;
 }
 late_initcall(device_probe_deferred);
@@ -573,6 +589,17 @@ const void *device_get_match_data(struct device_d *dev)
 	return NULL;
 }
 
+static void device_set_deferred_probe_reason(struct device_d *dev, const struct va_format *vaf)
+{
+	const char *drv = dev_name(dev);
+	char* reason;
+
+	if (dev->deferred_probe_reason)
+		kfree(dev->deferred_probe_reason);
+
+	reason = basprintf("%s: %pV", drv, vaf);
+	dev->deferred_probe_reason = reason;
+}
 /**
  * dev_err_probe - probe error check and log helper
  * @loglevel: log level configured in source file
@@ -584,8 +611,12 @@ const void *device_get_match_data(struct device_d *dev)
  * This helper implements common pattern present in probe functions for error
  * checking: print debug or error message depending if the error value is
  * -EPROBE_DEFER and propagate error upwards.
- * In case of -EPROBE_DEFER it sets also defer probe reason, which can be
- * checked later by reading devices_deferred debugfs attribute.
+ *
+ * In case of -EPROBE_DEFER it sets the device's defered_probe_reason attribute,
+ * but does not report an error. The error is recorded and displayed later, if
+ * (and only if) the probe is permanently  defered. For all other error codes,
+ * it just ouputs the error
+ *
  * It replaces code sequence::
  *
  * 	if (err != -EPROBE_DEFER)
@@ -606,13 +637,19 @@ int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...)
 {
 	struct va_format vaf;
 	va_list args;
+	char* reason;
 
 	va_start(args, fmt);
 	vaf.fmt = fmt;
 	vaf.va = &args;
 
-	dev_printf(err == -EPROBE_DEFER ? MSG_DEBUG : MSG_ERR,
-		   dev, "error %pe: %pV", ERR_PTR(err), &vaf);
+	//deferred probe, just remember the error reason
+	if(err == -EPROBE_DEFER){
+		device_set_deferred_probe_reason(dev, &vaf);
+		}
+	 else {
+		dev_printf(MSG_ERR, dev, "error %pe: %pV\n", ERR_PTR(err), &vaf);
+	}
 
 	va_end(args);
 
@@ -620,6 +657,8 @@ int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...)
 }
 EXPORT_SYMBOL_GPL(dev_err_probe);
 
+
+
 /*
  * device_find_child - device iterator for locating a particular device.
  * @parent: parent struct device_d
diff --git a/include/driver.h b/include/driver.h
index b35b5f397..a41e3d478 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -88,6 +88,12 @@ struct device_d {
 	 * when the driver should actually detect client devices
 	 */
 	int     (*detect) (struct device_d *);
+
+	/**
+	 * if a driver probe is deferred, this stores the last error
+	 **/
+
+	char *deferred_probe_reason;
 };
 
 /** @brief Describes a driver present in the system */
-- 
2.30.2




             reply	other threads:[~2022-07-07  8:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  8:25 Johannes Zink [this message]
2022-07-07  9:38 ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220707082506.2367374-1-j.zink@pengutronix.de \
    --to=j.zink@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox