Skip to content

Commit 79603a3

Browse files
Mark GrossLinus Torvalds
authored andcommitted
[PATCH] tlclk: bug fix + misc fixes
The following patch fixes a few problems with the tlclk driver. * bug in the select_amcb1_transmit_clock * racy read sys call * racy open sys call * use of add_timer where mod_timer would be better * change to the timer data parameter use Signed-off-by: Mark Gross <mark.gross@intel.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent cda9205 commit 79603a3

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

‎drivers/char/tlclk.c‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static int got_event; /* if events processing have been done */
186186
static void switchover_timeout(unsigned long data);
187187
static struct timer_list switchover_timer =
188188
TIMER_INITIALIZER(switchover_timeout , 0, 0);
189+
static unsigned long tlclk_timer_data;
189190

190191
static struct tlclk_alarms *alarm_events;
191192

@@ -197,10 +198,19 @@ static irqreturn_t tlclk_interrupt(int irq, void *dev_id);
197198

198199
static DECLARE_WAIT_QUEUE_HEAD(wq);
199200

201+
static unsigned long useflags;
202+
static DEFINE_MUTEX(tlclk_mutex);
203+
200204
static int tlclk_open(struct inode *inode, struct file *filp)
201205
{
202206
int result;
203207

208+
if (test_and_set_bit(0, &useflags))
209+
return -EBUSY;
210+
/* this legacy device is always one per system and it doesn't
211+
* know how to handle multiple concurrent clients.
212+
*/
213+
204214
/* Make sure there is no interrupt pending while
205215
* initialising interrupt handler */
206216
inb(TLCLK_REG6);
@@ -221,6 +231,7 @@ static int tlclk_open(struct inode *inode, struct file *filp)
221231
static int tlclk_release(struct inode *inode, struct file *filp)
222232
{
223233
free_irq(telclk_interrupt, tlclk_interrupt);
234+
clear_bit(0, &useflags);
224235

225236
return 0;
226237
}
@@ -230,26 +241,25 @@ static ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count,
230241
{
231242
if (count < sizeof(struct tlclk_alarms))
232243
return -EIO;
244+
if (mutex_lock_interruptible(&tlclk_mutex))
245+
return -EINTR;
246+
233247

234248
wait_event_interruptible(wq, got_event);
235-
if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms)))
249+
if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms))) {
250+
mutex_unlock(&tlclk_mutex);
236251
return -EFAULT;
252+
}
237253

238254
memset(alarm_events, 0, sizeof(struct tlclk_alarms));
239255
got_event = 0;
240256

257+
mutex_unlock(&tlclk_mutex);
241258
return sizeof(struct tlclk_alarms);
242259
}
243260

244-
static ssize_t tlclk_write(struct file *filp, const char __user *buf, size_t count,
245-
loff_t *f_pos)
246-
{
247-
return 0;
248-
}
249-
250261
static const struct file_operations tlclk_fops = {
251262
.read = tlclk_read,
252-
.write = tlclk_write,
253263
.open = tlclk_open,
254264
.release = tlclk_release,
255265

@@ -540,7 +550,7 @@ static ssize_t store_select_amcb1_transmit_clock(struct device *d,
540550
SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7);
541551
switch (val) {
542552
case CLK_8_592MHz:
543-
SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
553+
SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
544554
break;
545555
case CLK_11_184MHz:
546556
SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
@@ -549,7 +559,7 @@ static ssize_t store_select_amcb1_transmit_clock(struct device *d,
549559
SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
550560
break;
551561
case CLK_44_736MHz:
552-
SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
562+
SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
553563
break;
554564
}
555565
} else
@@ -839,11 +849,13 @@ static void __exit tlclk_cleanup(void)
839849

840850
static void switchover_timeout(unsigned long data)
841851
{
842-
if ((data & 1)) {
843-
if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08))
852+
unsigned long flags = *(unsigned long *) data;
853+
854+
if ((flags & 1)) {
855+
if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
844856
alarm_events->switchover_primary++;
845857
} else {
846-
if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08))
858+
if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
847859
alarm_events->switchover_secondary++;
848860
}
849861

@@ -901,8 +913,9 @@ static irqreturn_t tlclk_interrupt(int irq, void *dev_id)
901913

902914
/* TIMEOUT in ~10ms */
903915
switchover_timer.expires = jiffies + msecs_to_jiffies(10);
904-
switchover_timer.data = inb(TLCLK_REG1);
905-
add_timer(&switchover_timer);
916+
tlclk_timer_data = inb(TLCLK_REG1);
917+
switchover_timer.data = (unsigned long) &tlclk_timer_data;
918+
mod_timer(&switchover_timer, switchover_timer.expires);
906919
} else {
907920
got_event = 1;
908921
wake_up(&wq);

0 commit comments

Comments
 (0)