public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com
Subject: [PATCH 2/7] Check we have a supported format first before allocating memory
Date: Tue, 17 Mar 2026 11:57:57 +0200	[thread overview]
Message-ID: <20260317095802.214532-3-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20260317095802.214532-1-sakari.ailus@linux.intel.com>

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 121f0e0272e4..8aa7258218ad 100644
--- a/raw2rgbpnm.c
+++ b/raw2rgbpnm.c
@@ -370,20 +370,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) {
@@ -395,6 +382,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(info->bpp, src, src_stride,
+						src_x, src_y));
+
+		src_stride = unpacked_stride;
+		src = tmp_src;
 	}
 	}
 
-- 
2.47.3


  parent reply	other threads:[~2026-03-17  9:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17  9:57 [PATCH 0/7] raw2rgbpnm cleanups and a fix Sakari Ailus
2026-03-17  9:57 ` [PATCH 1/7] Reorder headers alphabetically Sakari Ailus
2026-03-17 10:50   ` Laurent Pinchart
2026-03-17  9:57 ` Sakari Ailus [this message]
2026-03-17 10:54   ` [PATCH 2/7] Check we have a supported format first before allocating memory Laurent Pinchart
2026-03-17 13:11     ` Sakari Ailus
2026-03-17  9:57 ` [PATCH 3/7] Add quotes for "-f help" in help text and do a line wrap Sakari Ailus
2026-03-17 10:54   ` Laurent Pinchart
2026-03-17  9:57 ` [PATCH 4/7] Constify progname Sakari Ailus
2026-03-17 10:54   ` Laurent Pinchart
2026-03-17  9:58 ` [PATCH 5/7] More header sorting Sakari Ailus
2026-03-17 10:54   ` Laurent Pinchart
2026-03-17  9:58 ` [PATCH 6/7] Use "stride" in a stride-related error message instead of an internal name Sakari Ailus
2026-03-17 10:55   ` Laurent Pinchart
2026-03-17  9:58 ` [PATCH 7/7] Fix file size check Sakari Ailus
2026-03-17 10:57   ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260317095802.214532-3-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox