[RFC,v2,12/13] apps: ppm_writer: Return EIO on I/O errors
diff mbox series

Message ID 20250124215806.158024-13-mzamazal@redhat.com
State Accepted
Headers show
Series
  • Enable raw streams with software ISP
Related show

Commit Message

Milan Zamazal Jan. 24, 2025, 9:58 p.m. UTC
EINVAL should be returned only when the requested format is unsupported.
On errors when writing the data, let's return EIO, which is the closest
description of the situation when we don't inspect it more.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 src/apps/common/ppm_writer.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Laurent Pinchart Jan. 25, 2025, 8:14 p.m. UTC | #1
Hi Milan,

Thank you for the patch.

On Fri, Jan 24, 2025 at 10:58:03PM +0100, Milan Zamazal wrote:
> EINVAL should be returned only when the requested format is unsupported.
> On errors when writing the data, let's return EIO, which is the closest
> description of the situation when we don't inspect it more.
> 
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/apps/common/ppm_writer.cpp | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/apps/common/ppm_writer.cpp b/src/apps/common/ppm_writer.cpp
> index 2e9378aa..368de8bf 100644
> --- a/src/apps/common/ppm_writer.cpp
> +++ b/src/apps/common/ppm_writer.cpp
> @@ -29,7 +29,7 @@ int PPMWriter::write(const char *filename,
>  	std::ofstream output(filename, std::ios::binary);
>  	if (!output) {
>  		std::cerr << "Failed to open ppm file: " << filename << std::endl;
> -		return -EINVAL;
> +		return -EIO;
>  	}
>  
>  	output << "P6" << std::endl
> @@ -37,7 +37,7 @@ int PPMWriter::write(const char *filename,
>  	       << "255" << std::endl;
>  	if (!output) {
>  		std::cerr << "Failed to write the file header" << std::endl;
> -		return -EINVAL;
> +		return -EIO;
>  	}
>  
>  	const unsigned int rowLength = config.size.width * 3;
> @@ -46,7 +46,7 @@ int PPMWriter::write(const char *filename,
>  		output.write(row, rowLength);
>  		if (!output) {
>  			std::cerr << "Failed to write image data at row " << y << std::endl;
> -			return -EINVAL;
> +			return -EIO;
>  		}
>  	}
>

Patch
diff mbox series

diff --git a/src/apps/common/ppm_writer.cpp b/src/apps/common/ppm_writer.cpp
index 2e9378aa..368de8bf 100644
--- a/src/apps/common/ppm_writer.cpp
+++ b/src/apps/common/ppm_writer.cpp
@@ -29,7 +29,7 @@  int PPMWriter::write(const char *filename,
 	std::ofstream output(filename, std::ios::binary);
 	if (!output) {
 		std::cerr << "Failed to open ppm file: " << filename << std::endl;
-		return -EINVAL;
+		return -EIO;
 	}
 
 	output << "P6" << std::endl
@@ -37,7 +37,7 @@  int PPMWriter::write(const char *filename,
 	       << "255" << std::endl;
 	if (!output) {
 		std::cerr << "Failed to write the file header" << std::endl;
-		return -EINVAL;
+		return -EIO;
 	}
 
 	const unsigned int rowLength = config.size.width * 3;
@@ -46,7 +46,7 @@  int PPMWriter::write(const char *filename,
 		output.write(row, rowLength);
 		if (!output) {
 			std::cerr << "Failed to write image data at row " << y << std::endl;
-			return -EINVAL;
+			return -EIO;
 		}
 	}