[PATCH linux dev-4.10] drivers/fsi: Fix SBEFIFO write() race condition

Brad Bishop bradleyb at fuzziesquirrel.com
Thu Jun 29 09:53:03 AEST 2017


thx Eddie!

Reviewed-by: Brad Bishop <bradleyb at fuzziesquirrel.com>

> On Jun 28, 2017, at 5:55 PM, Eddie James <eajames at linux.vnet.ibm.com> wrote:
> 
> From: "Edward A. James" <eajames at us.ibm.com>
> 
> There was a race condition with the XFR_WRITE_DONE flag between write()
> and the worker thread. Occasionally the worker wrote all the data and
> checked the flag before write() could set it.
> 
> Signed-off-by: Edward A. James <eajames at us.ibm.com>
> ---
> drivers/fsi/fsi-sbefifo.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c
> index f1bc144..d7dccf9 100644
> --- a/drivers/fsi/fsi-sbefifo.c
> +++ b/drivers/fsi/fsi-sbefifo.c
> @@ -688,6 +688,12 @@ static ssize_t sbefifo_write_common(struct sbefifo_client *client,
> 		len -= n;
> 		ret += n;
> 
> +		/* set flag before starting the worker, as it may run through
> +		 * and check the flag before we exit this loop!
> +		 */
> +		if (!len)
> +			set_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags);
> +
> 		/*
> 		 * Drain the write buffer.
> 		 */
> @@ -696,7 +702,6 @@ static ssize_t sbefifo_write_common(struct sbefifo_client *client,
> 			sbefifo_put(sbefifo);
> 	}
> 
> -	set_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags);
> 	sbefifo_put_client(client);
> 
> 	return ret;
> -- 
> 1.8.3.1


More information about the openbmc mailing list