2016-11-09 02:07:38

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 0/3] mtd: some minor cleanups for ooblayout APIs

- Remove unnecessary initializers
- Use min_t() helper

Masahiro Yamada (3):
mtd: remove unneeded initializer in mtd_ooblayout_{get,set}_bytes()
mtd: use min_t() to refactor mtd_ooblayout_{get,set}_bytes()
mtd: remove unneeded initializer in mtd_ooblayout_count_bytes()

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

--
1.9.1


2016-11-09 02:07:40

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 1/3] mtd: remove unneeded initializer in mtd_ooblayout_{get,set}_bytes()

There is no need to initialize oobregion and section since they will
be filled by mtd_ooblayout_find_region().

Signed-off-by: Masahiro Yamada <[email protected]>
---

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

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index d46e4ad..cf85f2b 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1274,8 +1274,8 @@ static int mtd_ooblayout_get_bytes(struct mtd_info *mtd, u8 *buf,
int section,
struct mtd_oob_region *oobregion))
{
- struct mtd_oob_region oobregion = { };
- int section = 0, ret;
+ struct mtd_oob_region oobregion;
+ int section, ret;

ret = mtd_ooblayout_find_region(mtd, start, &section,
&oobregion, iter);
@@ -1317,8 +1317,8 @@ static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf,
int section,
struct mtd_oob_region *oobregion))
{
- struct mtd_oob_region oobregion = { };
- int section = 0, ret;
+ struct mtd_oob_region oobregion;
+ int section, ret;

ret = mtd_ooblayout_find_region(mtd, start, &section,
&oobregion, iter);
--
1.9.1

2016-11-09 02:07:42

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 3/3] mtd: remove unneeded initializer in mtd_ooblayout_count_bytes()

There is no need to initialize oobregion since it will be filled by
the iterator.

This function is called with mtd_ooblayout_free or mtd_ooblayout_ecc
for the iterator; both of them calls memset() to clear the oobregion.

Signed-off-by: Masahiro Yamada <[email protected]>
---

drivers/mtd/mtdcore.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index ca6a89a..ca661ce 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1354,7 +1354,7 @@ static int mtd_ooblayout_count_bytes(struct mtd_info *mtd,
int section,
struct mtd_oob_region *oobregion))
{
- struct mtd_oob_region oobregion = { };
+ struct mtd_oob_region oobregion;
int section = 0, ret, nbytes = 0;

while (1) {
--
1.9.1

2016-11-09 02:08:11

by Masahiro Yamada

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

I hope this will make the code a little more readable.

Signed-off-by: Masahiro Yamada <[email protected]>
---

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;
--
1.9.1

2016-11-12 21:56:00

by Marek Vasut

[permalink] [raw]
Subject: Re: [PATCH 1/3] mtd: remove unneeded initializer in mtd_ooblayout_{get, set}_bytes()

On 11/09/2016 03:08 AM, Masahiro Yamada wrote:
> There is no need to initialize oobregion and section since they will
> be filled by mtd_ooblayout_find_region().
>
> Signed-off-by: Masahiro Yamada <[email protected]>

Reviewed-by: Marek Vasut <[email protected]>

> ---
>
> drivers/mtd/mtdcore.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index d46e4ad..cf85f2b 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -1274,8 +1274,8 @@ static int mtd_ooblayout_get_bytes(struct mtd_info *mtd, u8 *buf,
> int section,
> struct mtd_oob_region *oobregion))
> {
> - struct mtd_oob_region oobregion = { };
> - int section = 0, ret;
> + struct mtd_oob_region oobregion;
> + int section, ret;
>
> ret = mtd_ooblayout_find_region(mtd, start, &section,
> &oobregion, iter);
> @@ -1317,8 +1317,8 @@ static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf,
> int section,
> struct mtd_oob_region *oobregion))
> {
> - struct mtd_oob_region oobregion = { };
> - int section = 0, ret;
> + struct mtd_oob_region oobregion;
> + int section, ret;
>
> ret = mtd_ooblayout_find_region(mtd, start, &section,
> &oobregion, iter);
>


--
Best regards,
Marek Vasut

2016-11-12 21:56:02

by Marek Vasut

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

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 <[email protected]>

Reviewed-by: Marek Vasut <[email protected]>

> ---
>
> 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

2016-11-12 21:56:05

by Marek Vasut

[permalink] [raw]
Subject: Re: [PATCH 3/3] mtd: remove unneeded initializer in mtd_ooblayout_count_bytes()

On 11/09/2016 03:08 AM, Masahiro Yamada wrote:
> There is no need to initialize oobregion since it will be filled by
> the iterator.
>
> This function is called with mtd_ooblayout_free or mtd_ooblayout_ecc
> for the iterator; both of them calls memset() to clear the oobregion.
>
> Signed-off-by: Masahiro Yamada <[email protected]>

Reviewed-by: Marek Vasut <[email protected]>

> ---
>
> drivers/mtd/mtdcore.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index ca6a89a..ca661ce 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -1354,7 +1354,7 @@ static int mtd_ooblayout_count_bytes(struct mtd_info *mtd,
> int section,
> struct mtd_oob_region *oobregion))
> {
> - struct mtd_oob_region oobregion = { };
> + struct mtd_oob_region oobregion;
> int section = 0, ret, nbytes = 0;
>
> while (1) {
>


--
Best regards,
Marek Vasut

2016-11-20 09:42:41

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH 0/3] mtd: some minor cleanups for ooblayout APIs

On Wed, 9 Nov 2016 11:08:07 +0900
Masahiro Yamada <[email protected]> wrote:

> - Remove unnecessary initializers
> - Use min_t() helper

Applied.

Thanks,

Boris

>
> Masahiro Yamada (3):
> mtd: remove unneeded initializer in mtd_ooblayout_{get,set}_bytes()
> mtd: use min_t() to refactor mtd_ooblayout_{get,set}_bytes()
> mtd: remove unneeded initializer in mtd_ooblayout_count_bytes()
>
> drivers/mtd/mtdcore.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>