[Skiboot] [PATCH] libflash/file: Handle short read()s and write()s correctly

Suraj Jitindar Singh sjitindarsingh at gmail.com
Thu Sep 28 13:05:49 AEST 2017


On Thu, 2017-09-28 at 10:59 +1000, Cyril Bur wrote:
> Currently we don't move the buffer along for a short read() or
> write()
> and nor do we request only the remaining amount.
> 
> Fixes: c7c3a4cd53d libflash/file: Add a file access backend to for
> the blocklevel interface.
> Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>

Reviewed-by: Suraj Jitindar Singh <sjitindarsingh at gmail.com>

> ---
>  libflash/file.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libflash/file.c b/libflash/file.c
> index 7065eb4f..49f61778 100644
> --- a/libflash/file.c
> +++ b/libflash/file.c
> @@ -72,11 +72,12 @@ static int file_read(struct blocklevel_device
> *bl, uint64_t pos, void *buf, uint
>  		return FLASH_ERR_PARM_ERROR;
>  
>  	while (count < len) {
> -		rc = read(file_data->fd, buf, len);
> +		rc = read(file_data->fd, buf, len - count);
>  		/* errno should remain set */
>  		if (rc == -1 || rc == 0)
>  			return FLASH_ERR_BAD_READ;
>  
> +		buf += rc;
>  		count += rc;
>  	}
>  
> @@ -95,11 +96,12 @@ static int file_write(struct blocklevel_device
> *bl, uint64_t dst, const void *sr
>  		return FLASH_ERR_PARM_ERROR;
>  
>  	while (count < len) {
> -		rc = write(file_data->fd, src, len);
> +		rc = write(file_data->fd, src, len - count);
>  		/* errno should remain set */
>  		if (rc == -1)
>  			return FLASH_ERR_VERIFY_FAILURE;
>  
> +		src += rc;
>  		count += rc;
>  	}
>  


More information about the Skiboot mailing list