Skip to contentSkip to conversation

media: av7110: refactor deeply nested PTS loops

PATCH In review André Moreira 2 participants 3 messages Jun 20 – Aug 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: av7110: refactor deeply nested PTS loops

Extract the deeply nested loops handling PTS flags in the MPEG-1 block into a separate helper function av7110_ipack_m1_pts().

This fixes a checkpatch warning regarding too many leading tabs and improves code readability without changing the underlying parser logic.

---
 drivers/staging/media/av7110/av7110_ipack.c | 35 +++++++++++----------
 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/staging/media/av7110/av7110_ipack.c +18 -17
index 4be6e225f08e8..a3e69a737e97d 100644
@@ -136,6 +136,22 @@ static void write_ipack(struct ipack *p, const u8 *data, int count)
 	}
 }
 
+static int av7110_ipack_m1_pts(struct ipack *p, const u8 *buf,
+			       int c, int count, int max_which)
+{
+	while (c < count && p->which < max_which) {
+		if (p->which < 7)
+			p->pts[p->which - 2] = buf[c];
+
+		write_ipack(p, buf + c, 1);
+		c++;
+		p->found++;
+		p->which++;
+		p->hlength++;
+	}
+	return c;
+}
+
 int av7110_ipack_instant_repack(const u8 *buf, int count, struct ipack *p)
 {
 	int l;
@@ -335,26 +351,11 @@ int av7110_ipack_instant_repack(const u8 *buf, int count, struct ipack *p)
 				return count;
 			if (p->which > 2) {
 				if ((p->flag2 & PTS_DTS_FLAGS) == PTS_ONLY) {
-					while (c < count && p->which < 7) {
-						p->pts[p->which - 2] = buf[c];
-						write_ipack(p, buf + c, 1);
-						c++;
-						p->found++;
-						p->which++;
-						p->hlength++;
-					}
+					c = av7110_ipack_m1_pts(p, buf, c, count, 7);
 					if (c == count)
 						return count;
 				} else if ((p->flag2 & PTS_DTS_FLAGS) == PTS_DTS) {
-					while (c < count && p->which < 12) {
-						if (p->which < 7)
-							p->pts[p->which - 2] = buf[c];
-						write_ipack(p, buf + c, 1);
-						c++;
-						p->found++;
-						p->which++;
-						p->hlength++;
-					}
+					c = av7110_ipack_m1_pts(p, buf, c, count, 12);
 					if (c == count)
 						return count;
 				}
Signature · 1 line
2.43.0
#1 lore raw
Quoted 57 lines · André Moreira

Extract the deeply nested loops handling PTS flags in the MPEG-1 block into a separate helper function av7110_ipack_m1_pts().

This fixes a checkpatch warning regarding too many leading tabs and improves code readability without changing the underlying parser logic.

---
 drivers/staging/media/av7110/av7110_ipack.c | 35 +++++++++++----------
 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/staging/media/av7110/av7110_ipack.c +17 -11
index 4be6e225f08e8..a3e69a737e97d 100644
@@ -136,6 +136,22 @@ static void write_ipack(struct ipack *p, const u8 *data, int count)
 	}
 }
 
+static int av7110_ipack_m1_pts(struct ipack *p, const u8 *buf,
+			       int c, int count, int max_which)
+{
+	while (c < count && p->which < max_which) {
+		if (p->which < 7)
+			p->pts[p->which - 2] = buf[c];
+
+		write_ipack(p, buf + c, 1);
+		c++;
+		p->found++;
+		p->which++;
+		p->hlength++;
+	}
+	return c;
+}
+
 int av7110_ipack_instant_repack(const u8 *buf, int count, struct ipack *p)
 {
 	int l;
@@ -335,26 +351,11 @@ int av7110_ipack_instant_repack(const u8 *buf, int count, struct ipack *p)
 				return count;
 			if (p->which > 2) {
 				if ((p->flag2 & PTS_DTS_FLAGS) == PTS_ONLY) {
-					while (c < count && p->which < 7) {
-						p->pts[p->which - 2] = buf[c];
-						write_ipack(p, buf + c, 1);
-						c++;
-						p->found++;
-						p->which++;
-						p->hlength++;
-					}
+					c = av7110_ipack_m1_pts(p, buf, c, count, 7);
 					if (c == count)
 						return count;
 				} else if ((p->flag2 & PTS_DTS_FLAGS) == PTS_DTS) {
-					while (c < count && p->which < 12) {
-						if (p->which < 7)
-							p->pts[p->which - 2] = buf[c];

drivers/staging/media/av7110/av7110_ipack.c int av7110_ipack_instant_repack(const u8 *buf, int count, struct ipack *p) · line 361

Quoted 10 lines
drivers/staging/media/av7110/av7110_ipack.c +1 -6
-						write_ipack(p, buf + c, 1);
-						c++;
-						p->found++;
-						p->which++;
-						p->hlength++;
-					}
+					c = av7110_ipack_m1_pts(p, buf, c, count, 12);
 					if (c == count)
 						return count;
 				}

Hmm, I think I'll just keep the code as-is. Creating a separate function for this makes the repack function actually harder to understand.

Regards,

Hans

#2 lore raw

Thanks, Hans. I agree. I'll keep the code as-is.

Regards,
André