Commit 862f9453 authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Alexandre Belloni

rtc: max77686: Use ARRAY_SIZE() instead of current array length

It is better to use the ARRAY_SIZE() macro instead of the array length
to avoid bugs if the array is later changed and the length not updated.
Signed-off-by: default avatarJavier Martinez Canillas <javier@osg.samsung.com>
Reviewed-by: default avatarKrzysztof Kozlowski <k.kozlowski@samsung.com>
Tested-by: default avatarKrzysztof Kozlowski <k.kozlowski@samsung.com>
Reviewed-by: default avatarAndi Shyti <andi.shyti@samsung.com>
Acked-by: default avatarLaxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 7cdffeb5
...@@ -149,7 +149,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -149,7 +149,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
goto out; goto out;
ret = regmap_bulk_read(info->max77686->rtc_regmap, ret = regmap_bulk_read(info->max77686->rtc_regmap,
MAX77686_RTC_SEC, data, RTC_NR_TIME); MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__, ret); dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__, ret);
goto out; goto out;
...@@ -177,7 +177,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -177,7 +177,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
mutex_lock(&info->lock); mutex_lock(&info->lock);
ret = regmap_bulk_write(info->max77686->rtc_regmap, ret = regmap_bulk_write(info->max77686->rtc_regmap,
MAX77686_RTC_SEC, data, RTC_NR_TIME); MAX77686_RTC_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__, dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
ret); ret);
...@@ -205,7 +205,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -205,7 +205,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
goto out; goto out;
ret = regmap_bulk_read(info->max77686->rtc_regmap, ret = regmap_bulk_read(info->max77686->rtc_regmap,
MAX77686_ALARM1_SEC, data, RTC_NR_TIME); MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n", dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
__func__, __LINE__, ret); __func__, __LINE__, ret);
...@@ -215,7 +215,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -215,7 +215,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
alrm->enabled = 0; alrm->enabled = 0;
for (i = 0; i < RTC_NR_TIME; i++) { for (i = 0; i < ARRAY_SIZE(data); i++) {
if (data[i] & ALARM_ENABLE_MASK) { if (data[i] & ALARM_ENABLE_MASK) {
alrm->enabled = 1; alrm->enabled = 1;
break; break;
...@@ -252,7 +252,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info) ...@@ -252,7 +252,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
goto out; goto out;
ret = regmap_bulk_read(info->max77686->rtc_regmap, ret = regmap_bulk_read(info->max77686->rtc_regmap,
MAX77686_ALARM1_SEC, data, RTC_NR_TIME); MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to read alarm reg(%d)\n", dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
__func__, ret); __func__, ret);
...@@ -261,11 +261,11 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info) ...@@ -261,11 +261,11 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode); max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
for (i = 0; i < RTC_NR_TIME; i++) for (i = 0; i < ARRAY_SIZE(data); i++)
data[i] &= ~ALARM_ENABLE_MASK; data[i] &= ~ALARM_ENABLE_MASK;
ret = regmap_bulk_write(info->max77686->rtc_regmap, ret = regmap_bulk_write(info->max77686->rtc_regmap,
MAX77686_ALARM1_SEC, data, RTC_NR_TIME); MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
__func__, ret); __func__, ret);
...@@ -291,7 +291,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info) ...@@ -291,7 +291,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
goto out; goto out;
ret = regmap_bulk_read(info->max77686->rtc_regmap, ret = regmap_bulk_read(info->max77686->rtc_regmap,
MAX77686_ALARM1_SEC, data, RTC_NR_TIME); MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to read alarm reg(%d)\n", dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
__func__, ret); __func__, ret);
...@@ -312,7 +312,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info) ...@@ -312,7 +312,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT); data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
ret = regmap_bulk_write(info->max77686->rtc_regmap, ret = regmap_bulk_write(info->max77686->rtc_regmap,
MAX77686_ALARM1_SEC, data, RTC_NR_TIME); MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
__func__, ret); __func__, ret);
...@@ -341,7 +341,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -341,7 +341,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
goto out; goto out;
ret = regmap_bulk_write(info->max77686->rtc_regmap, ret = regmap_bulk_write(info->max77686->rtc_regmap,
MAX77686_ALARM1_SEC, data, RTC_NR_TIME); MAX77686_ALARM1_SEC, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
...@@ -406,7 +406,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info) ...@@ -406,7 +406,8 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
info->rtc_24hr_mode = 1; info->rtc_24hr_mode = 1;
ret = regmap_bulk_write(info->max77686->rtc_regmap, MAX77686_RTC_CONTROLM, data, 2); ret = regmap_bulk_write(info->max77686->rtc_regmap,
MAX77686_RTC_CONTROLM, data, ARRAY_SIZE(data));
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "%s: fail to write controlm reg(%d)\n", dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
__func__, ret); __func__, 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