diff mbox series

[2/3] media: hantro: h264: Rename POC_CMP() into HANTRO_CMP()

Message ID 20190909072815.23981-2-boris.brezillon@collabora.com (mailing list archive)
State New, archived
Headers show
Series [1/3] media: hantro: h264: Fix a comment in b1_ref_list_cmp() | expand

Commit Message

Boris Brezillon Sept. 9, 2019, 7:28 a.m. UTC
And use it for all native type comparisons, even if it's not strictly
required. By doing that we make the code more consistent and prevent
from potential incorrect results in case of overflow or when the the
values being compared are both negative.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
 drivers/staging/media/hantro/hantro_h264.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

Comments

Francois Buergisser Sept. 18, 2019, 5:03 a.m. UTC | #1
On Mon, Sep 9, 2019 at 4:28 PM Boris Brezillon
<boris.brezillon@collabora.com> wrote:
>
> And use it for all native type comparisons, even if it's not strictly
> required. By doing that we make the code more consistent and prevent
> from potential incorrect results in case of overflow or when the the
> values being compared are both negative.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Tested-by: Francois Buergisser <fbuergisser@chromium.org>
Tomasz Figa Sept. 18, 2019, 6:19 a.m. UTC | #2
On Wed, Sep 18, 2019 at 2:04 PM Francois Buergisser
<fbuergisser@google.com> wrote:
>
> On Mon, Sep 9, 2019 at 4:28 PM Boris Brezillon
> <boris.brezillon@collabora.com> wrote:
> >
> > And use it for all native type comparisons, even if it's not strictly
> > required. By doing that we make the code more consistent and prevent
> > from potential incorrect results in case of overflow or when the the
> > values being compared are both negative.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> Tested-by: Francois Buergisser <fbuergisser@chromium.org>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>

Best regards,
Tomasz
diff mbox series

Patch

diff --git a/drivers/staging/media/hantro/hantro_h264.c b/drivers/staging/media/hantro/hantro_h264.c
index f070e7174007..881d73977ff6 100644
--- a/drivers/staging/media/hantro/hantro_h264.c
+++ b/drivers/staging/media/hantro/hantro_h264.c
@@ -22,7 +22,7 @@ 
 #define POC_BUFFER_SIZE			34
 #define SCALING_LIST_SIZE		(6 * 16 + 6 * 64)
 
-#define POC_CMP(p0, p1) ((p0) < (p1) ? -1 : 1)
+#define HANTRO_CMP(a, b) ((a) < (b) ? -1 : 1)
 
 /* Data structure describing auxiliary buffer format. */
 struct hantro_h264_dec_priv_tbl {
@@ -353,9 +353,9 @@  static int p_ref_list_cmp(const void *ptra, const void *ptrb, const void *data)
 	 * ascending order.
 	 */
 	if (!(a->flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM))
-		return b->frame_num - a->frame_num;
+		return HANTRO_CMP(b->frame_num, a->frame_num);
 
-	return a->pic_num - b->pic_num;
+	return HANTRO_CMP(a->pic_num, b->pic_num);
 }
 
 static int b0_ref_list_cmp(const void *ptra, const void *ptrb, const void *data)
@@ -381,7 +381,7 @@  static int b0_ref_list_cmp(const void *ptra, const void *ptrb, const void *data)
 
 	/* Long term pics in ascending pic num order. */
 	if (a->flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)
-		return a->pic_num - b->pic_num;
+		return HANTRO_CMP(a->pic_num, b->pic_num);
 
 	poca = builder->pocs[idxa];
 	pocb = builder->pocs[idxb];
@@ -392,11 +392,11 @@  static int b0_ref_list_cmp(const void *ptra, const void *ptrb, const void *data)
 	 * order.
 	 */
 	if ((poca < builder->curpoc) != (pocb < builder->curpoc))
-		return POC_CMP(poca, pocb);
+		return HANTRO_CMP(poca, pocb);
 	else if (poca < builder->curpoc)
-		return POC_CMP(pocb, poca);
+		return HANTRO_CMP(pocb, poca);
 
-	return POC_CMP(poca, pocb);
+	return HANTRO_CMP(poca, pocb);
 }
 
 static int b1_ref_list_cmp(const void *ptra, const void *ptrb, const void *data)
@@ -422,7 +422,7 @@  static int b1_ref_list_cmp(const void *ptra, const void *ptrb, const void *data)
 
 	/* Long term pics in ascending pic num order. */
 	if (a->flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)
-		return a->pic_num - b->pic_num;
+		return HANTRO_CMP(a->pic_num, b->pic_num);
 
 	poca = builder->pocs[idxa];
 	pocb = builder->pocs[idxb];
@@ -433,11 +433,11 @@  static int b1_ref_list_cmp(const void *ptra, const void *ptrb, const void *data)
 	 * order.
 	 */
 	if ((poca < builder->curpoc) != (pocb < builder->curpoc))
-		return POC_CMP(pocb, poca);
+		return HANTRO_CMP(pocb, poca);
 	else if (poca < builder->curpoc)
-		return POC_CMP(pocb, poca);
+		return HANTRO_CMP(pocb, poca);
 
-	return POC_CMP(poca, pocb);
+	return HANTRO_CMP(poca, pocb);
 }
 
 static void