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>
This commit is contained in:
@@ -174,7 +174,8 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec)
|
|||||||
static struct clocksource *curr_clocksource;
|
static struct clocksource *curr_clocksource;
|
||||||
static LIST_HEAD(clocksource_list);
|
static LIST_HEAD(clocksource_list);
|
||||||
static DEFINE_MUTEX(clocksource_mutex);
|
static DEFINE_MUTEX(clocksource_mutex);
|
||||||
static char override_name[32];
|
#define CS_NAME_LEN 32
|
||||||
|
static char override_name[CS_NAME_LEN];
|
||||||
static int finished_booting;
|
static int finished_booting;
|
||||||
|
|
||||||
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
|
#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
|
||||||
@@ -838,6 +839,23 @@ sysfs_show_current_clocksources(struct device *dev,
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t clocksource_get_uname(const char *buf, char *dst, size_t cnt)
|
||||||
|
{
|
||||||
|
size_t ret = cnt;
|
||||||
|
|
||||||
|
/* strings from sysfs write are not 0 terminated! */
|
||||||
|
if (!cnt || cnt >= CS_NAME_LEN)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
/* strip of \n: */
|
||||||
|
if (buf[cnt-1] == '\n')
|
||||||
|
cnt--;
|
||||||
|
if (cnt > 0)
|
||||||
|
memcpy(dst, buf, cnt);
|
||||||
|
dst[cnt] = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sysfs_override_clocksource - interface for manually overriding clocksource
|
* sysfs_override_clocksource - interface for manually overriding clocksource
|
||||||
* @dev: unused
|
* @dev: unused
|
||||||
@@ -852,21 +870,12 @@ static ssize_t sysfs_override_clocksource(struct device *dev,
|
|||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
size_t ret = count;
|
size_t ret;
|
||||||
|
|
||||||
/* strings from sysfs write are not 0 terminated! */
|
|
||||||
if (count >= sizeof(override_name))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* strip of \n: */
|
|
||||||
if (buf[count-1] == '\n')
|
|
||||||
count--;
|
|
||||||
|
|
||||||
mutex_lock(&clocksource_mutex);
|
mutex_lock(&clocksource_mutex);
|
||||||
|
|
||||||
if (count > 0)
|
ret = clocksource_get_uname(buf, override_name, count);
|
||||||
memcpy(override_name, buf, count);
|
if (ret >= 0)
|
||||||
override_name[count] = 0;
|
|
||||||
clocksource_select();
|
clocksource_select();
|
||||||
|
|
||||||
mutex_unlock(&clocksource_mutex);
|
mutex_unlock(&clocksource_mutex);
|
||||||
|
Reference in New Issue
Block a user