From 0e21bc24240c87318ac79a8b186e5b9d22944808 Mon Sep 17 00:00:00 2001 From: Gobinda Joy Date: Sat, 2 Sep 2017 14:06:28 +0600 Subject: [PATCH] Squashed Commits Update deprecated Alarm driver users to upstream Alarmtimer driver. ---------------------------------- timerfd: Protect the might cancel mechanism proper commit 1e38da300e1e395a15048b0af1e5305bd91402f6 upstream. The handling of the might_cancel queueing is not properly protected, so parallel operations on the file descriptor can race with each other and lead to list corruptions or use after free. Protect the context for these operations with a seperate lock. The wait queue lock cannot be reused for this because that would create a lock inversion scenario vs. the cancel lock. Replacing might_cancel with an atomic (atomic_t or atomic bit) does not help either because it still can race vs. the actual list operation. Bug: 36266767 Reported-by: Dmitry Vyukov Signed-off-by: Thomas Gleixner Cc: "linux-fsdevel@vger.kernel.org" Cc: syzkaller Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org Link: http://lkml.kernel.org/r/alpine.DEB.2.20.1701311521430.3457@nanos Signed-off-by: Thomas Gleixner Signed-off-by: Greg Kroah-Hartman Signed-off-by: Siqi Lin Change-Id: I122753e0920e51757d3012cd1a133e823719be51 ---------------------------------- zcache, zram: use lzo instead of lz4 compression. ---------------------------------- Cleanup sound_control_3_gpl driver. ---------------------------------- rtc: alarm: Change wake-up source Currently, RTC_ALARM is used to wake-up target from suspend state and is also used for power-off alarm feature. This patch uses qtimer to wake-up from suspend state. Change-Id: Ia42cfecd573309be2f03c18b4f1c321be8202d7d Signed-off-by: Mohit Aggarwal Signed-off-by: Gobinda Joy # Conflicts: # drivers/battery/sec_battery.c # drivers/sensorhub/stm32f/ssp.h # drivers/sensorhub/stm32f/ssp_dev.c # drivers/staging/android/alarm-dev.c # fs/timerfd.c # include/linux/battery/sec_battery.h --- arch/arm/mach-msm/include/mach/cpuidle.h | 1 + arch/arm/mach-msm/lpm_levels.c | 27 ++++++-- drivers/staging/android/alarm-dev.c | 35 ++++++++-- drivers/staging/android/android_alarm.h | 3 + include/linux/clockchips.h | 3 +- kernel/time/clocksource.c | 6 +- sound/soc/codecs/sound_control_3_gpl.c | 88 +++++++++++------------- 7 files changed, 103 insertions(+), 60 deletions(-) diff --git a/arch/arm/mach-msm/include/mach/cpuidle.h b/arch/arm/mach-msm/include/mach/cpuidle.h index fef7a5a9be6..1308fb5103e 100644 --- a/arch/arm/mach-msm/include/mach/cpuidle.h +++ b/arch/arm/mach-msm/include/mach/cpuidle.h @@ -27,6 +27,7 @@ struct msm_cpuidle_state { #ifdef CONFIG_PM s32 msm_cpuidle_get_deep_idle_latency(void); +void lpm_suspend_wake_time(uint64_t wakeup_time); #else static inline s32 msm_cpuidle_get_deep_idle_latency(void) { return 0; } #endif diff --git a/arch/arm/mach-msm/lpm_levels.c b/arch/arm/mach-msm/lpm_levels.c index dcab0e19e3d..fe7190f60d6 100644 --- a/arch/arm/mach-msm/lpm_levels.c +++ b/arch/arm/mach-msm/lpm_levels.c @@ -139,6 +139,8 @@ static int msm_pm_sleep_time_override; module_param_named(sleep_time_override, msm_pm_sleep_time_override, int, S_IRUGO | S_IWUSR | S_IWGRP); +static uint64_t suspend_wake_time; + static int msm_pm_sleep_sec_debug; module_param_named(secdebug, msm_pm_sleep_sec_debug, int, S_IRUGO | S_IWUSR | S_IWGRP); @@ -395,8 +397,11 @@ static void lpm_system_prepare(struct lpm_system_state *system_state, } + if (!suspend_wake_time) + suspend_wake_time = msm_pm_sleep_time_override; + if (!from_idle) - us = USEC_PER_SEC * msm_pm_sleep_time_override; + us = USEC_PER_SEC * suspend_wake_time; do_div(us, USEC_PER_SEC/SCLK_HZ); sclk = (uint32_t)us; @@ -474,6 +479,21 @@ s32 msm_cpuidle_get_deep_idle_latency(void) return level->pwr.latency_us; } +void lpm_suspend_wake_time(uint64_t wakeup_time) +{ + if (wakeup_time <= 0) { + suspend_wake_time = msm_pm_sleep_time_override; + return; + } + + if (msm_pm_sleep_time_override && + (msm_pm_sleep_time_override < wakeup_time)) + suspend_wake_time = msm_pm_sleep_time_override; + else + suspend_wake_time = wakeup_time; +} +EXPORT_SYMBOL(lpm_suspend_wake_time); + static int lpm_cpu_callback(struct notifier_block *cpu_nb, unsigned long action, void *hcpu) { @@ -525,8 +545,7 @@ static noinline int lpm_cpu_power_select(struct cpuidle_device *dev, int *index) if (!sys_state.cpu_level) return -EINVAL; - if (!dev->cpu) - next_event_us = (uint32_t)(ktime_to_us(get_next_event_time())); + next_event_us = (uint32_t)(ktime_to_us(get_next_event_time(dev->cpu))); for (i = 0; i < sys_state.num_cpu_levels; i++) { struct lpm_cpu_level *level = &sys_state.cpu_level[i]; @@ -587,7 +606,7 @@ static noinline int lpm_cpu_power_select(struct cpuidle_device *dev, int *index) } } - if (modified_time_us && !dev->cpu) + if (modified_time_us) msm_pm_set_timer(modified_time_us); return best_level; diff --git a/drivers/staging/android/alarm-dev.c b/drivers/staging/android/alarm-dev.c index 8addd5da7c9..8741bb13d2a 100644 --- a/drivers/staging/android/alarm-dev.c +++ b/drivers/staging/android/alarm-dev.c @@ -41,10 +41,12 @@ do { \ #define ANDROID_ALARM_WAKEUP_MASK ( \ ANDROID_ALARM_RTC_WAKEUP_MASK | \ - ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK) + ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK | \ + ANDROID_ALARM_RTC_POWEROFF_WAKEUP_MASK) static int alarm_opened; static DEFINE_SPINLOCK(alarm_slock); +static DEFINE_MUTEX(alarm_mutex); static struct wakeup_source alarm_wake_lock; static DECLARE_WAIT_QUEUE_HEAD(alarm_wait_queue); static uint32_t alarm_pending; @@ -65,7 +67,8 @@ static struct devalarm alarms[ANDROID_ALARM_TYPE_COUNT]; static int is_wakeup(enum android_alarm_type type) { return (type == ANDROID_ALARM_RTC_WAKEUP || - type == ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP); + type == ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP || + type == ANDROID_ALARM_RTC_POWEROFF_WAKEUP); } @@ -93,11 +96,12 @@ static void devalarm_cancel(struct devalarm *alrm) hrtimer_cancel(&alrm->u.hrt); } -static void alarm_clear(enum android_alarm_type alarm_type) +static void alarm_clear(enum android_alarm_type alarm_type, struct timespec *ts) { uint32_t alarm_type_mask = 1U << alarm_type; unsigned long flags; + mutex_lock(&alarm_mutex); spin_lock_irqsave(&alarm_slock, flags); alarm_dbg(IO, "alarm %d clear\n", alarm_type); devalarm_try_to_cancel(&alarms[alarm_type]); @@ -109,6 +113,11 @@ static void alarm_clear(enum android_alarm_type alarm_type) alarm_enabled &= ~alarm_type_mask; spin_unlock_irqrestore(&alarm_slock, flags); +#if 0 + if (alarm_type == ANDROID_ALARM_RTC_POWEROFF_WAKEUP) + set_power_on_alarm(ts->tv_sec, 0); +#endif + mutex_unlock(&alarm_mutex); } static void alarm_set(enum android_alarm_type alarm_type, @@ -117,12 +126,19 @@ static void alarm_set(enum android_alarm_type alarm_type, uint32_t alarm_type_mask = 1U << alarm_type; unsigned long flags; + mutex_lock(&alarm_mutex); spin_lock_irqsave(&alarm_slock, flags); alarm_dbg(IO, "alarm %d set %ld.%09ld\n", alarm_type, ts->tv_sec, ts->tv_nsec); alarm_enabled |= alarm_type_mask; devalarm_start(&alarms[alarm_type], timespec_to_ktime(*ts)); spin_unlock_irqrestore(&alarm_slock, flags); + +#if 0 + if (alarm_type == ANDROID_ALARM_RTC_POWEROFF_WAKEUP) + set_power_on_alarm(ts->tv_sec, 1); +#endif + mutex_unlock(&alarm_mutex); } static int alarm_wait(void) @@ -182,6 +198,7 @@ static int alarm_get_time(enum android_alarm_type alarm_type, switch (alarm_type) { case ANDROID_ALARM_RTC_WAKEUP: case ANDROID_ALARM_RTC: + case ANDROID_ALARM_RTC_POWEROFF_WAKEUP: getnstimeofday(ts); break; case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP: @@ -225,7 +242,7 @@ static long alarm_do_ioctl(struct file *file, unsigned int cmd, switch (ANDROID_ALARM_BASE_CMD(cmd)) { case ANDROID_ALARM_CLEAR(0): - alarm_clear(alarm_type); + alarm_clear(alarm_type, ts); break; case ANDROID_ALARM_SET(0): alarm_set(alarm_type, ts); @@ -259,6 +276,7 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case ANDROID_ALARM_SET_AND_WAIT(0): case ANDROID_ALARM_SET(0): case ANDROID_ALARM_SET_RTC: + case ANDROID_ALARM_CLEAR(0): if (copy_from_user(&ts, (void __user *)arg, sizeof(ts))) return -EFAULT; break; @@ -298,6 +316,8 @@ static long alarm_compat_ioctl(struct file *file, unsigned int cmd, } rv = alarm_do_ioctl(file, cmd, &ts); + if (rv) + return rv; switch (ANDROID_ALARM_BASE_CMD(cmd)) { case ANDROID_ALARM_GET_TIME(0): /* NOTE: we modified cmd above */ @@ -306,7 +326,7 @@ static long alarm_compat_ioctl(struct file *file, unsigned int cmd, break; } - return rv; + return 0; } #endif @@ -420,6 +440,8 @@ static int __init alarm_dev_init(void) CLOCK_BOOTTIME, HRTIMER_MODE_ABS); hrtimer_init(&alarms[ANDROID_ALARM_SYSTEMTIME].u.hrt, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); + alarm_init(&alarms[ANDROID_ALARM_RTC_POWEROFF_WAKEUP].u.alrm, + ALARM_REALTIME, devalarm_alarmhandler); for (i = 0; i < ANDROID_ALARM_TYPE_COUNT; i++) { alarms[i].type = i; @@ -428,6 +450,8 @@ static int __init alarm_dev_init(void) } wakeup_source_init(&alarm_wake_lock, "alarm"); + + power_on_alarm_init(); return 0; } @@ -439,4 +463,3 @@ static void __exit alarm_dev_exit(void) module_init(alarm_dev_init); module_exit(alarm_dev_exit); - diff --git a/drivers/staging/android/android_alarm.h b/drivers/staging/android/android_alarm.h index 4fd32f337f9..f11ff295246 100644 --- a/drivers/staging/android/android_alarm.h +++ b/drivers/staging/android/android_alarm.h @@ -26,6 +26,7 @@ enum android_alarm_type { ANDROID_ALARM_RTC, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, ANDROID_ALARM_ELAPSED_REALTIME, + ANDROID_ALARM_RTC_POWEROFF_WAKEUP, ANDROID_ALARM_SYSTEMTIME, ANDROID_ALARM_TYPE_COUNT, @@ -41,6 +42,8 @@ enum android_alarm_return_flags { 1U << ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, ANDROID_ALARM_ELAPSED_REALTIME_MASK = 1U << ANDROID_ALARM_ELAPSED_REALTIME, + ANDROID_ALARM_RTC_POWEROFF_WAKEUP_MASK = + 1U << ANDROID_ALARM_RTC_POWEROFF_WAKEUP, ANDROID_ALARM_SYSTEMTIME_MASK = 1U << ANDROID_ALARM_SYSTEMTIME, ANDROID_ALARM_TIME_CHANGE_MASK = 1U << 16 }; diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h index bf89c117240..459ed695498 100644 --- a/include/linux/clockchips.h +++ b/include/linux/clockchips.h @@ -192,7 +192,8 @@ extern void clockevents_notify(unsigned long reason, void *arg); #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */ -#define clockevents_notify(reason, arg) do { } while (0) +static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; } +static inline void tick_setup_hrtimer_broadcast(void) {}; #endif diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index ed7d68dfea6..ab54282b0ed 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -622,8 +622,8 @@ static inline void clocksource_select(void) { } * clocksource_done_booting - Called near the end of core bootup * * Hack to avoid lots of clocksource churn at boot time. - * We use fs_initcall because we want this to start before - * device_initcall but after subsys_initcall. + * We use arch_initcall because we want this to start before + * device_initcall but after SMP init. */ static int __init clocksource_done_booting(void) { @@ -643,7 +643,7 @@ static int __init clocksource_done_booting(void) mutex_unlock(&clocksource_mutex); return 0; } -fs_initcall(clocksource_done_booting); +arch_initcall(clocksource_done_booting); /* * Enqueue the clocksource sorted by rating diff --git a/sound/soc/codecs/sound_control_3_gpl.c b/sound/soc/codecs/sound_control_3_gpl.c index a1192556150..5dff88a3ff5 100644 --- a/sound/soc/codecs/sound_control_3_gpl.c +++ b/sound/soc/codecs/sound_control_3_gpl.c @@ -195,7 +195,7 @@ static bool calc_checksum(unsigned int a, unsigned int b, unsigned int c) } } -static ssize_t cam_mic_gain_show(struct kobject *kobj, +static ssize_t gpl_cam_mic_gain_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%u\n", @@ -204,7 +204,7 @@ static ssize_t cam_mic_gain_show(struct kobject *kobj, } -static ssize_t cam_mic_gain_store(struct kobject *kobj, +static ssize_t gpl_cam_mic_gain_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { unsigned int lval, chksum; @@ -218,7 +218,7 @@ static ssize_t cam_mic_gain_store(struct kobject *kobj, return count; } -static ssize_t mic_gain_show(struct kobject *kobj, +static ssize_t gpl_mic_gain_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%u\n", @@ -226,7 +226,7 @@ static ssize_t mic_gain_show(struct kobject *kobj, TAIKO_A_CDC_TX7_VOL_CTL_GAIN)); } -static ssize_t mic_gain_store(struct kobject *kobj, +static ssize_t gpl_mic_gain_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { unsigned int lval, chksum; @@ -241,7 +241,7 @@ static ssize_t mic_gain_store(struct kobject *kobj, } -static ssize_t speaker_gain_show(struct kobject *kobj, +static ssize_t gpl_speaker_gain_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%u %u\n", @@ -252,7 +252,7 @@ static ssize_t speaker_gain_show(struct kobject *kobj, } -static ssize_t speaker_gain_store(struct kobject *kobj, +static ssize_t gpl_speaker_gain_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { unsigned int lval, rval, chksum; @@ -268,7 +268,7 @@ static ssize_t speaker_gain_store(struct kobject *kobj, return count; } -static ssize_t headphone_gain_show(struct kobject *kobj, +static ssize_t gpl_headphone_gain_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%u %u\n", @@ -278,7 +278,7 @@ static ssize_t headphone_gain_show(struct kobject *kobj, TAIKO_A_CDC_RX2_VOL_CTL_B2_CTL)); } -static ssize_t headphone_gain_store(struct kobject *kobj, +static ssize_t gpl_headphone_gain_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { unsigned int lval, rval, chksum; @@ -294,7 +294,7 @@ static ssize_t headphone_gain_store(struct kobject *kobj, return count; } -static ssize_t headphone_pa_gain_show(struct kobject *kobj, +static ssize_t gpl_headphone_pa_gain_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%u %u\n", @@ -302,7 +302,7 @@ static ssize_t headphone_pa_gain_show(struct kobject *kobj, taiko_read(fauxsound_codec_ptr, TAIKO_A_RX_HPH_R_GAIN)); } -static ssize_t headphone_pa_gain_store(struct kobject *kobj, +static ssize_t gpl_headphone_pa_gain_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { unsigned int lval, rval, chksum; @@ -364,13 +364,13 @@ static ssize_t sound_reg_write_store(struct kobject *kobj, return count; } -static ssize_t sound_control_hw_revision_show (struct kobject *kobj, +static ssize_t gpl_sound_control_hw_revision_show (struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "hw_revision: %i\n", wcd9xxx_hw_revision); } -static ssize_t sound_control_version_show(struct kobject *kobj, +static ssize_t gpl_sound_control_version_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "version: %u.%u\n", @@ -378,7 +378,7 @@ static ssize_t sound_control_version_show(struct kobject *kobj, SOUND_CONTROL_MINOR_VERSION); } -static ssize_t sound_control_locked_store(struct kobject *kobj, +static ssize_t gpl_sound_control_locked_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { int inp; @@ -390,13 +390,13 @@ static ssize_t sound_control_locked_store(struct kobject *kobj, return count; } -static ssize_t sound_control_locked_show(struct kobject *kobj, +static ssize_t gpl_sound_control_locked_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%d\n", snd_ctrl_locked); } -static ssize_t sound_control_rec_locked_store(struct kobject *kobj, +static ssize_t gpl_sound_control_rec_locked_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { int inp; @@ -408,7 +408,7 @@ static ssize_t sound_control_rec_locked_store(struct kobject *kobj, return count; } -static ssize_t sound_control_rec_locked_show(struct kobject *kobj, +static ssize_t gpl_sound_control_rec_locked_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%d\n", snd_rec_ctrl_locked); @@ -416,73 +416,69 @@ static ssize_t sound_control_rec_locked_show(struct kobject *kobj, static struct kobj_attribute sound_reg_sel_attribute = __ATTR(sound_reg_sel, - 0222, + S_IWUSR, NULL, sound_reg_select_store); static struct kobj_attribute sound_reg_read_attribute = __ATTR(sound_reg_read, - 0444, + S_IRUGO, sound_reg_read_show, NULL); static struct kobj_attribute sound_reg_write_attribute = __ATTR(sound_reg_write, - 0222, + S_IWUSR, NULL, sound_reg_write_store); static struct kobj_attribute cam_mic_gain_attribute = __ATTR(gpl_cam_mic_gain, - 0666, - cam_mic_gain_show, - cam_mic_gain_store); + S_IRUGO | S_IWUSR, + gpl_cam_mic_gain_show, + gpl_cam_mic_gain_store); static struct kobj_attribute mic_gain_attribute = __ATTR(gpl_mic_gain, - 0666, - mic_gain_show, - mic_gain_store); + S_IRUGO | S_IWUSR, + gpl_mic_gain_show, + gpl_mic_gain_store); static struct kobj_attribute speaker_gain_attribute = __ATTR(gpl_speaker_gain, - 0666, - speaker_gain_show, - speaker_gain_store); + S_IRUGO | S_IWUSR, + gpl_speaker_gain_show, + gpl_speaker_gain_store); static struct kobj_attribute headphone_gain_attribute = __ATTR(gpl_headphone_gain, - 0666, - headphone_gain_show, - headphone_gain_store); + S_IRUGO | S_IWUSR, + gpl_headphone_gain_show, + gpl_headphone_gain_store); static struct kobj_attribute headphone_pa_gain_attribute = __ATTR(gpl_headphone_pa_gain, - 0666, - headphone_pa_gain_show, - headphone_pa_gain_store); + S_IRUGO | S_IWUSR, + gpl_headphone_pa_gain_show, + gpl_headphone_pa_gain_store); static struct kobj_attribute sound_control_locked_attribute = __ATTR(gpl_sound_control_locked, - 0666, - sound_control_locked_show, - sound_control_locked_store); + S_IRUGO | S_IWUSR, + gpl_sound_control_locked_show, + gpl_sound_control_locked_store); static struct kobj_attribute sound_control_rec_locked_attribute = __ATTR(gpl_sound_control_rec_locked, - 0666, - sound_control_rec_locked_show, - sound_control_rec_locked_store); + S_IRUGO | S_IWUSR, + gpl_sound_control_rec_locked_show, + gpl_sound_control_rec_locked_store); static struct kobj_attribute sound_control_version_attribute = - __ATTR(gpl_sound_control_version, - 0444, - sound_control_version_show, NULL); + __ATTR_RO(gpl_sound_control_version); static struct kobj_attribute sound_hw_revision_attribute = - __ATTR(gpl_sound_control_hw_revision, - 0444, - sound_control_hw_revision_show, NULL); + __ATTR_RO(gpl_sound_control_hw_revision); static struct attribute *sound_control_attrs[] = {