diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index 282cd7d24077..bf89e1fe6613 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -120,7 +120,7 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode) bitmap_set(queue->mask, 0, PTP_MAX_CHANNELS); spin_lock_init(&queue->lock); list_add_tail(&queue->qlist, &ptp->tsevqs); - pccontext->private_clkdata = queue; + WRITE_ONCE(pccontext->private_clkdata, queue); /* Debugfs contents */ sprintf(debugfsname, "0x%p", queue); @@ -137,12 +137,12 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode) int ptp_release(struct posix_clock_context *pccontext) { - struct timestamp_event_queue *queue = pccontext->private_clkdata; + struct timestamp_event_queue *queue = READ_ONCE(pccontext->private_clkdata); unsigned long flags; if (queue) { debugfs_remove(queue->debugfs_instance); - pccontext->private_clkdata = NULL; + WRITE_ONCE(pccontext->private_clkdata, NULL); spin_lock_irqsave(&queue->lock, flags); list_del(&queue->qlist); spin_unlock_irqrestore(&queue->lock, flags); @@ -172,7 +172,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, struct timespec64 ts; int enable, err = 0; - tsevq = pccontext->private_clkdata; + tsevq = READ_ONCE(pccontext->private_clkdata); switch (cmd) { @@ -506,7 +506,7 @@ __poll_t ptp_poll(struct posix_clock_context *pccontext, struct file *fp, container_of(pccontext->clk, struct ptp_clock, clock); struct timestamp_event_queue *queue; - queue = pccontext->private_clkdata; + queue = READ_ONCE(pccontext->private_clkdata); if (!queue) return EPOLLERR; @@ -528,7 +528,7 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags, size_t qcnt, i; int result; - queue = pccontext->private_clkdata; + queue = READ_ONCE(pccontext->private_clkdata); if (!queue) { result = -EINVAL; goto exit; @@ -585,7 +585,5 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags, free_event: kfree(event); exit: - if (result < 0) - ptp_release(pccontext); return result; }