Skip to content

Commit 9017960

Browse files
qianfengrongbroonie
authored andcommitted
spi: spl022: use min_t() to improve code
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>
1 parent 1bdc716 commit 9017960

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

drivers/spi/spi-pl022.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/pm_runtime.h>
3434
#include <linux/of.h>
3535
#include <linux/pinctrl/consumer.h>
36+
#include <linux/minmax.h>
3637

3738
/*
3839
* This macro is used to define some register default values.
@@ -760,10 +761,9 @@ static void setup_dma_scatter(struct pl022 *pl022,
760761
* we just feed in this, else we stuff in as much
761762
* as we can.
762763
*/
763-
if (bytesleft < (PAGE_SIZE - offset_in_page(bufp)))
764-
mapbytes = bytesleft;
765-
else
766-
mapbytes = PAGE_SIZE - offset_in_page(bufp);
764+
mapbytes = min_t(int, bytesleft,
765+
PAGE_SIZE - offset_in_page(bufp));
766+
767767
sg_set_page(sg, virt_to_page(bufp),
768768
mapbytes, offset_in_page(bufp));
769769
bufp += mapbytes;
@@ -775,10 +775,7 @@ static void setup_dma_scatter(struct pl022 *pl022,
775775
} else {
776776
/* Map the dummy buffer on every page */
777777
for_each_sg(sgtab->sgl, sg, sgtab->nents, i) {
778-
if (bytesleft < PAGE_SIZE)
779-
mapbytes = bytesleft;
780-
else
781-
mapbytes = PAGE_SIZE;
778+
mapbytes = min_t(int, bytesleft, PAGE_SIZE);
782779
sg_set_page(sg, virt_to_page(pl022->dummypage),
783780
mapbytes, 0);
784781
bytesleft -= mapbytes;

0 commit comments

Comments
 (0)