Skip to contentSkip to conversation

hwmon: ltc2947: Properly handle errors when looking for the external clock

PATCH Applied Uwe Kleine-König 2 participants 2 messages Sep 23, 2021 – Sep 24, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: ltc2947: Properly handle errors when looking for the external clock

The return value of devm_clk_get should in general be propagated to upper layer. In this case the clk is optional, use the appropriate wrapper instead of interpreting all errors as "The optional clk is not available".

---
 drivers/hwmon/ltc2947-core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/hwmon/ltc2947-core.c +6 -2
index bb3f7749a0b0..5423466de697 100644
@@ -989,8 +989,12 @@ static int ltc2947_setup(struct ltc2947_data *st)
 		return ret;
 
 	/* check external clock presence */
-	extclk = devm_clk_get(st->dev, NULL);
-	if (!IS_ERR(extclk)) {
+	extclk = devm_clk_get_optional(st->dev, NULL);
+	if (IS_ERR(extclk))
+		return dev_err_probe(st->dev, PTR_ERR(extclk),
+				     "Failed to get external clock\n");
+
+	if (extclk) {
 		unsigned long rate_hz;
 		u8 pre = 0, div, tbctl;
 		u64 aux;

base-commit: 7d2a07b769330c34b4deabeed939325c77a7ec2f

Signature · 1 line
2.30.2
maintainer Applied
#1 lore raw
Quoted 6 lines · Uwe Kleine-König

The return value of devm_clk_get should in general be propagated to upper layer. In this case the clk is optional, use the appropriate wrapper instead of interpreting all errors as "The optional clk is not available".

Applied.

Thanks,
Guenter

Quoted 26 lines
---
 drivers/hwmon/ltc2947-core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

base-commit: 7d2a07b769330c34b4deabeed939325c77a7ec2f

drivers/hwmon/ltc2947-core.c +6 -2
index bb3f7749a0b0..5423466de697 100644
@@ -989,8 +989,12 @@ static int ltc2947_setup(struct ltc2947_data *st)
 		return ret;
 
 	/* check external clock presence */
-	extclk = devm_clk_get(st->dev, NULL);
-	if (!IS_ERR(extclk)) {
+	extclk = devm_clk_get_optional(st->dev, NULL);
+	if (IS_ERR(extclk))
+		return dev_err_probe(st->dev, PTR_ERR(extclk),
+				     "Failed to get external clock\n");
+
+	if (extclk) {
 		unsigned long rate_hz;
 		u8 pre = 0, div, tbctl;
 		u64 aux;