Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Consistently reference kn->kn_data only within the ...
details: https://anonhg.NetBSD.org/src/rev/a63b21f15434
branches: trunk
changeset: 1023827:a63b21f15434
user: thorpej <thorpej%NetBSD.org@localhost>
date: Mon Sep 27 00:40:49 2021 +0000
description:
Consistently reference kn->kn_data only within the lock perimeter in
the filtops f_event() callback.
diffstat:
sys/kern/sys_eventfd.c | 12 ++++++++----
sys/kern/sys_timerfd.c | 8 +++++---
sys/kern/tty.c | 8 +++++---
3 files changed, 18 insertions(+), 10 deletions(-)
diffs (141 lines):
diff -r 4752f98e2341 -r a63b21f15434 sys/kern/sys_eventfd.c
--- a/sys/kern/sys_eventfd.c Sun Sep 26 23:37:40 2021 +0000
+++ b/sys/kern/sys_eventfd.c Mon Sep 27 00:40:49 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_eventfd.c,v 1.6 2021/09/26 03:42:54 thorpej Exp $ */
+/* $NetBSD: sys_eventfd.c,v 1.7 2021/09/27 00:40:49 thorpej Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.6 2021/09/26 03:42:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.7 2021/09/27 00:40:49 thorpej Exp $");
/*
* eventfd
@@ -408,6 +408,7 @@
eventfd_filt_read(struct knote * const kn, long const hint)
{
struct eventfd * const efd = ((file_t *)kn->kn_obj)->f_eventfd;
+ int rv;
if (hint & NOTE_SUBMIT) {
KASSERT(mutex_owned(&efd->efd_lock));
@@ -416,12 +417,13 @@
}
kn->kn_data = (int64_t)efd->efd_val;
+ rv = (eventfd_t)kn->kn_data > 0;
if ((hint & NOTE_SUBMIT) == 0) {
mutex_exit(&efd->efd_lock);
}
- return (eventfd_t)kn->kn_data > 0;
+ return rv;
}
static const struct filterops eventfd_read_filterops = {
@@ -445,6 +447,7 @@
eventfd_filt_write(struct knote * const kn, long const hint)
{
struct eventfd * const efd = ((file_t *)kn->kn_obj)->f_eventfd;
+ int rv;
if (hint & NOTE_SUBMIT) {
KASSERT(mutex_owned(&efd->efd_lock));
@@ -453,12 +456,13 @@
}
kn->kn_data = (int64_t)efd->efd_val;
+ rv = (eventfd_t)kn->kn_data < EVENTFD_MAXVAL;
if ((hint & NOTE_SUBMIT) == 0) {
mutex_exit(&efd->efd_lock);
}
- return (eventfd_t)kn->kn_data < EVENTFD_MAXVAL;
+ return rv;
}
static const struct filterops eventfd_write_filterops = {
diff -r 4752f98e2341 -r a63b21f15434 sys/kern/sys_timerfd.c
--- a/sys/kern/sys_timerfd.c Sun Sep 26 23:37:40 2021 +0000
+++ b/sys/kern/sys_timerfd.c Mon Sep 27 00:40:49 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_timerfd.c,v 1.5 2021/09/26 03:42:54 thorpej Exp $ */
+/* $NetBSD: sys_timerfd.c,v 1.6 2021/09/27 00:40:49 thorpej Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_timerfd.c,v 1.5 2021/09/26 03:42:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_timerfd.c,v 1.6 2021/09/27 00:40:49 thorpej Exp $");
/*
* timerfd
@@ -404,6 +404,7 @@
timerfd_filt_read(struct knote * const kn, long const hint)
{
struct timerfd * const tfd = ((file_t *)kn->kn_obj)->f_timerfd;
+ int rv;
if (hint & NOTE_SUBMIT) {
KASSERT(itimer_lock_held());
@@ -412,12 +413,13 @@
}
kn->kn_data = (int64_t)timerfd_fire_count(tfd);
+ rv = kn->kn_data != 0;
if ((hint & NOTE_SUBMIT) == 0) {
itimer_unlock();
}
- return kn->kn_data != 0;
+ return rv;
}
static const struct filterops timerfd_read_filterops = {
diff -r 4752f98e2341 -r a63b21f15434 sys/kern/tty.c
--- a/sys/kern/tty.c Sun Sep 26 23:37:40 2021 +0000
+++ b/sys/kern/tty.c Mon Sep 27 00:40:49 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tty.c,v 1.296 2021/09/26 01:16:10 thorpej Exp $ */
+/* $NetBSD: tty.c,v 1.297 2021/09/27 00:40:49 thorpej Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.296 2021/09/26 01:16:10 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.297 2021/09/27 00:40:49 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -1477,14 +1477,16 @@
filt_ttyread(struct knote *kn, long hint)
{
struct tty *tp;
+ int rv;
tp = kn->kn_hook;
if ((hint & NOTE_SUBMIT) == 0)
mutex_spin_enter(&tty_lock);
kn->kn_data = ttnread(tp);
+ rv = kn->kn_data > 0;
if ((hint & NOTE_SUBMIT) == 0)
mutex_spin_exit(&tty_lock);
- return (kn->kn_data > 0);
+ return rv;
}
static void
Home |
Main Index |
Thread Index |
Old Index