Commit 5d049837 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: ab-b5ze-s3: remove unnecessary gotos

Rework error handling to remove unnecessary gotos.
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent ac246738
...@@ -227,14 +227,12 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -227,14 +227,12 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm)
if (ret) { if (ret) {
dev_err(dev, "%s: reading RTC time failed (%d)\n", dev_err(dev, "%s: reading RTC time failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
/* If clock integrity is not guaranteed, do not return a time value */ /* If clock integrity is not guaranteed, do not return a time value */
if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC) { if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC)
ret = -ENODATA; return -ENODATA;
goto err;
}
tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F); tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F);
tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]); tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]);
...@@ -252,7 +250,6 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -252,7 +250,6 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm)
tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */ tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */
tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100; tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100;
err:
return ret; return ret;
} }
...@@ -326,23 +323,23 @@ static int _abb5zes3_rtc_read_timer(struct device *dev, ...@@ -326,23 +323,23 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,
if (ret) { if (ret) {
dev_err(dev, "%s: reading Timer A section failed (%d)\n", dev_err(dev, "%s: reading Timer A section failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
/* get current time ... */ /* get current time ... */
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret) if (ret)
goto err; return ret;
/* ... convert to seconds ... */ /* ... convert to seconds ... */
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
if (ret) if (ret)
goto err; return ret;
/* ... add remaining timer A time ... */ /* ... add remaining timer A time ... */
ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]); ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]);
if (ret) if (ret)
goto err; return ret;
/* ... and convert back. */ /* ... and convert back. */
rtc_time_to_tm(rtc_secs + timer_secs, alarm_tm); rtc_time_to_tm(rtc_secs + timer_secs, alarm_tm);
...@@ -351,13 +348,12 @@ static int _abb5zes3_rtc_read_timer(struct device *dev, ...@@ -351,13 +348,12 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,
if (ret) { if (ret) {
dev_err(dev, "%s: reading ctrl reg failed (%d)\n", dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE); alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE);
err: return 0;
return ret;
} }
/* Read alarm currently configured via a RTC alarm registers. */ /* Read alarm currently configured via a RTC alarm registers. */
...@@ -376,7 +372,7 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, ...@@ -376,7 +372,7 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
if (ret) { if (ret) {
dev_err(dev, "%s: reading alarm section failed (%d)\n", dev_err(dev, "%s: reading alarm section failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
alarm_tm->tm_sec = 0; alarm_tm->tm_sec = 0;
...@@ -392,18 +388,18 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, ...@@ -392,18 +388,18 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
*/ */
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret) if (ret)
goto err; return ret;
alarm_tm->tm_year = rtc_tm.tm_year; alarm_tm->tm_year = rtc_tm.tm_year;
alarm_tm->tm_mon = rtc_tm.tm_mon; alarm_tm->tm_mon = rtc_tm.tm_mon;
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
if (ret) if (ret)
goto err; return ret;
ret = rtc_tm_to_time(alarm_tm, &alarm_secs); ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
if (ret) if (ret)
goto err; return ret;
if (alarm_secs < rtc_secs) { if (alarm_secs < rtc_secs) {
if (alarm_tm->tm_mon == 11) { if (alarm_tm->tm_mon == 11) {
...@@ -418,13 +414,12 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, ...@@ -418,13 +414,12 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
if (ret) { if (ret) {
dev_err(dev, "%s: reading ctrl reg failed (%d)\n", dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE); alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE);
err: return 0;
return ret;
} }
/* /*
...@@ -465,15 +460,15 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -465,15 +460,15 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret) if (ret)
goto err; return ret;
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
if (ret) if (ret)
goto err; return ret;
ret = rtc_tm_to_time(alarm_tm, &alarm_secs); ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
if (ret) if (ret)
goto err; return ret;
/* If alarm time is before current time, disable the alarm */ /* If alarm time is before current time, disable the alarm */
if (!alarm->enabled || alarm_secs <= rtc_secs) { if (!alarm->enabled || alarm_secs <= rtc_secs) {
...@@ -494,13 +489,12 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -494,13 +489,12 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
if (ret) if (ret)
goto err; return ret;
if (alarm_secs > rtc_secs) { if (alarm_secs > rtc_secs) {
dev_err(dev, "%s: alarm maximum is one month in the " dev_err(dev, "%s: alarm maximum is one month in the "
"future (%d)\n", __func__, ret); "future (%d)\n", __func__, ret);
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
...@@ -518,17 +512,14 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -518,17 +512,14 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: writing ALARM section failed (%d)\n", dev_err(dev, "%s: writing ALARM section failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
/* Record currently configured alarm is not a timer */ /* Record currently configured alarm is not a timer */
data->timer_alarm = 0; data->timer_alarm = 0;
/* Enable or disable alarm interrupt generation */ /* Enable or disable alarm interrupt generation */
ret = _abb5zes3_rtc_update_alarm(dev, enable); return _abb5zes3_rtc_update_alarm(dev, enable);
err:
return ret;
} }
/* /*
...@@ -549,7 +540,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, ...@@ -549,7 +540,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm,
ABB5ZES3_TIMA_SEC_LEN); ABB5ZES3_TIMA_SEC_LEN);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: writing timer section failed\n", __func__); dev_err(dev, "%s: writing timer section failed\n", __func__);
goto err; return ret;
} }
/* Configure Timer A as a watchdog timer */ /* Configure Timer A as a watchdog timer */
...@@ -562,10 +553,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, ...@@ -562,10 +553,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm,
data->timer_alarm = 1; data->timer_alarm = 1;
/* Enable or disable timer interrupt generation */ /* Enable or disable timer interrupt generation */
ret = _abb5zes3_rtc_update_timer(dev, alarm->enabled); return _abb5zes3_rtc_update_timer(dev, alarm->enabled);
err:
return ret;
} }
/* /*
...@@ -584,28 +572,28 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -584,28 +572,28 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret) if (ret)
goto err; return ret;
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
if (ret) if (ret)
goto err; return ret;
ret = rtc_tm_to_time(alarm_tm, &alarm_secs); ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
if (ret) if (ret)
goto err; return ret;
/* Let's first disable both the alarm and the timer interrupts */ /* Let's first disable both the alarm and the timer interrupts */
ret = _abb5zes3_rtc_update_alarm(dev, false); ret = _abb5zes3_rtc_update_alarm(dev, false);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__, dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__,
ret); ret);
goto err; return ret;
} }
ret = _abb5zes3_rtc_update_timer(dev, false); ret = _abb5zes3_rtc_update_timer(dev, false);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: unable to disable timer (%d)\n", __func__, dev_err(dev, "%s: unable to disable timer (%d)\n", __func__,
ret); ret);
goto err; return ret;
} }
data->timer_alarm = 0; data->timer_alarm = 0;
...@@ -620,7 +608,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -620,7 +608,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
else else
ret = _abb5zes3_rtc_set_alarm(dev, alarm); ret = _abb5zes3_rtc_set_alarm(dev, alarm);
err:
if (ret) if (ret)
dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__, dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__,
ret); ret);
...@@ -871,42 +858,38 @@ static int abb5zes3_probe(struct i2c_client *client, ...@@ -871,42 +858,38 @@ static int abb5zes3_probe(struct i2c_client *client,
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_I2C_BLOCK)) { I2C_FUNC_SMBUS_I2C_BLOCK))
ret = -ENODEV; return -ENODEV;
goto err;
}
regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config); regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap)) {
ret = PTR_ERR(regmap); ret = PTR_ERR(regmap);
dev_err(dev, "%s: regmap allocation failed: %d\n", dev_err(dev, "%s: regmap allocation failed: %d\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
ret = abb5zes3_i2c_validate_chip(regmap); ret = abb5zes3_i2c_validate_chip(regmap);
if (ret) if (ret)
goto err; return ret;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data) { if (!data)
ret = -ENOMEM; return -ENOMEM;
goto err;
}
data->regmap = regmap; data->regmap = regmap;
dev_set_drvdata(dev, data); dev_set_drvdata(dev, data);
ret = abb5zes3_rtc_check_setup(dev); ret = abb5zes3_rtc_check_setup(dev);
if (ret) if (ret)
goto err; return ret;
data->rtc = devm_rtc_allocate_device(dev); data->rtc = devm_rtc_allocate_device(dev);
ret = PTR_ERR_OR_ZERO(data->rtc); ret = PTR_ERR_OR_ZERO(data->rtc);
if (ret) { if (ret) {
dev_err(dev, "%s: unable to allocate RTC device (%d)\n", dev_err(dev, "%s: unable to allocate RTC device (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
if (client->irq > 0) { if (client->irq > 0) {
...@@ -943,7 +926,7 @@ static int abb5zes3_probe(struct i2c_client *client, ...@@ -943,7 +926,7 @@ static int abb5zes3_probe(struct i2c_client *client,
ret = rtc_register_device(data->rtc); ret = rtc_register_device(data->rtc);
err: err:
if (ret && data && data->irq) if (ret && data->irq)
device_init_wakeup(dev, false); device_init_wakeup(dev, false);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment