Skip to contentSkip to conversation

media: use swap() to make code cleaner

PATCH In review [email protected] 4 participants 5 messages Nov 3, 2021 – Nov 8, 2021

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

PATCH 1/1 media: use swap() to make code cleaner

From: Yang Guang <[email protected]>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid opencoding it.

---
 drivers/media/pci/saa7134/saa7134-video.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/pci/saa7134/saa7134-video.c +2 -4
index 374c8e1087de..6f4132058c35 100644
@@ -823,7 +823,7 @@ static int buffer_activate(struct saa7134_dev *dev,
 {
 	struct saa7134_dmaqueue *dmaq = buf->vb2.vb2_buf.vb2_queue->drv_priv;
 	unsigned long base,control,bpl;
-	unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
+	unsigned long bpl_uv, lines_uv, base2, base3; /* planar */
 
 	video_dbg("buffer_activate buf=%p\n", buf);
 	buf->top_seen = 0;
@@ -869,9 +869,7 @@ static int buffer_activate(struct saa7134_dev *dev,
 		base2    = base + bpl * dev->height;
 		base3    = base2 + bpl_uv * lines_uv;
 		if (dev->fmt->uvswap) {
-			tmp = base2;
-			base2 = base3;
-			base3 = tmp;
+			swap(base2, base3);
 		}
 		video_dbg("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
 			bpl_uv,lines_uv,base2,base3);
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw

Hi David,

Is this patch something you discovered somewhere and have posted on behalf of Yang Guang?

Have you made any modifications to it that would require your sign off? or is it simply a repost of a patch you came across?

Quoting [email protected] (2021-11-03 08:33:37)

Quoted 6 lines

From: Yang Guang <[email protected]>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid opencoding it.

The change itself looks fine to me though.

Quoted 31 lines
---
 drivers/media/pci/saa7134/saa7134-video.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/pci/saa7134/saa7134-video.c +2 -4
index 374c8e1087de..6f4132058c35 100644
@@ -823,7 +823,7 @@ static int buffer_activate(struct saa7134_dev *dev,
 {
        struct saa7134_dmaqueue *dmaq = buf->vb2.vb2_buf.vb2_queue->drv_priv;
        unsigned long base,control,bpl;
-       unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
+       unsigned long bpl_uv, lines_uv, base2, base3; /* planar */
 
        video_dbg("buffer_activate buf=%p\n", buf);
        buf->top_seen = 0;
@@ -869,9 +869,7 @@ static int buffer_activate(struct saa7134_dev *dev,
                base2    = base + bpl * dev->height;
                base3    = base2 + bpl_uv * lines_uv;
                if (dev->fmt->uvswap) {
-                       tmp = base2;
-                       base2 = base3;
-                       base3 = tmp;
+                       swap(base2, base3);
                }
                video_dbg("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
                        bpl_uv,lines_uv,base2,base3);
Signature · 1 line
2.30.2
author
#2 lore raw

Hi Kieran,

Both of [email protected] and [email protected] are mine.
Because the [email protected] can't send email out. So I use the gmail to send.

Thanks.

Quoted 51 lines · Kieran Bingham

Hi David,

Is this patch something you discovered somewhere and have posted on behalf of Yang Guang?

Have you made any modifications to it that would require your sign off? or is it simply a repost of a patch you came across?

Quoting [email protected] (2021-11-03 08:33:37)

Quoted 6 lines

From: Yang Guang <[email protected]>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid opencoding it.

The change itself looks fine to me though.

Quoted 31 lines
---
 drivers/media/pci/saa7134/saa7134-video.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/pci/saa7134/saa7134-video.c +2 -4
index 374c8e1087de..6f4132058c35 100644
@@ -823,7 +823,7 @@ static int buffer_activate(struct saa7134_dev *dev,
 {
        struct saa7134_dmaqueue *dmaq = buf->vb2.vb2_buf.vb2_queue->drv_priv;
        unsigned long base,control,bpl;
-       unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
+       unsigned long bpl_uv, lines_uv, base2, base3; /* planar */
 
        video_dbg("buffer_activate buf=%p\n", buf);
        buf->top_seen = 0;
@@ -869,9 +869,7 @@ static int buffer_activate(struct saa7134_dev *dev,
                base2    = base + bpl * dev->height;
                base3    = base2 + bpl_uv * lines_uv;
                if (dev->fmt->uvswap) {
-                       tmp = base2;
-                       base2 = base3;
-                       base3 = tmp;
+                       swap(base2, base3);
                }
                video_dbg("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
                        bpl_uv,lines_uv,base2,base3);
Signature · 1 line
2.30.2
#3 lore raw
In reply to [email protected]
Quoted 2 lines · On Wed, Nov 3, 2021 at 10:34 AM <[email protected]> wrote:

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid opencoding it.

Same comments as per all your valuable contributions: just think more about the code that you are dealing with!

drivers/media/pci/saa7134/saa7134-video.c static int buffer_activate(struct saa7134_dev *dev, · line 873

Quoted 6 lines
                if (dev->fmt->uvswap) {
drivers/media/pci/saa7134/saa7134-video.c +1 -3
-                       tmp = base2;
-                       base2 = base3;
-                       base3 = tmp;
+                       swap(base2, base3);
                }

Have you run checkpatch? What did it say?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · On Wed, Nov 3, 2021 at 10:34 AM <[email protected]> wrote:

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid opencoding it.

Same comments as per all your valuable contributions: just think more about the code that you are dealing with!

Quoted 9 lines

drivers/media/pci/saa7134/saa7134-video.c static int buffer_activate(struct saa7134_dev *dev, · line 873

Quoted 6 lines
                if (dev->fmt->uvswap) {
drivers/media/pci/saa7134/saa7134-video.c +1 -3
-                       tmp = base2;
-                       base2 = base3;
-                       base3 = tmp;
+                       swap(base2, base3);
                }

Have you run checkpatch? What did it say?

checkpatch says all is fine :-)

But yes, the {} can now be dropped. If I apply the patch, then run checkpatch, it will indeed complain about the {}.

Regards,

Hans