diff options
Diffstat (limited to 'lib/errseq.c')
-rw-r--r-- | lib/errseq.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/errseq.c b/lib/errseq.c index df782418b333..81f9e33aa7e7 100644 --- a/lib/errseq.c +++ b/lib/errseq.c | |||
@@ -111,27 +111,22 @@ EXPORT_SYMBOL(errseq_set); | |||
111 | * errseq_sample() - Grab current errseq_t value. | 111 | * errseq_sample() - Grab current errseq_t value. |
112 | * @eseq: Pointer to errseq_t to be sampled. | 112 | * @eseq: Pointer to errseq_t to be sampled. |
113 | * | 113 | * |
114 | * This function allows callers to sample an errseq_t value, marking it as | 114 | * This function allows callers to initialise their errseq_t variable. |
115 | * "seen" if required. | 115 | * If the error has been "seen", new callers will not see an old error. |
116 | * If there is an unseen error in @eseq, the caller of this function will | ||
117 | * see it the next time it checks for an error. | ||
116 | * | 118 | * |
119 | * Context: Any context. | ||
117 | * Return: The current errseq value. | 120 | * Return: The current errseq value. |
118 | */ | 121 | */ |
119 | errseq_t errseq_sample(errseq_t *eseq) | 122 | errseq_t errseq_sample(errseq_t *eseq) |
120 | { | 123 | { |
121 | errseq_t old = READ_ONCE(*eseq); | 124 | errseq_t old = READ_ONCE(*eseq); |
122 | errseq_t new = old; | ||
123 | 125 | ||
124 | /* | 126 | /* If nobody has seen this error yet, then we can be the first. */ |
125 | * For the common case of no errors ever having been set, we can skip | 127 | if (!(old & ERRSEQ_SEEN)) |
126 | * marking the SEEN bit. Once an error has been set, the value will | 128 | old = 0; |
127 | * never go back to zero. | 129 | return old; |
128 | */ | ||
129 | if (old != 0) { | ||
130 | new |= ERRSEQ_SEEN; | ||
131 | if (old != new) | ||
132 | cmpxchg(eseq, old, new); | ||
133 | } | ||
134 | return new; | ||
135 | } | 130 | } |
136 | EXPORT_SYMBOL(errseq_sample); | 131 | EXPORT_SYMBOL(errseq_sample); |
137 | 132 | ||