Linux RTC
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@samsung.com>
To: Javier Martinez Canillas <javier@osg.samsung.com>
Cc: linux-kernel@vger.kernel.org, Kukjin Kim <kgene@kernel.org>,
	rtc-linux@googlegroups.com, Chanwoo Choi <cw00.choi@samsung.com>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	Krzysztof Kozlowski <k.kozlowski@samsung.com>,
	Laxman Dewangan <ldewangan@nvidia.com>,
	linux-samsung-soc@vger.kernel.org
Subject: [rtc-linux] Re: [PATCH v3 02/10] rtc: max77686: Use ARRAY_SIZE() instead of current array length
Date: Wed, 27 Jan 2016 10:20:34 +0900	[thread overview]
Message-ID: <20160127012034.GB14296@samsunx.samsung> (raw)
In-Reply-To: <1453836020-29579-3-git-send-email-javier@osg.samsung.com>

On Tue, Jan 26, 2016 at 04:20:12PM -0300, Javier Martinez Canillas wrote:
> 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: Javier Martinez Canillas <javier@osg.samsung.com>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Tested-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Reviewed-by: Andi Shyti <andi.shyti@samsung.com>

> ---
> 
> Changes in v3:
> - Add Krzysztof Kozlowski's Tested-by tag to patch #2.
> - Add Laxman Dewangan's Acked-by tag to patch #2.
> - Use ARRAY_SIZE() in all places. Suggested by Laxman Dewangan.
> 
> Changes in v2:
> - Add Krzysztof Kozlowski's Reviewed-by tag to patch #2.
> 
>  drivers/rtc/rtc-max77686.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 6653c3d11b66..d84a50c9f7f7 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -149,7 +149,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  		goto out;
>  
>  	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) {
>  		dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,	ret);
>  		goto out;
> @@ -177,7 +177,7 @@ static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  	mutex_lock(&info->lock);
>  
>  	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) {
>  		dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
>  				ret);
> @@ -205,7 +205,7 @@ static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  
>  	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) {
>  		dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
>  				__func__, __LINE__, ret);
> @@ -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);
>  
>  	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) {
>  			alrm->enabled = 1;
>  			break;
> @@ -252,7 +252,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  
>  	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) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -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);
>  
> -	for (i = 0; i < RTC_NR_TIME; i++)
> +	for (i = 0; i < ARRAY_SIZE(data); i++)
>  		data[i] &= ~ALARM_ENABLE_MASK;
>  
>  	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) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -291,7 +291,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		goto out;
>  
>  	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) {
>  		dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
>  				__func__, ret);
> @@ -312,7 +312,7 @@ static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
>  		data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
>  
>  	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) {
>  		dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
>  				__func__, ret);
> @@ -341,7 +341,7 @@ static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  		goto out;
>  
>  	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) {
>  		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)
>  
>  	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) {
>  		dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
>  				__func__, ret);
> -- 
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2016-01-27  1:20 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 19:20 [rtc-linux] [PATCH v3 00/10] rtc: max77686: Extend driver and add max77802 support Javier Martinez Canillas
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 01/10] rtc: max77686: Fix max77686_rtc_read_alarm() return value Javier Martinez Canillas
2016-01-27  1:19   ` [rtc-linux] " Andi Shyti
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 02/10] rtc: max77686: Use ARRAY_SIZE() instead of current array length Javier Martinez Canillas
2016-01-27  1:20   ` Andi Shyti [this message]
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 03/10] rtc: max77686: Use usleep_range() instead of msleep() Javier Martinez Canillas
2016-01-27  1:21   ` [rtc-linux] " Andi Shyti
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 04/10] rtc: max77686: Use a driver data struct instead hard-coded values Javier Martinez Canillas
2016-01-27  1:21   ` [rtc-linux] " Andi Shyti
2016-01-27  1:47   ` Krzysztof Kozlowski
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 05/10] rtc: max77686: Add an indirection level to access RTC registers Javier Martinez Canillas
2016-01-27  1:53   ` [rtc-linux] " Krzysztof Kozlowski
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 06/10] rtc: max77686: Add max77802 support Javier Martinez Canillas
2016-01-27  1:59   ` [rtc-linux] " Krzysztof Kozlowski
2016-01-27  2:24     ` Javier Martinez Canillas
2016-01-27  2:22   ` Andi Shyti
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 07/10] rtc: max77686: Use dev_warn() instead of pr_warn() Javier Martinez Canillas
2016-01-27  1:22   ` [rtc-linux] " Andi Shyti
2016-01-27  1:53     ` Javier Martinez Canillas
2016-01-27  2:05       ` Krzysztof Kozlowski
2016-01-27  2:20         ` Javier Martinez Canillas
2016-01-27  2:35         ` Andi Shyti
2016-01-27  2:42           ` Javier Martinez Canillas
2016-01-27  2:46         ` Alexandre Belloni
2016-01-27  2:50           ` Javier Martinez Canillas
2016-01-27  2:12       ` Andi Shyti
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 08/10] rtc: Remove Maxim 77802 driver Javier Martinez Canillas
2016-01-27  1:22   ` [rtc-linux] " Andi Shyti
2016-01-27  2:09   ` Krzysztof Kozlowski
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 09/10] ARM: exynos_defconfig: Remove MAX77802 RTC Kconfig symbol Javier Martinez Canillas
2016-01-26 19:20 ` [rtc-linux] [PATCH v3 10/10] ARM: multi_v7_defconfig: " Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160127012034.GB14296@samsunx.samsung \
    --to=andi.shyti@samsung.com \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=cw00.choi@samsung.com \
    --cc=javier@osg.samsung.com \
    --cc=k.kozlowski@samsung.com \
    --cc=kgene@kernel.org \
    --cc=ldewangan@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=rtc-linux@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox