diff options
author | Gustavo A. R. Silva <gustavo@embeddedor.com> | 2018-03-10 01:27:35 -0500 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-03-17 09:20:57 -0400 |
commit | 756d5282bf04db868b1c0b93f41981dabe2af57f (patch) | |
tree | 4631fc3f2adbe463c97c2ea3d3fd3b7dfaa45579 | |
parent | 4a681243cc2d2cea98c6b5e57224f3bcb08bce6c (diff) |
rtc: s5m: Remove VLA usage
In preparation to enabling -Wvla, remove VLAs and replace them
with fixed-length arrays instead.
>From a security viewpoint, the use of Variable Length Arrays can be
a vector for stack overflow attacks. Also, in general, as the code
evolves it is easy to lose track of how big a VLA can get. Thus, we
can end up having segfaults that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from
the kernel: https://lkml.org/lkml/2018/3/7/621
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r-- | drivers/rtc/rtc-s5m.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c index 4c363deb79fd..8428455432ca 100644 --- a/drivers/rtc/rtc-s5m.c +++ b/drivers/rtc/rtc-s5m.c | |||
@@ -47,6 +47,8 @@ enum { | |||
47 | RTC_MONTH, | 47 | RTC_MONTH, |
48 | RTC_YEAR1, | 48 | RTC_YEAR1, |
49 | RTC_YEAR2, | 49 | RTC_YEAR2, |
50 | /* Make sure this is always the last enum name. */ | ||
51 | RTC_MAX_NUM_TIME_REGS | ||
50 | }; | 52 | }; |
51 | 53 | ||
52 | /* | 54 | /* |
@@ -378,7 +380,7 @@ static void s5m8763_tm_to_data(struct rtc_time *tm, u8 *data) | |||
378 | static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm) | 380 | static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm) |
379 | { | 381 | { |
380 | struct s5m_rtc_info *info = dev_get_drvdata(dev); | 382 | struct s5m_rtc_info *info = dev_get_drvdata(dev); |
381 | u8 data[info->regs->regs_count]; | 383 | u8 data[RTC_MAX_NUM_TIME_REGS]; |
382 | int ret; | 384 | int ret; |
383 | 385 | ||
384 | if (info->regs->read_time_udr_mask) { | 386 | if (info->regs->read_time_udr_mask) { |
@@ -424,7 +426,7 @@ static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
424 | static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm) | 426 | static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm) |
425 | { | 427 | { |
426 | struct s5m_rtc_info *info = dev_get_drvdata(dev); | 428 | struct s5m_rtc_info *info = dev_get_drvdata(dev); |
427 | u8 data[info->regs->regs_count]; | 429 | u8 data[RTC_MAX_NUM_TIME_REGS]; |
428 | int ret = 0; | 430 | int ret = 0; |
429 | 431 | ||
430 | switch (info->device_type) { | 432 | switch (info->device_type) { |
@@ -461,7 +463,7 @@ static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
461 | static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 463 | static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
462 | { | 464 | { |
463 | struct s5m_rtc_info *info = dev_get_drvdata(dev); | 465 | struct s5m_rtc_info *info = dev_get_drvdata(dev); |
464 | u8 data[info->regs->regs_count]; | 466 | u8 data[RTC_MAX_NUM_TIME_REGS]; |
465 | unsigned int val; | 467 | unsigned int val; |
466 | int ret, i; | 468 | int ret, i; |
467 | 469 | ||
@@ -511,7 +513,7 @@ static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
511 | 513 | ||
512 | static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info) | 514 | static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info) |
513 | { | 515 | { |
514 | u8 data[info->regs->regs_count]; | 516 | u8 data[RTC_MAX_NUM_TIME_REGS]; |
515 | int ret, i; | 517 | int ret, i; |
516 | struct rtc_time tm; | 518 | struct rtc_time tm; |
517 | 519 | ||
@@ -556,7 +558,7 @@ static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info) | |||
556 | static int s5m_rtc_start_alarm(struct s5m_rtc_info *info) | 558 | static int s5m_rtc_start_alarm(struct s5m_rtc_info *info) |
557 | { | 559 | { |
558 | int ret; | 560 | int ret; |
559 | u8 data[info->regs->regs_count]; | 561 | u8 data[RTC_MAX_NUM_TIME_REGS]; |
560 | u8 alarm0_conf; | 562 | u8 alarm0_conf; |
561 | struct rtc_time tm; | 563 | struct rtc_time tm; |
562 | 564 | ||
@@ -609,7 +611,7 @@ static int s5m_rtc_start_alarm(struct s5m_rtc_info *info) | |||
609 | static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 611 | static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
610 | { | 612 | { |
611 | struct s5m_rtc_info *info = dev_get_drvdata(dev); | 613 | struct s5m_rtc_info *info = dev_get_drvdata(dev); |
612 | u8 data[info->regs->regs_count]; | 614 | u8 data[RTC_MAX_NUM_TIME_REGS]; |
613 | int ret; | 615 | int ret; |
614 | 616 | ||
615 | switch (info->device_type) { | 617 | switch (info->device_type) { |