Skip to content

Commit 666b5d1

Browse files
Fabien Lahouderealexandrebelloni
Fabien Lahoudere
authored andcommitted
rtc: rx8010: change lock mechanism
Remove spinlock and use the "rtc->ops_lock" from RTC subsystem instead. spin_lock_irqsave() is not needed here because we do not have hard IRQs. This patch fixes the following issue: root@GE004097290448 b850v3:~# hwclock --systohc root@GE004097290448 b850v3:~# hwclock --systohc root@GE004097290448 b850v3:~# hwclock --systohc root@GE004097290448 b850v3:~# hwclock --systohc root@GE004097290448 b850v3:~# hwclock --systohc [ 82.108175] BUG: spinlock wrong CPU on CPU#0, hwclock/855 [ 82.113660] lock: 0xedb4899c, .magic: dead4ead, .owner: hwclock/855, .owner_cpu: 1 [ 82.121329] CPU: 0 PID: 855 Comm: hwclock Not tainted 4.8.0-00042-g09d5410-dirty rib#20 [ 82.129078] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree) [ 82.135609] Backtrace: [ 82.138090] [<8010d378>] (dump_backtrace) from [<8010d5c0>] (show_stack+0x20/0x24) [ 82.145664] r7:ec936000 r6:600a0013 r5:00000000 r4:81031680 [ 82.151402] [<8010d5a0>] (show_stack) from [<80401518>] (dump_stack+0xb4/0xe8) [ 82.158636] [<80401464>] (dump_stack) from [<8017b8b0>] (spin_dump+0x84/0xcc) [ 82.165775] r10:00000000 r9:ec936000 r8:81056090 r7:600a0013 r6:edb4899c r5:edb4899c [ 82.173691] r4:e5033e00 r3:00000000 [ 82.177308] [<8017b82c>] (spin_dump) from [<8017bcb0>] (do_raw_spin_unlock+0x108/0x130) [ 82.185314] r5:edb4899c r4:edb4899c [ 82.188938] [<8017bba8>] (do_raw_spin_unlock) from [<8094b93c>] (_raw_spin_unlock_irqrestore+0x34/0x54) [ 82.198333] r5:edb4899c r4:600a0013 [ 82.201953] [<8094b908>] (_raw_spin_unlock_irqrestore) from [<8065b090>] (rx8010_set_time+0x14c/0x188) [ 82.211261] r5:00000020 r4:edb48990 [ 82.214882] [<8065af44>] (rx8010_set_time) from [<80653fe4>] (rtc_set_time+0x70/0x104) [ 82.222801] r7:00000051 r6:edb39da0 r5:edb39c00 r4:ec937e8c [ 82.228535] [<80653f74>] (rtc_set_time) from [<80655774>] (rtc_dev_ioctl+0x3c4/0x674) [ 82.236368] r7:00000051 r6:7ecf1b74 r5:00000000 r4:edb39c00 [ 82.242106] [<806553b0>] (rtc_dev_ioctl) from [<80284034>] (do_vfs_ioctl+0xa4/0xa6c) [ 82.249851] r8:00000003 r7:80284a40 r6:ed1e9c80 r5:edb44e60 r4:7ecf1b74 [ 82.256642] [<80283f90>] (do_vfs_ioctl) from [<80284a40>] (SyS_ioctl+0x44/0x6c) [ 82.263953] r10:00000000 r9:ec936000 r8:7ecf1b74 r7:4024700a r6:ed1e9c80 r5:00000003 [ 82.271869] r4:ed1e9c80 [ 82.274432] [<802849fc>] (SyS_ioctl) from [<80108520>] (ret_fast_syscall+0x0/0x1c) [ 82.282005] r9:ec936000 r8:801086c4 r7:00000036 r6:00000000 r5:00000003 r4:0008e1bc root@GE004097290448 b850v3:~# Message from syslogd@GE004097290448 at Dec 3 11:17:08 ... kernel:[ 82.108175] BUG: spinlock wrong CPU on CPU#0, hwclock/855 Message from syslogd@GE004097290448 at Dec 3 11:17:08 ... kernel:[ 82.113660] lock: 0xedb4899c, .magic: dead4ead, .owner: hwclock/855, .owner_cpu: 1 hwclock --systohc root@GE004097290448 b850v3:~# Signed-off-by: Fabien Lahoudere <[email protected]> Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 7ce7d89 commit 666b5d1

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

drivers/rtc/rtc-rx8010.c

+3-21
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ struct rx8010_data {
6363
struct i2c_client *client;
6464
struct rtc_device *rtc;
6565
u8 ctrlreg;
66-
spinlock_t flags_lock;
6766
};
6867

6968
static irqreturn_t rx8010_irq_1_handler(int irq, void *dev_id)
@@ -72,12 +71,12 @@ static irqreturn_t rx8010_irq_1_handler(int irq, void *dev_id)
7271
struct rx8010_data *rx8010 = i2c_get_clientdata(client);
7372
int flagreg;
7473

75-
spin_lock(&rx8010->flags_lock);
74+
mutex_lock(&rx8010->rtc->ops_lock);
7675

7776
flagreg = i2c_smbus_read_byte_data(client, RX8010_FLAG);
7877

7978
if (flagreg <= 0) {
80-
spin_unlock(&rx8010->flags_lock);
79+
mutex_unlock(&rx8010->rtc->ops_lock);
8180
return IRQ_NONE;
8281
}
8382

@@ -101,7 +100,7 @@ static irqreturn_t rx8010_irq_1_handler(int irq, void *dev_id)
101100

102101
i2c_smbus_write_byte_data(client, RX8010_FLAG, flagreg);
103102

104-
spin_unlock(&rx8010->flags_lock);
103+
mutex_unlock(&rx8010->rtc->ops_lock);
105104
return IRQ_HANDLED;
106105
}
107106

@@ -143,7 +142,6 @@ static int rx8010_set_time(struct device *dev, struct rtc_time *dt)
143142
u8 date[7];
144143
int ctrl, flagreg;
145144
int ret;
146-
unsigned long irqflags;
147145

148146
if ((dt->tm_year < 100) || (dt->tm_year > 199))
149147
return -EINVAL;
@@ -181,20 +179,15 @@ static int rx8010_set_time(struct device *dev, struct rtc_time *dt)
181179
if (ret < 0)
182180
return ret;
183181

184-
spin_lock_irqsave(&rx8010->flags_lock, irqflags);
185-
186182
flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG);
187183
if (flagreg < 0) {
188-
spin_unlock_irqrestore(&rx8010->flags_lock, irqflags);
189184
return flagreg;
190185
}
191186

192187
if (flagreg & RX8010_FLAG_VLF)
193188
ret = i2c_smbus_write_byte_data(rx8010->client, RX8010_FLAG,
194189
flagreg & ~RX8010_FLAG_VLF);
195190

196-
spin_unlock_irqrestore(&rx8010->flags_lock, irqflags);
197-
198191
return 0;
199192
}
200193

@@ -288,12 +281,9 @@ static int rx8010_set_alarm(struct device *dev, struct rtc_wkalrm *t)
288281
u8 alarmvals[3];
289282
int extreg, flagreg;
290283
int err;
291-
unsigned long irqflags;
292284

293-
spin_lock_irqsave(&rx8010->flags_lock, irqflags);
294285
flagreg = i2c_smbus_read_byte_data(client, RX8010_FLAG);
295286
if (flagreg < 0) {
296-
spin_unlock_irqrestore(&rx8010->flags_lock, irqflags);
297287
return flagreg;
298288
}
299289

@@ -302,14 +292,12 @@ static int rx8010_set_alarm(struct device *dev, struct rtc_wkalrm *t)
302292
err = i2c_smbus_write_byte_data(rx8010->client, RX8010_CTRL,
303293
rx8010->ctrlreg);
304294
if (err < 0) {
305-
spin_unlock_irqrestore(&rx8010->flags_lock, irqflags);
306295
return err;
307296
}
308297
}
309298

310299
flagreg &= ~RX8010_FLAG_AF;
311300
err = i2c_smbus_write_byte_data(rx8010->client, RX8010_FLAG, flagreg);
312-
spin_unlock_irqrestore(&rx8010->flags_lock, irqflags);
313301
if (err < 0)
314302
return err;
315303

@@ -404,7 +392,6 @@ static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
404392
struct rx8010_data *rx8010 = dev_get_drvdata(dev);
405393
int ret, tmp;
406394
int flagreg;
407-
unsigned long irqflags;
408395

409396
switch (cmd) {
410397
case RTC_VL_READ:
@@ -419,16 +406,13 @@ static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
419406
return 0;
420407

421408
case RTC_VL_CLR:
422-
spin_lock_irqsave(&rx8010->flags_lock, irqflags);
423409
flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG);
424410
if (flagreg < 0) {
425-
spin_unlock_irqrestore(&rx8010->flags_lock, irqflags);
426411
return flagreg;
427412
}
428413

429414
flagreg &= ~RX8010_FLAG_VLF;
430415
ret = i2c_smbus_write_byte_data(client, RX8010_FLAG, flagreg);
431-
spin_unlock_irqrestore(&rx8010->flags_lock, irqflags);
432416
if (ret < 0)
433417
return ret;
434418

@@ -466,8 +450,6 @@ static int rx8010_probe(struct i2c_client *client,
466450
rx8010->client = client;
467451
i2c_set_clientdata(client, rx8010);
468452

469-
spin_lock_init(&rx8010->flags_lock);
470-
471453
err = rx8010_init_client(client);
472454
if (err)
473455
return err;

0 commit comments

Comments
 (0)