VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   35 Branches   59 Tags
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100   1) // SPDX-License-Identifier: GPL-2.0
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400   2) #include <linux/err.h>
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400   3) #include <linux/bug.h>
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400   4) #include <linux/atomic.h>
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400   5) #include <linux/errseq.h>
aa6159ab99a9a (Andy Shevchenko    2020-12-15 20:42:48 -0800   6) #include <linux/log2.h>
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400   7) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400   8) /*
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400   9)  * An errseq_t is a way of recording errors in one place, and allowing any
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  10)  * number of "subscribers" to tell whether it has changed since a previous
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  11)  * point where it was sampled.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  12)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  13)  * It's implemented as an unsigned 32-bit value. The low order bits are
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  14)  * designated to hold an error code (between 0 and -MAX_ERRNO). The upper bits
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  15)  * are used as a counter. This is done with atomics instead of locking so that
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  16)  * these functions can be called from any context.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  17)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  18)  * The general idea is for consumers to sample an errseq_t value. That value
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  19)  * can later be used to tell whether any new errors have occurred since that
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  20)  * sampling was done.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  21)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  22)  * Note that there is a risk of collisions if new errors are being recorded
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  23)  * frequently, since we have so few bits to use as a counter.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  24)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  25)  * To mitigate this, one bit is used as a flag to tell whether the value has
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  26)  * been sampled since a new value was recorded. That allows us to avoid bumping
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  27)  * the counter if no one has sampled it since the last time an error was
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  28)  * recorded.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  29)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  30)  * A new errseq_t should always be zeroed out.  A errseq_t value of all zeroes
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  31)  * is the special (but common) case where there has never been an error. An all
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  32)  * zero value thus serves as the "epoch" if one wishes to know whether there
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  33)  * has ever been an error set since it was first initialized.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  34)  */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  35) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  36) /* The low bits are designated for error code (max of MAX_ERRNO) */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  37) #define ERRSEQ_SHIFT		ilog2(MAX_ERRNO + 1)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  38) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  39) /* This bit is used as a flag to indicate whether the value has been seen */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  40) #define ERRSEQ_SEEN		(1 << ERRSEQ_SHIFT)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  41) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  42) /* The lowest bit of the counter */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  43) #define ERRSEQ_CTR_INC		(1 << (ERRSEQ_SHIFT + 1))
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  44) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  45) /**
3acdfd280fe7d (Jeff Layton        2017-07-24 06:22:15 -0400  46)  * errseq_set - set a errseq_t for later reporting
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  47)  * @eseq: errseq_t field that should be set
3acdfd280fe7d (Jeff Layton        2017-07-24 06:22:15 -0400  48)  * @err: error to set (must be between -1 and -MAX_ERRNO)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  49)  *
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800  50)  * This function sets the error in @eseq, and increments the sequence counter
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  51)  * if the last sequence was sampled at some point in the past.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  52)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  53)  * Any error set will always overwrite an existing error.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  54)  *
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800  55)  * Return: The previous value, primarily for debugging purposes. The
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800  56)  * return value should not be used as a previously sampled value in later
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800  57)  * calls as it will not have the SEEN flag set.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  58)  */
3acdfd280fe7d (Jeff Layton        2017-07-24 06:22:15 -0400  59) errseq_t errseq_set(errseq_t *eseq, int err)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  60) {
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  61) 	errseq_t cur, old;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  62) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  63) 	/* MAX_ERRNO must be able to serve as a mask */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  64) 	BUILD_BUG_ON_NOT_POWER_OF_2(MAX_ERRNO + 1);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  65) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  66) 	/*
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  67) 	 * Ensure the error code actually fits where we want it to go. If it
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  68) 	 * doesn't then just throw a warning and don't record anything. We
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  69) 	 * also don't accept zero here as that would effectively clear a
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  70) 	 * previous error.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  71) 	 */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  72) 	old = READ_ONCE(*eseq);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  73) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  74) 	if (WARN(unlikely(err == 0 || (unsigned int)-err > MAX_ERRNO),
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  75) 				"err = %d\n", err))
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  76) 		return old;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  77) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  78) 	for (;;) {
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  79) 		errseq_t new;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  80) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  81) 		/* Clear out error bits and set new error */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  82) 		new = (old & ~(MAX_ERRNO|ERRSEQ_SEEN)) | -err;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  83) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  84) 		/* Only increment if someone has looked at it */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  85) 		if (old & ERRSEQ_SEEN)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  86) 			new += ERRSEQ_CTR_INC;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  87) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  88) 		/* If there would be no change, then call it done */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  89) 		if (new == old) {
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  90) 			cur = new;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  91) 			break;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  92) 		}
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  93) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  94) 		/* Try to swap the new value into place */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  95) 		cur = cmpxchg(eseq, old, new);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  96) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  97) 		/*
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  98) 		 * Call it success if we did the swap or someone else beat us
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400  99) 		 * to it for the same value.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 100) 		 */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 101) 		if (likely(cur == old || cur == new))
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 102) 			break;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 103) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 104) 		/* Raced with an update, try again */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 105) 		old = cur;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 106) 	}
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 107) 	return cur;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 108) }
3acdfd280fe7d (Jeff Layton        2017-07-24 06:22:15 -0400 109) EXPORT_SYMBOL(errseq_set);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 110) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 111) /**
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 112)  * errseq_sample() - Grab current errseq_t value.
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 113)  * @eseq: Pointer to errseq_t to be sampled.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 114)  *
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 115)  * This function allows callers to initialise their errseq_t variable.
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 116)  * If the error has been "seen", new callers will not see an old error.
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 117)  * If there is an unseen error in @eseq, the caller of this function will
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 118)  * see it the next time it checks for an error.
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 119)  *
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 120)  * Context: Any context.
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 121)  * Return: The current errseq value.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 122)  */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 123) errseq_t errseq_sample(errseq_t *eseq)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 124) {
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 125) 	errseq_t old = READ_ONCE(*eseq);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 126) 
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 127) 	/* If nobody has seen this error yet, then we can be the first. */
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 128) 	if (!(old & ERRSEQ_SEEN))
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 129) 		old = 0;
b4678df184b31 (Matthew Wilcox     2018-04-24 14:02:57 -0700 130) 	return old;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 131) }
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 132) EXPORT_SYMBOL(errseq_sample);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 133) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 134) /**
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 135)  * errseq_check() - Has an error occurred since a particular sample point?
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 136)  * @eseq: Pointer to errseq_t value to be checked.
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 137)  * @since: Previously-sampled errseq_t from which to check.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 138)  *
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 139)  * Grab the value that eseq points to, and see if it has changed @since
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 140)  * the given value was sampled. The @since value is not advanced, so there
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 141)  * is no need to mark the value as seen.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 142)  *
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 143)  * Return: The latest error set in the errseq_t or 0 if it hasn't changed.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 144)  */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 145) int errseq_check(errseq_t *eseq, errseq_t since)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 146) {
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 147) 	errseq_t cur = READ_ONCE(*eseq);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 148) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 149) 	if (likely(cur == since))
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 150) 		return 0;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 151) 	return -(cur & MAX_ERRNO);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 152) }
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 153) EXPORT_SYMBOL(errseq_check);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 154) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 155) /**
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 156)  * errseq_check_and_advance() - Check an errseq_t and advance to current value.
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 157)  * @eseq: Pointer to value being checked and reported.
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 158)  * @since: Pointer to previously-sampled errseq_t to check against and advance.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 159)  *
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 160)  * Grab the eseq value, and see whether it matches the value that @since
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 161)  * points to. If it does, then just return 0.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 162)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 163)  * If it doesn't, then the value has changed. Set the "seen" flag, and try to
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 164)  * swap it into place as the new eseq value. Then, set that value as the new
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 165)  * "since" value, and return whatever the error portion is set to.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 166)  *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 167)  * Note that no locking is provided here for concurrent updates to the "since"
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 168)  * value. The caller must provide that if necessary. Because of this, callers
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 169)  * may want to do a lockless errseq_check before taking the lock and calling
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 170)  * this.
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 171)  *
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 172)  * Return: Negative errno if one has been stored, or 0 if no new error has
14ebc28e07e68 (Matthew Wilcox     2017-12-22 06:32:16 -0800 173)  * occurred.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 174)  */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 175) int errseq_check_and_advance(errseq_t *eseq, errseq_t *since)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 176) {
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 177) 	int err = 0;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 178) 	errseq_t old, new;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 179) 
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 180) 	/*
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 181) 	 * Most callers will want to use the inline wrapper to check this,
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 182) 	 * so that the common case of no error is handled without needing
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 183) 	 * to take the lock that protects the "since" value.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 184) 	 */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 185) 	old = READ_ONCE(*eseq);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 186) 	if (old != *since) {
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 187) 		/*
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 188) 		 * Set the flag and try to swap it into place if it has
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 189) 		 * changed.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 190) 		 *
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 191) 		 * We don't care about the outcome of the swap here. If the
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 192) 		 * swap doesn't occur, then it has either been updated by a
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 193) 		 * writer who is altering the value in some way (updating
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 194) 		 * counter or resetting the error), or another reader who is
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 195) 		 * just setting the "seen" flag. Either outcome is OK, and we
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 196) 		 * can advance "since" and return an error based on what we
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 197) 		 * have.
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 198) 		 */
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 199) 		new = old | ERRSEQ_SEEN;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 200) 		if (new != old)
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 201) 			cmpxchg(eseq, old, new);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 202) 		*since = new;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 203) 		err = -(new & MAX_ERRNO);
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 204) 	}
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 205) 	return err;
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 206) }
84cbadadc6eaf (Jeff Layton        2017-07-06 07:02:24 -0400 207) EXPORT_SYMBOL(errseq_check_and_advance);