aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2013-04-25 16:31:45 -0400
committerThomas Gleixner <tglx@linutronix.de>2013-05-16 05:09:15 -0400
commit29b5407819f59731c9423238fae03b756822708c (patch)
tree838fdee303cf292e1463ad347bd4dcbeafd7baa7 /kernel
parentf5a2e34375a5e2b711aea488ac3ae50eeba6d57c (diff)
clocksource: Split out user string input
Split out the user string input for clocksource override. Preparatory patch for unbind. [ jstultz: Fix an off by one error ] Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: John Stultz <john.stultz@linaro.org> Cc: Magnus Damm <magnus.damm@gmail.com> Link: http://lkml.kernel.org/r/20130425143435.895851338@linutronix.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/time/clocksource.c37
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)
174static struct clocksource *curr_clocksource; 174static struct clocksource *curr_clocksource;
175static LIST_HEAD(clocksource_list); 175static LIST_HEAD(clocksource_list);
176static DEFINE_MUTEX(clocksource_mutex); 176static DEFINE_MUTEX(clocksource_mutex);
177static char override_name[32]; 177#define CS_NAME_LEN 32
178static char override_name[CS_NAME_LEN];
178static int finished_booting; 179static 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
842static 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