]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
spi: spl022: use min_t() to improve code
authorQianfeng Rong <rongqianfeng@vivo.com>
Fri, 15 Aug 2025 08:21:17 +0000 (16:21 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 18 Aug 2025 12:14:04 +0000 (13:14 +0100)
Use min_t() to reduce the code in setup_dma_scatter() and improve its
readability.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Link: https://patch.msgid.link/20250815082118.586422-4-rongqianfeng@vivo.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-pl022.c

index dd87cf4f70dd5678f348d2e16e933e8707ce3923..9e56e87746142f0d637c70758772860ba120f18d 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/of.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/minmax.h>
 
 /*
  * This macro is used to define some register default values.
@@ -760,10 +761,9 @@ static void setup_dma_scatter(struct pl022 *pl022,
                         * we just feed in this, else we stuff in as much
                         * as we can.
                         */
-                       if (bytesleft < (PAGE_SIZE - offset_in_page(bufp)))
-                               mapbytes = bytesleft;
-                       else
-                               mapbytes = PAGE_SIZE - offset_in_page(bufp);
+                       mapbytes = min_t(int, bytesleft,
+                                        PAGE_SIZE - offset_in_page(bufp));
+
                        sg_set_page(sg, virt_to_page(bufp),
                                    mapbytes, offset_in_page(bufp));
                        bufp += mapbytes;
@@ -775,10 +775,7 @@ static void setup_dma_scatter(struct pl022 *pl022,
        } else {
                /* Map the dummy buffer on every page */
                for_each_sg(sgtab->sgl, sg, sgtab->nents, i) {
-                       if (bytesleft < PAGE_SIZE)
-                               mapbytes = bytesleft;
-                       else
-                               mapbytes = PAGE_SIZE;
+                       mapbytes = min_t(int, bytesleft, PAGE_SIZE);
                        sg_set_page(sg, virt_to_page(pl022->dummypage),
                                    mapbytes, 0);
                        bytesleft -= mapbytes;