Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ad2c174 authored by Enrico Scholz's avatar Enrico Scholz Committed by Alexandre Belloni
Browse files

rtc: da9063: avoid writing undefined data to rtc



driver did

| static void da9063_tm_to_data(struct rtc_time *tm, u8 *data,
| {
|  	const struct da9063_compatible_rtc_regmap *config = rtc->config;
|
| 	data[RTC_SEC] &= ~config->rtc_count_sec_mask;
| 	data[RTC_SEC] |= tm->tm_sec & config->rtc_count_sec_mask;
| ...
| }
| ...
| static int da9063_rtc_set_time(struct device *dev, struct rtc_time *tm)
| {
|       ...
|	u8 data[RTC_DATA_LEN];
|	int ret;
|
|	da9063_tm_to_data(tm, data, rtc);

which means that some bits of stack content (in 'data[]') was masked out
and written to the RTC.

Because da9063_tm_to_data() is used only by da9063_rtc_set_time() and
da9063_rtc_set_alarm(), we can write fields directly.

Signed-off-by: default avatarEnrico Scholz <enrico.scholz@sigma-chemnitz.de>
Acked-by: default avatarSteve Twiss <stwiss.opensource@diasemi.com>
Tested-by: default avatarSteve Twiss <stwiss.opensource@diasemi.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 4d833d60
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -191,24 +191,13 @@ static void da9063_tm_to_data(struct rtc_time *tm, u8 *data,
{
	const struct da9063_compatible_rtc_regmap *config = rtc->config;

	data[RTC_SEC] &= ~config->rtc_count_sec_mask;
	data[RTC_SEC] |= tm->tm_sec & config->rtc_count_sec_mask;

	data[RTC_MIN] &= ~config->rtc_count_min_mask;
	data[RTC_MIN] |= tm->tm_min & config->rtc_count_min_mask;

	data[RTC_HOUR] &= ~config->rtc_count_hour_mask;
	data[RTC_HOUR] |= tm->tm_hour & config->rtc_count_hour_mask;

	data[RTC_DAY] &= ~config->rtc_count_day_mask;
	data[RTC_DAY] |= tm->tm_mday & config->rtc_count_day_mask;

	data[RTC_MONTH] &= ~config->rtc_count_month_mask;
	data[RTC_MONTH] |= MONTHS_TO_DA9063(tm->tm_mon) &
	data[RTC_SEC]   = tm->tm_sec & config->rtc_count_sec_mask;
	data[RTC_MIN]   = tm->tm_min & config->rtc_count_min_mask;
	data[RTC_HOUR]  = tm->tm_hour & config->rtc_count_hour_mask;
	data[RTC_DAY]   = tm->tm_mday & config->rtc_count_day_mask;
	data[RTC_MONTH] = MONTHS_TO_DA9063(tm->tm_mon) &
				config->rtc_count_month_mask;

	data[RTC_YEAR] &= ~config->rtc_count_year_mask;
	data[RTC_YEAR] |= YEARS_TO_DA9063(tm->tm_year) &
	data[RTC_YEAR]  = YEARS_TO_DA9063(tm->tm_year) &
				config->rtc_count_year_mask;
}