[v1,1/1] i2c: core: Make debug message even more debuggish

Message ID 20210428145751.4934-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series
  • [v1,1/1] i2c: core: Make debug message even more debuggish
Related show

Commit Message

Andy Shevchenko April 28, 2021, 2:57 p.m.
One may notice that dev_printk(KERN_DEBUG ...) is *not* an equivalent
to dev_dbg(). It will be printed whenever loglevel is high enough.
And currently it will be the only message in the I²C core in some
configurations that got printed under above conditions.

Moving to dev_dbg() will hide it in the configurations where Dynamic Debug
is enabled and hence align with all other debug messages in the I²C core..

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-core-base.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Andy Shevchenko May 17, 2021, 1:55 p.m. | #1
On Wed, Apr 28, 2021 at 05:57:51PM +0300, Andy Shevchenko wrote:
> One may notice that dev_printk(KERN_DEBUG ...) is *not* an equivalent

> to dev_dbg(). It will be printed whenever loglevel is high enough.

> And currently it will be the only message in the I²C core in some

> configurations that got printed under above conditions.

> 

> Moving to dev_dbg() will hide it in the configurations where Dynamic Debug

> is enabled and hence align with all other debug messages in the I²C core..


Wolfram, any comment on this?

-- 
With Best Regards,
Andy Shevchenko
Wolfram Sang May 27, 2021, 8:30 p.m. | #2
On Wed, Apr 28, 2021 at 05:57:51PM +0300, Andy Shevchenko wrote:
> One may notice that dev_printk(KERN_DEBUG ...) is *not* an equivalent

> to dev_dbg(). It will be printed whenever loglevel is high enough.

> And currently it will be the only message in the I²C core in some

> configurations that got printed under above conditions.

> 

> Moving to dev_dbg() will hide it in the configurations where Dynamic Debug

> is enabled and hence align with all other debug messages in the I²C core..


OK in general.

> +	bool error_or_debug = true;


A bool having "or" in the name is quite confusing: "do you want this or
that" - "yes!" :) What about "is_error_level"?

Patch

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 5a97e4a02fa2..7f711853d464 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -399,7 +399,8 @@  static int i2c_gpio_init_recovery(struct i2c_adapter *adap)
 static int i2c_init_recovery(struct i2c_adapter *adap)
 {
 	struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
-	char *err_str, *err_level = KERN_ERR;
+	bool error_or_debug = true;
+	char *err_str;
 
 	if (!bri)
 		return 0;
@@ -409,7 +410,7 @@  static int i2c_init_recovery(struct i2c_adapter *adap)
 
 	if (!bri->recover_bus) {
 		err_str = "no suitable method provided";
-		err_level = KERN_DEBUG;
+		error_or_debug = false;
 		goto err;
 	}
 
@@ -436,7 +437,10 @@  static int i2c_init_recovery(struct i2c_adapter *adap)
 
 	return 0;
  err:
-	dev_printk(err_level, &adap->dev, "Not using recovery: %s\n", err_str);
+	if (error_or_debug)
+		dev_err(&adap->dev, "Not using recovery: %s\n", err_str);
+	else
+		dev_dbg(&adap->dev, "Not using recovery: %s\n", err_str);
 	adap->bus_recovery_info = NULL;
 
 	return -EINVAL;