diff options
author | Stefan Wahren <stefan.wahren@i2se.com> | 2015-06-10 02:13:15 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-06-10 06:09:30 -0400 |
commit | 5751a99fe971262f3701922d116bcde7e9045b17 (patch) | |
tree | 9c6ee5845dda82c7eafbd84148014dde44cc89a0 | |
parent | 96dc589624954fea915c1cee90e0987ff9631386 (diff) |
regulator: core: replace sprintf with scnprintf
In order to avoid potential overflows in print_constraints we
better replace sprintf() with scnprintf().
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/core.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 6b9edb525d74..9da5c5559147 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -780,58 +780,63 @@ static void print_constraints(struct regulator_dev *rdev) | |||
780 | { | 780 | { |
781 | struct regulation_constraints *constraints = rdev->constraints; | 781 | struct regulation_constraints *constraints = rdev->constraints; |
782 | char buf[160] = ""; | 782 | char buf[160] = ""; |
783 | size_t len = sizeof(buf) - 1; | ||
783 | int count = 0; | 784 | int count = 0; |
784 | int ret; | 785 | int ret; |
785 | 786 | ||
786 | if (constraints->min_uV && constraints->max_uV) { | 787 | if (constraints->min_uV && constraints->max_uV) { |
787 | if (constraints->min_uV == constraints->max_uV) | 788 | if (constraints->min_uV == constraints->max_uV) |
788 | count += sprintf(buf + count, "%d mV ", | 789 | count += scnprintf(buf + count, len - count, "%d mV ", |
789 | constraints->min_uV / 1000); | 790 | constraints->min_uV / 1000); |
790 | else | 791 | else |
791 | count += sprintf(buf + count, "%d <--> %d mV ", | 792 | count += scnprintf(buf + count, len - count, |
792 | constraints->min_uV / 1000, | 793 | "%d <--> %d mV ", |
793 | constraints->max_uV / 1000); | 794 | constraints->min_uV / 1000, |
795 | constraints->max_uV / 1000); | ||
794 | } | 796 | } |
795 | 797 | ||
796 | if (!constraints->min_uV || | 798 | if (!constraints->min_uV || |
797 | constraints->min_uV != constraints->max_uV) { | 799 | constraints->min_uV != constraints->max_uV) { |
798 | ret = _regulator_get_voltage(rdev); | 800 | ret = _regulator_get_voltage(rdev); |
799 | if (ret > 0) | 801 | if (ret > 0) |
800 | count += sprintf(buf + count, "at %d mV ", ret / 1000); | 802 | count += scnprintf(buf + count, len - count, |
803 | "at %d mV ", ret / 1000); | ||
801 | } | 804 | } |
802 | 805 | ||
803 | if (constraints->uV_offset) | 806 | if (constraints->uV_offset) |
804 | count += sprintf(buf + count, "%dmV offset ", | 807 | count += scnprintf(buf + count, len - count, "%dmV offset ", |
805 | constraints->uV_offset / 1000); | 808 | constraints->uV_offset / 1000); |
806 | 809 | ||
807 | if (constraints->min_uA && constraints->max_uA) { | 810 | if (constraints->min_uA && constraints->max_uA) { |
808 | if (constraints->min_uA == constraints->max_uA) | 811 | if (constraints->min_uA == constraints->max_uA) |
809 | count += sprintf(buf + count, "%d mA ", | 812 | count += scnprintf(buf + count, len - count, "%d mA ", |
810 | constraints->min_uA / 1000); | 813 | constraints->min_uA / 1000); |
811 | else | 814 | else |
812 | count += sprintf(buf + count, "%d <--> %d mA ", | 815 | count += scnprintf(buf + count, len - count, |
813 | constraints->min_uA / 1000, | 816 | "%d <--> %d mA ", |
814 | constraints->max_uA / 1000); | 817 | constraints->min_uA / 1000, |
818 | constraints->max_uA / 1000); | ||
815 | } | 819 | } |
816 | 820 | ||
817 | if (!constraints->min_uA || | 821 | if (!constraints->min_uA || |
818 | constraints->min_uA != constraints->max_uA) { | 822 | constraints->min_uA != constraints->max_uA) { |
819 | ret = _regulator_get_current_limit(rdev); | 823 | ret = _regulator_get_current_limit(rdev); |
820 | if (ret > 0) | 824 | if (ret > 0) |
821 | count += sprintf(buf + count, "at %d mA ", ret / 1000); | 825 | count += scnprintf(buf + count, len - count, |
826 | "at %d mA ", ret / 1000); | ||
822 | } | 827 | } |
823 | 828 | ||
824 | if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) | 829 | if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) |
825 | count += sprintf(buf + count, "fast "); | 830 | count += scnprintf(buf + count, len - count, "fast "); |
826 | if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) | 831 | if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) |
827 | count += sprintf(buf + count, "normal "); | 832 | count += scnprintf(buf + count, len - count, "normal "); |
828 | if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) | 833 | if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) |
829 | count += sprintf(buf + count, "idle "); | 834 | count += scnprintf(buf + count, len - count, "idle "); |
830 | if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) | 835 | if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) |
831 | count += sprintf(buf + count, "standby"); | 836 | count += scnprintf(buf + count, len - count, "standby"); |
832 | 837 | ||
833 | if (!count) | 838 | if (!count) |
834 | sprintf(buf, "no parameters"); | 839 | scnprintf(buf, len, "no parameters"); |
835 | 840 | ||
836 | rdev_dbg(rdev, "%s\n", buf); | 841 | rdev_dbg(rdev, "%s\n", buf); |
837 | 842 | ||