Skip to content

Commit 4838bc9

Browse files
KAGA-KOKOkuba-moo
authored andcommitted
ptp: Convert chardev code to lock guards
Convert the various spin_lock_irqsave() protected critical regions to scoped guards. Use spinlock_irq instead of spinlock_irqsave as all the functions are invoked in thread context with interrupts enabled. No functional change intended. Signed-off-by: Thomas Gleixner <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 745e3c7 commit 4838bc9

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

drivers/ptp/ptp_chardev.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
110110
container_of(pccontext->clk, struct ptp_clock, clock);
111111
struct timestamp_event_queue *queue;
112112
char debugfsname[32];
113-
unsigned long flags;
114113

115114
queue = kzalloc(sizeof(*queue), GFP_KERNEL);
116115
if (!queue)
@@ -122,9 +121,8 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
122121
}
123122
bitmap_set(queue->mask, 0, PTP_MAX_CHANNELS);
124123
spin_lock_init(&queue->lock);
125-
spin_lock_irqsave(&ptp->tsevqs_lock, flags);
126-
list_add_tail(&queue->qlist, &ptp->tsevqs);
127-
spin_unlock_irqrestore(&ptp->tsevqs_lock, flags);
124+
scoped_guard(spinlock_irq, &ptp->tsevqs_lock)
125+
list_add_tail(&queue->qlist, &ptp->tsevqs);
128126
pccontext->private_clkdata = queue;
129127

130128
/* Debugfs contents */
@@ -143,15 +141,13 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
143141
int ptp_release(struct posix_clock_context *pccontext)
144142
{
145143
struct timestamp_event_queue *queue = pccontext->private_clkdata;
146-
unsigned long flags;
147144
struct ptp_clock *ptp =
148145
container_of(pccontext->clk, struct ptp_clock, clock);
149146

150147
debugfs_remove(queue->debugfs_instance);
151148
pccontext->private_clkdata = NULL;
152-
spin_lock_irqsave(&ptp->tsevqs_lock, flags);
153-
list_del(&queue->qlist);
154-
spin_unlock_irqrestore(&ptp->tsevqs_lock, flags);
149+
scoped_guard(spinlock_irq, &ptp->tsevqs_lock)
150+
list_del(&queue->qlist);
155151
bitmap_free(queue->mask);
156152
kfree(queue);
157153
return 0;
@@ -544,8 +540,6 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags,
544540
container_of(pccontext->clk, struct ptp_clock, clock);
545541
struct timestamp_event_queue *queue;
546542
struct ptp_extts_event *event;
547-
unsigned long flags;
548-
size_t qcnt, i;
549543
int result;
550544

551545
queue = pccontext->private_clkdata;
@@ -580,21 +574,19 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags,
580574
goto exit;
581575
}
582576

583-
spin_lock_irqsave(&queue->lock, flags);
577+
scoped_guard(spinlock_irq, &queue->lock) {
578+
size_t qcnt = queue_cnt(queue);
584579

585-
qcnt = queue_cnt(queue);
580+
if (cnt > qcnt)
581+
cnt = qcnt;
586582

587-
if (cnt > qcnt)
588-
cnt = qcnt;
589-
590-
for (i = 0; i < cnt; i++) {
591-
event[i] = queue->buf[queue->head];
592-
/* Paired with READ_ONCE() in queue_cnt() */
593-
WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS);
583+
for (size_t i = 0; i < cnt; i++) {
584+
event[i] = queue->buf[queue->head];
585+
/* Paired with READ_ONCE() in queue_cnt() */
586+
WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS);
587+
}
594588
}
595589

596-
spin_unlock_irqrestore(&queue->lock, flags);
597-
598590
cnt = cnt * sizeof(struct ptp_extts_event);
599591

600592
result = cnt;

0 commit comments

Comments
 (0)