Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: msp3400: Use wait_event_freezable_timeout() in msp_sleep()

The msp_sleep() is nearly open-coded wait_event_interruptible_timeout(),
and a freezable kernel thread can enter frozen state during freezing by
either calling try_to_freeze() or using wait_event_freezable() and its
variants. So we can reimplement msp_sleep() to simply invoke
a wait_event_freezable_timeout() and then eliminate a call to
try_to_freeze().

Signed-off-by: Kevin Hao <haokexin@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Kevin Hao and committed by
Hans Verkuil
7c17c552 ed917040

+7 -15
+6 -14
drivers/media/i2c/msp3400-driver.c
··· 309 309 wake_up_interruptible(&state->wq); 310 310 } 311 311 312 - int msp_sleep(struct msp_state *state, int timeout) 312 + int msp_sleep(struct msp_state *state, int msec) 313 313 { 314 - DECLARE_WAITQUEUE(wait, current); 314 + long timeout; 315 315 316 - add_wait_queue(&state->wq, &wait); 317 - if (!kthread_should_stop()) { 318 - if (timeout < 0) { 319 - set_current_state(TASK_INTERRUPTIBLE); 320 - schedule(); 321 - } else { 322 - schedule_timeout_interruptible 323 - (msecs_to_jiffies(timeout)); 324 - } 325 - } 316 + timeout = msec < 0 ? MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(msec); 326 317 327 - remove_wait_queue(&state->wq, &wait); 328 - try_to_freeze(); 318 + wait_event_freezable_timeout(state->wq, kthread_should_stop() || 319 + state->restart, timeout); 320 + 329 321 return state->restart; 330 322 } 331 323
+1 -1
drivers/media/i2c/msp3400-driver.h
··· 134 134 int msp_reset(struct i2c_client *client); 135 135 void msp_set_scart(struct i2c_client *client, int in, int out); 136 136 void msp_update_volume(struct msp_state *state); 137 - int msp_sleep(struct msp_state *state, int timeout); 137 + int msp_sleep(struct msp_state *state, int msec); 138 138 139 139 /* msp3400-kthreads.c */ 140 140 const char *msp_standard_std_name(int std);