diff options
-rw-r--r-- | kernel/time/clocksource.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 9782997cb6cf..d7f1a45c2fa5 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c | |||
@@ -174,7 +174,8 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec) | |||
174 | static struct clocksource *curr_clocksource; | 174 | static struct clocksource *curr_clocksource; |
175 | static LIST_HEAD(clocksource_list); | 175 | static LIST_HEAD(clocksource_list); |
176 | static DEFINE_MUTEX(clocksource_mutex); | 176 | static DEFINE_MUTEX(clocksource_mutex); |
177 | static char override_name[32]; | 177 | #define CS_NAME_LEN 32 |
178 | static char override_name[CS_NAME_LEN]; | ||
178 | static int finished_booting; | 179 | static int finished_booting; |
179 | 180 | ||
180 | #ifdef CONFIG_CLOCKSOURCE_WATCHDOG | 181 | #ifdef CONFIG_CLOCKSOURCE_WATCHDOG |
@@ -838,6 +839,23 @@ sysfs_show_current_clocksources(struct device *dev, | |||
838 | return count; | 839 | return count; |
839 | } | 840 | } |
840 | 841 | ||
842 | static size_t clocksource_get_uname(const char *buf, char *dst, size_t cnt) | ||
843 | { | ||
844 | size_t ret = cnt; | ||
845 | |||
846 | /* strings from sysfs write are not 0 terminated! */ | ||
847 | if (!cnt || cnt >= CS_NAME_LEN) | ||
848 | return -EINVAL; | ||
849 | |||
850 | /* strip of \n: */ | ||
851 | if (buf[cnt-1] == '\n') | ||
852 | cnt--; | ||
853 | if (cnt > 0) | ||
854 | memcpy(dst, buf, cnt); | ||
855 | dst[cnt] = 0; | ||
856 | return ret; | ||
857 | } | ||
858 | |||
841 | /** | 859 | /** |
842 | * sysfs_override_clocksource - interface for manually overriding clocksource | 860 | * sysfs_override_clocksource - interface for manually overriding clocksource |
843 | * @dev: unused | 861 | * @dev: unused |
@@ -852,22 +870,13 @@ static ssize_t sysfs_override_clocksource(struct device *dev, | |||
852 | struct device_attribute *attr, | 870 | struct device_attribute *attr, |
853 | const char *buf, size_t count) | 871 | const char *buf, size_t count) |
854 | { | 872 | { |
855 | size_t ret = count; | 873 | size_t ret; |
856 | |||
857 | /* strings from sysfs write are not 0 terminated! */ | ||
858 | if (count >= sizeof(override_name)) | ||
859 | return -EINVAL; | ||
860 | |||
861 | /* strip of \n: */ | ||
862 | if (buf[count-1] == '\n') | ||
863 | count--; | ||
864 | 874 | ||
865 | mutex_lock(&clocksource_mutex); | 875 | mutex_lock(&clocksource_mutex); |
866 | 876 | ||
867 | if (count > 0) | 877 | ret = clocksource_get_uname(buf, override_name, count); |
868 | memcpy(override_name, buf, count); | 878 | if (ret >= 0) |
869 | override_name[count] = 0; | 879 | clocksource_select(); |
870 | clocksource_select(); | ||
871 | 880 | ||
872 | mutex_unlock(&clocksource_mutex); | 881 | mutex_unlock(&clocksource_mutex); |
873 | 882 | ||