diff mbox

[2/3] mtd: use min_t() to refactor mtd_ooblayout_{get,set}_bytes()

Message ID 1478657290-9430-3-git-send-email-yamada.masahiro@socionext.com
State Accepted
Commit 7c295ef9642c107203a485843853b12d6f5cdb39
Headers show

Commit Message

Masahiro Yamada Nov. 9, 2016, 2:08 a.m. UTC
I hope this will make the code a little more readable.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

 drivers/mtd/mtdcore.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
1.9.1

Comments

Marek Vasut Nov. 12, 2016, 9:27 p.m. UTC | #1
On 11/09/2016 03:08 AM, Masahiro Yamada wrote:
> I hope this will make the code a little more readable.

> 

> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


Reviewed-by: Marek Vasut <marek.vasut@gmail.com>


> ---

> 

>  drivers/mtd/mtdcore.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c

> index cf85f2b..ca6a89a 100644

> --- a/drivers/mtd/mtdcore.c

> +++ b/drivers/mtd/mtdcore.c

> @@ -1283,7 +1283,7 @@ static int mtd_ooblayout_get_bytes(struct mtd_info *mtd, u8 *buf,

>  	while (!ret) {

>  		int cnt;

>  

> -		cnt = oobregion.length > nbytes ? nbytes : oobregion.length;

> +		cnt = min_t(int, nbytes, oobregion.length);

>  		memcpy(buf, oobbuf + oobregion.offset, cnt);

>  		buf += cnt;

>  		nbytes -= cnt;

> @@ -1326,7 +1326,7 @@ static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf,

>  	while (!ret) {

>  		int cnt;

>  

> -		cnt = oobregion.length > nbytes ? nbytes : oobregion.length;

> +		cnt = min_t(int, nbytes, oobregion.length);

>  		memcpy(oobbuf + oobregion.offset, buf, cnt);

>  		buf += cnt;

>  		nbytes -= cnt;

> 



-- 
Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index cf85f2b..ca6a89a 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1283,7 +1283,7 @@  static int mtd_ooblayout_get_bytes(struct mtd_info *mtd, u8 *buf,
 	while (!ret) {
 		int cnt;
 
-		cnt = oobregion.length > nbytes ? nbytes : oobregion.length;
+		cnt = min_t(int, nbytes, oobregion.length);
 		memcpy(buf, oobbuf + oobregion.offset, cnt);
 		buf += cnt;
 		nbytes -= cnt;
@@ -1326,7 +1326,7 @@  static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf,
 	while (!ret) {
 		int cnt;
 
-		cnt = oobregion.length > nbytes ? nbytes : oobregion.length;
+		cnt = min_t(int, nbytes, oobregion.length);
 		memcpy(oobbuf + oobregion.offset, buf, cnt);
 		buf += cnt;
 		nbytes -= cnt;