diff mbox series

[4/8] rtc: max77686: remove useless variable

Message ID 20211011155615.257529-5-luca@lucaceresoli.net (mailing list archive)
State Not Applicable
Headers show
Series Add MAX77714 PMIC minimal driver (RTC and watchdog only) | expand

Commit Message

Luca Ceresoli Oct. 11, 2021, 3:56 p.m. UTC
rtc_24hr_mode is set to 1 in max77686_rtc_probe()->max77686_rtc_init_reg()
before being read and is never set back to 0 again. As such, it is de facto
a constant.

Remove the variable and the unreachable code.

Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
---
 drivers/rtc/rtc-max77686.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

Comments

Krzysztof Kozlowski Oct. 12, 2021, 8:01 a.m. UTC | #1
On 11/10/2021 17:56, Luca Ceresoli wrote:
> rtc_24hr_mode is set to 1 in max77686_rtc_probe()->max77686_rtc_init_reg()
> before being read and is never set back to 0 again. As such, it is de facto
> a constant.
> 
> Remove the variable and the unreachable code.
> 
> Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
> ---
>  drivers/rtc/rtc-max77686.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)
> 


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof
Alexandre Belloni Oct. 15, 2021, 5:33 p.m. UTC | #2
On 11/10/2021 17:56:11+0200, Luca Ceresoli wrote:
>> rtc_24hr_mode is set to 1 in max77686_rtc_probe()->max77686_rtc_init_reg()
> before being read and is never set back to 0 again. As such, it is de facto
> a constant.
> 
> Remove the variable and the unreachable code.
> 
> Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
> ---
>  drivers/rtc/rtc-max77686.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index 7e765207f28e..9901c596998a 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -99,7 +99,6 @@ struct max77686_rtc_info {
>  
>  	int rtc_irq;
>  	int virq;
> -	int rtc_24hr_mode;
>  };
>  
>  enum MAX77686_RTC_OP {
> @@ -278,13 +277,7 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
>  
>  	tm->tm_sec = data[RTC_SEC] & mask;
>  	tm->tm_min = data[RTC_MIN] & mask;
> -	if (info->rtc_24hr_mode) {
> -		tm->tm_hour = data[RTC_HOUR] & 0x1f;
> -	} else {
> -		tm->tm_hour = data[RTC_HOUR] & 0x0f;
> -		if (data[RTC_HOUR] & HOUR_PM_MASK)

So I guess HOUR_PM_SHIFT and HOUR_PM_MASK can also be removed

> -			tm->tm_hour += 12;
> -	}
> +	tm->tm_hour = data[RTC_HOUR] & 0x1f;
>  
>  	/* Only a single bit is set in data[], so fls() would be equivalent */
>  	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
> @@ -662,8 +655,6 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
>  	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
>  	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
>  
> -	info->rtc_24hr_mode = 1;
> -
>  	ret = regmap_bulk_write(info->rtc_regmap,
>  				info->drv_data->map[REG_RTC_CONTROLM],
>  				data, ARRAY_SIZE(data));
> -- 
> 2.25.1
>
Luca Ceresoli Oct. 15, 2021, 8:59 p.m. UTC | #3
Hi,

On 15/10/21 19:33, Alexandre Belloni wrote:
> On 11/10/2021 17:56:11+0200, Luca Ceresoli wrote:
>>> rtc_24hr_mode is set to 1 in max77686_rtc_probe()->max77686_rtc_init_reg()
>> before being read and is never set back to 0 again. As such, it is de facto
>> a constant.
>>
>> Remove the variable and the unreachable code.
>>
>> Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
>> ---
>>  drivers/rtc/rtc-max77686.c | 11 +----------
>>  1 file changed, 1 insertion(+), 10 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
>> index 7e765207f28e..9901c596998a 100644
>> --- a/drivers/rtc/rtc-max77686.c
>> +++ b/drivers/rtc/rtc-max77686.c
>> @@ -99,7 +99,6 @@ struct max77686_rtc_info {
>>  
>>  	int rtc_irq;
>>  	int virq;
>> -	int rtc_24hr_mode;
>>  };
>>  
>>  enum MAX77686_RTC_OP {
>> @@ -278,13 +277,7 @@ static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
>>  
>>  	tm->tm_sec = data[RTC_SEC] & mask;
>>  	tm->tm_min = data[RTC_MIN] & mask;
>> -	if (info->rtc_24hr_mode) {
>> -		tm->tm_hour = data[RTC_HOUR] & 0x1f;
>> -	} else {
>> -		tm->tm_hour = data[RTC_HOUR] & 0x0f;
>> -		if (data[RTC_HOUR] & HOUR_PM_MASK)
> 
> So I guess HOUR_PM_SHIFT and HOUR_PM_MASK can also be removed

Sure. Coming in v2.

Thanks.
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 7e765207f28e..9901c596998a 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -99,7 +99,6 @@  struct max77686_rtc_info {
 
 	int rtc_irq;
 	int virq;
-	int rtc_24hr_mode;
 };
 
 enum MAX77686_RTC_OP {
@@ -278,13 +277,7 @@  static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
 
 	tm->tm_sec = data[RTC_SEC] & mask;
 	tm->tm_min = data[RTC_MIN] & mask;
-	if (info->rtc_24hr_mode) {
-		tm->tm_hour = data[RTC_HOUR] & 0x1f;
-	} else {
-		tm->tm_hour = data[RTC_HOUR] & 0x0f;
-		if (data[RTC_HOUR] & HOUR_PM_MASK)
-			tm->tm_hour += 12;
-	}
+	tm->tm_hour = data[RTC_HOUR] & 0x1f;
 
 	/* Only a single bit is set in data[], so fls() would be equivalent */
 	tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1;
@@ -662,8 +655,6 @@  static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
 	data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
 	data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
 
-	info->rtc_24hr_mode = 1;
-
 	ret = regmap_bulk_write(info->rtc_regmap,
 				info->drv_data->map[REG_RTC_CONTROLM],
 				data, ARRAY_SIZE(data));