diff mbox

[1/8] mtd-utils: Fix return status in mtd_torture test function

Message ID 1461622409-14970-2-git-send-email-richard@nod.at
State Accepted
Headers show

Commit Message

Richard Weinberger April 25, 2016, 10:13 p.m. UTC
From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>

This patch fixes the return status of the mtd_torture function
in libmtd.

The torture test function is currently only used by the ubiformat
utilitiy to check if a block is bad after a write fails (blocks are
marked bad if the function returns an error status). However, the
way the function was written, it ALWAYS returns an error value
irregardless of whether it failed or not.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 lib/libmtd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Boris Brezillon April 26, 2016, 7:57 a.m. UTC | #1
On Tue, 26 Apr 2016 00:13:22 +0200
Richard Weinberger <richard@nod.at> wrote:

> From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
> 
> This patch fixes the return status of the mtd_torture function
> in libmtd.
> 
> The torture test function is currently only used by the ubiformat
> utilitiy to check if a block is bad after a write fails (blocks are
> marked bad if the function returns an error status). However, the
> way the function was written, it ALWAYS returns an error value
> irregardless of whether it failed or not.
> 
> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
> Signed-off-by: Richard Weinberger <richard@nod.at>

Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>

> ---
>  lib/libmtd.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/libmtd.c b/lib/libmtd.c
> index bf6d71f..1717468 100644
> --- a/lib/libmtd.c
> +++ b/lib/libmtd.c
> @@ -939,7 +939,7 @@ static uint8_t patterns[] = {0xa5, 0x5a, 0x0};
>   * @patt: the pattern to check
>   * @size: buffer size in bytes
>   *
> - * This function returns %1 in there are only @patt bytes in @buf, and %0 if
> + * This function returns %0 if there are only @patt bytes in @buf, and %-1 if
>   * something else was also found.
>   */
>  static int check_pattern(const void *buf, uint8_t patt, int size)
> @@ -948,8 +948,8 @@ static int check_pattern(const void *buf, uint8_t patt, int size)
>  
>  	for (i = 0; i < size; i++)
>  		if (((const uint8_t *)buf)[i] != patt)
> -			return 0;
> -	return 1;
> +			return -1;
> +	return 0;
>  }
>  
>  int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
> @@ -973,7 +973,7 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
>  			goto out;
>  
>  		err = check_pattern(buf, 0xFF, mtd->eb_size);
> -		if (err == 0) {
> +		if (err) {
>  			errmsg("erased PEB %d, but a non-0xFF byte found", eb);
>  			errno = EIO;
>  			goto out;
> @@ -992,7 +992,7 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
>  			goto out;
>  
>  		err = check_pattern(buf, patterns[i], mtd->eb_size);
> -		if (err == 0) {
> +		if (err) {
>  			errmsg("pattern %x checking failed for PEB %d",
>  				patterns[i], eb);
>  			errno = EIO;
> @@ -1005,7 +1005,7 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
>  
>  out:
>  	free(buf);
> -	return -1;
> +	return err;
>  }
>  
>  int mtd_is_bad(const struct mtd_dev_info *mtd, int fd, int eb)
Brian Norris July 13, 2016, 5:30 p.m. UTC | #2
On Tue, Apr 26, 2016 at 12:13:22AM +0200, Richard Weinberger wrote:
> From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
> 
> This patch fixes the return status of the mtd_torture function
> in libmtd.
> 
> The torture test function is currently only used by the ubiformat
> utilitiy to check if a block is bad after a write fails (blocks are
> marked bad if the function returns an error status). However, the
> way the function was written, it ALWAYS returns an error value
> irregardless of whether it failed or not.
> 
> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
> Signed-off-by: Richard Weinberger <richard@nod.at>

Seems like everyone's reviewed this, but no one applied it. (Richard,
did we get you push access to mtd-utils yet?)

Applied patch 1.

Brian
Richard Weinberger July 13, 2016, 9:59 p.m. UTC | #3
Brian,

Am 13.07.2016 um 19:30 schrieb Brian Norris:
> On Tue, Apr 26, 2016 at 12:13:22AM +0200, Richard Weinberger wrote:
>> From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
>>
>> This patch fixes the return status of the mtd_torture function
>> in libmtd.
>>
>> The torture test function is currently only used by the ubiformat
>> utilitiy to check if a block is bad after a write fails (blocks are
>> marked bad if the function returns an error status). However, the
>> way the function was written, it ALWAYS returns an error value
>> irregardless of whether it failed or not.
>>
>> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
>> Signed-off-by: Richard Weinberger <richard@nod.at>
> 
> Seems like everyone's reviewed this, but no one applied it. (Richard,
> did we get you push access to mtd-utils yet?)

I think I have write access.

But I'm still a bit unsure how the mtd-utils release cycle
works.
In fact, I fear there is none. ;-)

David was so kind and went through linux-mtd@ to located old but not merged
mtd-utils packages.
I'm currently rebasing them to 1.5.2 and would push them later into a temporary
branch.

Thanks,
//richard
Brian Norris July 13, 2016, 10:06 p.m. UTC | #4
On Wed, Jul 13, 2016 at 11:59:00PM +0200, Richard Weinberger wrote:
> But I'm still a bit unsure how the mtd-utils release cycle
> works.
> In fact, I fear there is none. ;-)

Yep, that's about correct. We can try to establish one if that'd help.
Previously, I think it was "whenever Artem decided there were enough
new things (fixes or features)".

> David was so kind and went through linux-mtd@ to located old but not merged
> mtd-utils packages.
> I'm currently rebasing them to 1.5.2 and would push them later into a temporary
> branch.

Cool.

Brian
diff mbox

Patch

diff --git a/lib/libmtd.c b/lib/libmtd.c
index bf6d71f..1717468 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -939,7 +939,7 @@  static uint8_t patterns[] = {0xa5, 0x5a, 0x0};
  * @patt: the pattern to check
  * @size: buffer size in bytes
  *
- * This function returns %1 in there are only @patt bytes in @buf, and %0 if
+ * This function returns %0 if there are only @patt bytes in @buf, and %-1 if
  * something else was also found.
  */
 static int check_pattern(const void *buf, uint8_t patt, int size)
@@ -948,8 +948,8 @@  static int check_pattern(const void *buf, uint8_t patt, int size)
 
 	for (i = 0; i < size; i++)
 		if (((const uint8_t *)buf)[i] != patt)
-			return 0;
-	return 1;
+			return -1;
+	return 0;
 }
 
 int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
@@ -973,7 +973,7 @@  int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
 			goto out;
 
 		err = check_pattern(buf, 0xFF, mtd->eb_size);
-		if (err == 0) {
+		if (err) {
 			errmsg("erased PEB %d, but a non-0xFF byte found", eb);
 			errno = EIO;
 			goto out;
@@ -992,7 +992,7 @@  int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
 			goto out;
 
 		err = check_pattern(buf, patterns[i], mtd->eb_size);
-		if (err == 0) {
+		if (err) {
 			errmsg("pattern %x checking failed for PEB %d",
 				patterns[i], eb);
 			errno = EIO;
@@ -1005,7 +1005,7 @@  int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
 
 out:
 	free(buf);
-	return -1;
+	return err;
 }
 
 int mtd_is_bad(const struct mtd_dev_info *mtd, int fd, int eb)