Skip to contentSkip to conversation

rtc: abx80x: Provide feedback for invalid dt properties

PATCH Superseded Kevin P. Fleming 2 participants 4 messages May 29, 2020 Real time clock (RTC)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: abx80x: Provide feedback for invalid dt properties

When the user provides an invalid value for tc-diode or tc-resistor generate an error message instead of silently ignoring it.

---
 drivers/rtc/rtc-abx80x.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/rtc/rtc-abx80x.c +11 -6
index 3521d8e8dc38..dae046e3484a 100644
@@ -554,7 +554,8 @@ static const struct rtc_class_ops abx80x_rtc_ops = {
 	.ioctl		= abx80x_ioctl,
 };
 
-static int abx80x_dt_trickle_cfg(struct device_node *np)
+static int abx80x_dt_trickle_cfg(struct i2c_client *client,
+				 struct device_node *np)
 {
 	const char *diode;
 	int trickle_cfg = 0;
@@ -565,12 +566,14 @@ static int abx80x_dt_trickle_cfg(struct device_node *np)
 	if (ret)
 		return ret;
 
-	if (!strcmp(diode, "standard"))
+	if (!strcmp(diode, "standard")) {
 		trickle_cfg |= ABX8XX_TRICKLE_STANDARD_DIODE;
-	else if (!strcmp(diode, "schottky"))
+	} else if (!strcmp(diode, "schottky")) {
 		trickle_cfg |= ABX8XX_TRICKLE_SCHOTTKY_DIODE;
-	else
+	} else {
+		dev_err(&client->dev, "Invalid tc-diode value: %s\n", diode);
 		return -EINVAL;
+	}
 
 	ret = of_property_read_u32(np, "abracon,tc-resistor", &tmp);
 	if (ret)
@@ -580,8 +583,10 @@ static int abx80x_dt_trickle_cfg(struct device_node *np)
 		if (trickle_resistors[i] == tmp)
 			break;
 
-	if (i == sizeof(trickle_resistors))
+	if (i == sizeof(trickle_resistors)) {
+		dev_err(&client->dev, "Invalid tc-resistor value: %u\n", tmp);
 		return -EINVAL;
+	}
 
 	return (trickle_cfg | i);
 }
@@ -793,7 +798,7 @@ static int abx80x_probe(struct i2c_client *client,
 	}
 
 	if (np && abx80x_caps[part].has_tc)
-		trickle_cfg = abx80x_dt_trickle_cfg(np);
+		trickle_cfg = abx80x_dt_trickle_cfg(client, np);
 
 	if (trickle_cfg > 0) {
 		dev_info(&client->dev, "Enabling trickle charger: %02x\n",
Signature · 1 line
2.26.2
#1 lore raw

Hi,

Quoted 14 lines · Kevin P. Fleming

When the user provides an invalid value for tc-diode or tc-resistor generate an error message instead of silently ignoring it.

---
 drivers/rtc/rtc-abx80x.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/rtc/rtc-abx80x.c +0 -0
index 3521d8e8dc38..dae046e3484a 100644

drivers/rtc/rtc-abx80x.c static const struct rtc_class_ops abx80x_rtc_ops = { · line 558

Quoted 6 lines
drivers/rtc/rtc-abx80x.c +2 -1
@@ -554,7 +554,8 @@ static const struct rtc_class_ops abx80x_rtc_ops = {
 	.ioctl		= abx80x_ioctl,
 };
 
-static int abx80x_dt_trickle_cfg(struct device_node *np)
+static int abx80x_dt_trickle_cfg(struct i2c_client *client,
+				 struct device_node *np)

I would remove np from the parameters and use
struct device_node *np = client->dev.of_node;
in the function.

Quoted 6 lines
drivers/rtc/rtc-abx80x.c +0 -0
 {
 	const char *diode;
 	int trickle_cfg = 0;
@@ -565,12 +566,14 @@ static int abx80x_dt_trickle_cfg(struct device_node *np)
 	if (ret)
 		return ret;

drivers/rtc/rtc-abx80x.c static int abx80x_dt_trickle_cfg(struct device_node *np) · line 574

Quoted 10 lines
drivers/rtc/rtc-abx80x.c +4 -3
 
-	if (!strcmp(diode, "standard"))
+	if (!strcmp(diode, "standard")) {
 		trickle_cfg |= ABX8XX_TRICKLE_STANDARD_DIODE;
-	else if (!strcmp(diode, "schottky"))
+	} else if (!strcmp(diode, "schottky")) {
 		trickle_cfg |= ABX8XX_TRICKLE_SCHOTTKY_DIODE;
-	else
+	} else {
+		dev_err(&client->dev, "Invalid tc-diode value: %s\n", diode);

Can you make that dev_dbg? This is only ever needed at board bring up/ development time, so it is not necessary to bloat the kernel with more strings.

Quoted 29 lines
drivers/rtc/rtc-abx80x.c +5 -2
 		return -EINVAL;
+	}
 
 	ret = of_property_read_u32(np, "abracon,tc-resistor", &tmp);
 	if (ret)
@@ -580,8 +583,10 @@ static int abx80x_dt_trickle_cfg(struct device_node *np)
 		if (trickle_resistors[i] == tmp)
 			break;
 
-	if (i == sizeof(trickle_resistors))
+	if (i == sizeof(trickle_resistors)) {
+		dev_err(&client->dev, "Invalid tc-resistor value: %u\n", tmp);
 		return -EINVAL;
+	}
 
 	return (trickle_cfg | i);
 }
@@ -793,7 +798,7 @@ static int abx80x_probe(struct i2c_client *client,
 	}
 
 	if (np && abx80x_caps[part].has_tc)
-		trickle_cfg = abx80x_dt_trickle_cfg(np);
+		trickle_cfg = abx80x_dt_trickle_cfg(client, np);
 
 	if (trickle_cfg > 0) {
 		dev_info(&client->dev, "Enabling trickle charger: %02x\n",
Signature · 1 line
2.26.2
Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw
Quoted 7 lines · Alexandre Belloni

drivers/rtc/rtc-abx80x.c static const struct rtc_class_ops abx80x_rtc_ops = { · line 558

Quoted 3 lines
drivers/rtc/rtc-abx80x.c +2 -1
-static int abx80x_dt_trickle_cfg(struct device_node *np)
+static int abx80x_dt_trickle_cfg(struct i2c_client *client,
+                              struct device_node *np)

I would remove np from the parameters and use
struct device_node *np = client->dev.of_node;
in the function.

Will do.

Quoted 5 lines
Quoted 1 line

+ dev_err(&client->dev, "Invalid tc-diode value: %s\n", diode);

Can you make that dev_dbg? This is only ever needed at board bring up/ development time, so it is not necessary to bloat the kernel with more strings.

I'm using this driver via the Raspberry Pi device tree 'overlay' mechanism, so I'm setting these parameters in a configuration file and they are applied by the board's firmware before the kernel is booted. As a result this is essentially 'runtime' configuration, it's not a static device tree for the board, so end users like me could run into this problem.

I'd be fine with changing it to dev_info though, and indicating that the trickle charger won't be enabled in addition.

#3 lore raw
Quoted 18 lines · Kevin P. Fleming
Quoted 7 lines · Alexandre Belloni

drivers/rtc/rtc-abx80x.c static const struct rtc_class_ops abx80x_rtc_ops = { · line 558

Quoted 3 lines
drivers/rtc/rtc-abx80x.c +2 -1
-static int abx80x_dt_trickle_cfg(struct device_node *np)
+static int abx80x_dt_trickle_cfg(struct i2c_client *client,
+                              struct device_node *np)

I would remove np from the parameters and use
struct device_node *np = client->dev.of_node;
in the function.

Will do.

Quoted 5 lines
Quoted 1 line

+ dev_err(&client->dev, "Invalid tc-diode value: %s\n", diode);

Can you make that dev_dbg? This is only ever needed at board bring up/ development time, so it is not necessary to bloat the kernel with more strings.

Quoted 7 lines

I'm using this driver via the Raspberry Pi device tree 'overlay' mechanism, so I'm setting these parameters in a configuration file and they are applied by the board's firmware before the kernel is booted. As a result this is essentially 'runtime' configuration, it's not a static device tree for the board, so end users like me could run into this problem.

This is still board bringup, once it is correct, you will never need the message anymore. If the issue is device tree validation (i.e. typo in the string), then maybe you should convert the doc to yaml so you device tree and overlay could be checked.

Quoted 2 lines

I'd be fine with changing it to dev_info though, and indicating that the trickle charger won't be enabled in addition.

dev_info is worse, it is still bloating the kernel and also always printing in the kernel logs.

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com