public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] raw2rgbpnm cleanups and a fix
@ 2026-03-17 13:18 Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 1/6] Reorder headers alphabetically Sakari Ailus
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-03-17 13:18 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Hi folks,

Here are a few cleanups and fixes found in Laurent's review.

since v1:

- Use old_info->bpp field in reading the original buffer.

- Squash two header sorting patches plus swap two lines.

Sakari Ailus (6):
  Reorder headers alphabetically
  Check we have a supported format first before allocating memory
  Add quotes for "-f help" in help text and do a line wrap
  Constify progname
  Use "stride" in a stride-related error message instead of an internal
    name
  Fix file size check

 raw2rgbpnm.c | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/6] Reorder headers alphabetically
  2026-03-17 13:18 [PATCH v2 0/6] raw2rgbpnm cleanups and a fix Sakari Ailus
@ 2026-03-17 13:18 ` Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 2/6] Check we have a supported format first before allocating memory Sakari Ailus
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-03-17 13:18 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 raw2rgbpnm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c
index 24a88feddf00..007ee7a37636 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -26,15 +26,17 @@
 #include <ctype.h>
 #include <getopt.h>
 #include <limits.h>
-#include <stdio.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
-#include <sys/types.h>
+#include <unistd.h>
+
 #include <linux/videodev2.h>
-#include "utils.h"
+#include <sys/types.h>
+
 #include "raw_to_rgb.h"
+#include "utils.h"
 #include "yuv_to_rgb.h"
 
 #define DEFAULT_BGR 0
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/6] Check we have a supported format first before allocating memory
  2026-03-17 13:18 [PATCH v2 0/6] raw2rgbpnm cleanups and a fix Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 1/6] Reorder headers alphabetically Sakari Ailus
@ 2026-03-17 13:18 ` Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 3/6] Add quotes for "-f help" in help text and do a line wrap Sakari Ailus
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-03-17 13:18 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 raw2rgbpnm.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c
index 007ee7a37636..96466a5a1d44 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -372,20 +372,7 @@ static void raw_to_rgb(const struct format_info *info,
 		src_width &= ~3;
 
 		const struct format_info *old_info = info;
-		unsigned int new_stride = src_width * 2;
-
-		tmp_src = malloc(new_stride * src_height);
-		if (!tmp_src)
-			error("can't allocate memory for the temporary buffer");
-
-		for (src_y = 0; src_y < src_height; src_y++)
-			for (src_x = 0; src_x < src_width; src_x++)
-				raw_put(16, tmp_src, new_stride, src_x, src_y,
-					raw_get(info->bpp, src, src_stride,
-						src_x, src_y));
-
-		src_stride = new_stride;
-		src = tmp_src;
+		unsigned int unpacked_stride = src_width * 2;
 
 		for (unsigned int i = 0; i < SIZE(v4l2_pix_fmt_str); i++) {
 			if (v4l2_pix_fmt_str[i].fmt == info->compat_fmt) {
@@ -397,6 +384,19 @@ static void raw_to_rgb(const struct format_info *info,
 		if (info == old_info)
 			error("no supported format found for %s",
 			      old_info->name);
+
+		tmp_src = malloc(unpacked_stride * src_height);
+		if (!tmp_src)
+			error("can't allocate memory for the temporary buffer");
+
+		for (src_y = 0; src_y < src_height; src_y++)
+			for (src_x = 0; src_x < src_width; src_x++)
+				raw_put(16, tmp_src, unpacked_stride, src_x, src_y,
+					raw_get(old_info->bpp, src, src_stride,
+						src_x, src_y));
+
+		src_stride = unpacked_stride;
+		src = tmp_src;
 	}
 	}
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/6] Add quotes for "-f help" in help text and do a line wrap
  2026-03-17 13:18 [PATCH v2 0/6] raw2rgbpnm cleanups and a fix Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 1/6] Reorder headers alphabetically Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 2/6] Check we have a supported format first before allocating memory Sakari Ailus
@ 2026-03-17 13:18 ` Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 4/6] Constify progname Sakari Ailus
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-03-17 13:18 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 raw2rgbpnm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c
index 96466a5a1d44..1f00787e80d7 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -931,11 +931,12 @@ int main(int argc, char *argv[])
 			       "--brightness, -b <bright> Set brightness (multiplier) to output image\n"
 			       "                          (float, default 1.0)\n"
 			       "--format, -f <format>     Specify input file format format\n"
-			       "                          (-f help for list, default UYVY)\n"
+			       "                          (\"-f help\" for list, default UYVY)\n"
 			       "--help, -h                Show this help\n"
 			       "--high-bits, -g           Use high bits for Bayer RAW 10 data\n"
 			       "--size, -s <XxY>          Specify image size\n"
-			       "--swap-rb, -w             Swap R and B channels\n", progname, argv[0]);
+			       "--swap-rb, -w             Swap R and B channels\n",
+			       progname, argv[0]);
 			exit(0);
 		case 's':
 			if (parse_format(optarg, &width, &height) < 0) {
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/6] Constify progname
  2026-03-17 13:18 [PATCH v2 0/6] raw2rgbpnm cleanups and a fix Sakari Ailus
                   ` (2 preceding siblings ...)
  2026-03-17 13:18 ` [PATCH v2 3/6] Add quotes for "-f help" in help text and do a line wrap Sakari Ailus
@ 2026-03-17 13:18 ` Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 5/6] Use "stride" in a stride-related error message instead of an internal name Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 6/6] Fix file size check Sakari Ailus
  5 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-03-17 13:18 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 raw2rgbpnm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c
index 1f00787e80d7..bdcc8dae1db9 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -45,7 +45,7 @@
 #define MAX(a,b)	((a)>(b)?(a):(b))
 #define MIN(a,b)	((a)<(b)?(a):(b))
 
-char *progname = "raw2rgbpnm";
+const char *progname = "raw2rgbpnm";
 
 static int swaprb = 0;
 static int highbits = 0;			/* Bayer RAW10 formats use high bits for data */
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 5/6] Use "stride" in a stride-related error message instead of an internal name
  2026-03-17 13:18 [PATCH v2 0/6] raw2rgbpnm cleanups and a fix Sakari Ailus
                   ` (3 preceding siblings ...)
  2026-03-17 13:18 ` [PATCH v2 4/6] Constify progname Sakari Ailus
@ 2026-03-17 13:18 ` Sakari Ailus
  2026-03-17 13:18 ` [PATCH v2 6/6] Fix file size check Sakari Ailus
  5 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-03-17 13:18 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 raw2rgbpnm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c
index bdcc8dae1db9..ce02c0ec011f 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -177,7 +177,7 @@ static unsigned char *read_raw_data(char *filename, unsigned int *width,
 	line_length = line_length ?: (*width * bpp + 7) / 8;
 	if (!line_length || UINT_MAX / line_length < *height ||
 	    line_length < *width * bpp / 8)
-		error("line_length %u is bad", line_length);
+		error("stride %u is bad", line_length);
 	if (file_size > UINT_MAX)
 		error("too large file");
 	if ((unsigned int)file_size < line_length * *height)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 6/6] Fix file size check
  2026-03-17 13:18 [PATCH v2 0/6] raw2rgbpnm cleanups and a fix Sakari Ailus
                   ` (4 preceding siblings ...)
  2026-03-17 13:18 ` [PATCH v2 5/6] Use "stride" in a stride-related error message instead of an internal name Sakari Ailus
@ 2026-03-17 13:18 ` Sakari Ailus
  5 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-03-17 13:18 UTC (permalink / raw)
  To: linux-media; +Cc: laurent.pinchart

The file size was unintentionally multiplied by 8 and that's not right
anymore due to changes elsewhere.

Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Fixes: 578f7012a851 ("Improve input validation")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 raw2rgbpnm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c
index ce02c0ec011f..afbe47764de4 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -187,7 +187,7 @@ static unsigned char *read_raw_data(char *filename, unsigned int *width,
 	if (file_size % *height == 0) {
 		padding = file_size / *height - line_length;
 		printf("%u padding bytes detected at end of line\n", padding);
-	} else if ((file_size * 8) % (line_length * *height) != 0) {
+	} else if (file_size % (line_length * *height) != 0) {
 		printf("warning: input size not multiple of frame size\n");
 	}
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-17 13:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 13:18 [PATCH v2 0/6] raw2rgbpnm cleanups and a fix Sakari Ailus
2026-03-17 13:18 ` [PATCH v2 1/6] Reorder headers alphabetically Sakari Ailus
2026-03-17 13:18 ` [PATCH v2 2/6] Check we have a supported format first before allocating memory Sakari Ailus
2026-03-17 13:18 ` [PATCH v2 3/6] Add quotes for "-f help" in help text and do a line wrap Sakari Ailus
2026-03-17 13:18 ` [PATCH v2 4/6] Constify progname Sakari Ailus
2026-03-17 13:18 ` [PATCH v2 5/6] Use "stride" in a stride-related error message instead of an internal name Sakari Ailus
2026-03-17 13:18 ` [PATCH v2 6/6] Fix file size check Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox