mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] block: propagate error code from block_get
@ 2012-05-30  5:31 Sascha Hauer
  2012-05-30  5:31 ` [PATCH 2/2] block: do not BUG() on failed block_get Sascha Hauer
  2012-05-31 12:45 ` [PATCH 1/2] block: propagate error code from block_get Roberto Nibali
  0 siblings, 2 replies; 4+ messages in thread
From: Sascha Hauer @ 2012-05-30  5:31 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/block.c |   26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/common/block.c b/common/block.c
index 4253fc4..437dc95 100644
--- a/common/block.c
+++ b/common/block.c
@@ -161,7 +161,7 @@ static void *block_get(struct block_device *blk, int block)
 	int ret;
 
 	if (block >= blk->num_blocks)
-		return NULL;
+		return ERR_PTR(-ENXIO);
 
 	outdata = block_get_cached(blk, block);
 	if (outdata)
@@ -169,7 +169,7 @@ static void *block_get(struct block_device *blk, int block)
 
 	ret = block_cache(blk, block);
 	if (ret)
-		return NULL;
+		return ERR_PTR(ret);
 
 	outdata = block_get_cached(blk, block);
 	if (!outdata)
@@ -191,8 +191,8 @@ static ssize_t block_read(struct cdev *cdev, void *buf, size_t count,
 		size_t now = BLOCKSIZE(blk) - (offset & mask);
 		void *iobuf = block_get(blk, block);
 
-		if (!iobuf)
-			return -EIO;
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
 
 		now = min(count, now);
 
@@ -207,8 +207,8 @@ static ssize_t block_read(struct cdev *cdev, void *buf, size_t count,
 	while (blocks) {
 		void *iobuf = block_get(blk, block);
 
-		if (!iobuf)
-			return -EIO;
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
 
 		memcpy(buf, iobuf, BLOCKSIZE(blk));
 		buf += BLOCKSIZE(blk);
@@ -220,8 +220,8 @@ static ssize_t block_read(struct cdev *cdev, void *buf, size_t count,
 	if (count) {
 		void *iobuf = block_get(blk, block);
 
-		if (!iobuf)
-			return -EIO;
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
 
 		memcpy(buf, iobuf, count);
 	}
@@ -244,7 +244,7 @@ static int block_put(struct block_device *blk, const void *buf, int block)
 		return -EINVAL;
 
 	data = block_get(blk, block);
-	if (!data)
+	if (IS_ERR(data))
 		BUG();
 
 	memcpy(data, buf, 1 << blk->blockbits);
@@ -270,8 +270,8 @@ static ssize_t block_write(struct cdev *cdev, const void *buf, size_t count,
 
 		now = min(count, now);
 
-		if (!iobuf)
-			return -EIO;
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
 
 		memcpy(iobuf + (offset & mask), buf, now);
 		ret = block_put(blk, iobuf, block);
@@ -299,8 +299,8 @@ static ssize_t block_write(struct cdev *cdev, const void *buf, size_t count,
 	if (count) {
 		void *iobuf = block_get(blk, block);
 
-		if (!iobuf)
-			return -EIO;
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
 
 		memcpy(iobuf, buf, count);
 		ret = block_put(blk, iobuf, block);
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] block: do not BUG() on failed block_get
  2012-05-30  5:31 [PATCH 1/2] block: propagate error code from block_get Sascha Hauer
@ 2012-05-30  5:31 ` Sascha Hauer
  2012-05-31 12:46   ` Roberto Nibali
  2012-05-31 12:45 ` [PATCH 1/2] block: propagate error code from block_get Roberto Nibali
  1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2012-05-30  5:31 UTC (permalink / raw)
  To: barebox

It does not necessarily means a bug when block_get fails here,
this can also be a failure on the underlying device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/block.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/block.c b/common/block.c
index 437dc95..5983171 100644
--- a/common/block.c
+++ b/common/block.c
@@ -245,7 +245,7 @@ static int block_put(struct block_device *blk, const void *buf, int block)
 
 	data = block_get(blk, block);
 	if (IS_ERR(data))
-		BUG();
+		return PTR_ERR(data);
 
 	memcpy(data, buf, 1 << blk->blockbits);
 
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] block: propagate error code from block_get
  2012-05-30  5:31 [PATCH 1/2] block: propagate error code from block_get Sascha Hauer
  2012-05-30  5:31 ` [PATCH 2/2] block: do not BUG() on failed block_get Sascha Hauer
@ 2012-05-31 12:45 ` Roberto Nibali
  1 sibling, 0 replies; 4+ messages in thread
From: Roberto Nibali @ 2012-05-31 12:45 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


[-- Attachment #1.1: Type: text/plain, Size: 3680 bytes --]

Hi Sascha

On Wed, May 30, 2012 at 7:31 AM, Sascha Hauer <s.hauer@pengutronix.de>wrote:

> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  common/block.c |   26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/common/block.c b/common/block.c
> index 4253fc4..437dc95 100644
> --- a/common/block.c
> +++ b/common/block.c
> @@ -161,7 +161,7 @@ static void *block_get(struct block_device *blk, int
> block)
>        int ret;
>
>        if (block >= blk->num_blocks)
> -               return NULL;
> +               return ERR_PTR(-ENXIO);
>
>        outdata = block_get_cached(blk, block);
>        if (outdata)
> @@ -169,7 +169,7 @@ static void *block_get(struct block_device *blk, int
> block)
>
>        ret = block_cache(blk, block);
>        if (ret)
> -               return NULL;
> +               return ERR_PTR(ret);
>
>        outdata = block_get_cached(blk, block);
>        if (!outdata)
> @@ -191,8 +191,8 @@ static ssize_t block_read(struct cdev *cdev, void
> *buf, size_t count,
>                size_t now = BLOCKSIZE(blk) - (offset & mask);
>                void *iobuf = block_get(blk, block);
>
> -               if (!iobuf)
> -                       return -EIO;
> +               if (IS_ERR(iobuf))
> +                       return PTR_ERR(iobuf);
>
>                now = min(count, now);
>
> @@ -207,8 +207,8 @@ static ssize_t block_read(struct cdev *cdev, void
> *buf, size_t count,
>        while (blocks) {
>                void *iobuf = block_get(blk, block);
>
> -               if (!iobuf)
> -                       return -EIO;
> +               if (IS_ERR(iobuf))
> +                       return PTR_ERR(iobuf);
>
>                memcpy(buf, iobuf, BLOCKSIZE(blk));
>                buf += BLOCKSIZE(blk);
> @@ -220,8 +220,8 @@ static ssize_t block_read(struct cdev *cdev, void
> *buf, size_t count,
>        if (count) {
>                void *iobuf = block_get(blk, block);
>
> -               if (!iobuf)
> -                       return -EIO;
> +               if (IS_ERR(iobuf))
> +                       return PTR_ERR(iobuf);
>
>                memcpy(buf, iobuf, count);
>        }
> @@ -244,7 +244,7 @@ static int block_put(struct block_device *blk, const
> void *buf, int block)
>                return -EINVAL;
>
>        data = block_get(blk, block);
> -       if (!data)
> +       if (IS_ERR(data))
>                BUG();
>
>        memcpy(data, buf, 1 << blk->blockbits);
> @@ -270,8 +270,8 @@ static ssize_t block_write(struct cdev *cdev, const
> void *buf, size_t count,
>
>                now = min(count, now);
>
> -               if (!iobuf)
> -                       return -EIO;
> +               if (IS_ERR(iobuf))
> +                       return PTR_ERR(iobuf);
>
>                memcpy(iobuf + (offset & mask), buf, now);
>                ret = block_put(blk, iobuf, block);
> @@ -299,8 +299,8 @@ static ssize_t block_write(struct cdev *cdev, const
> void *buf, size_t count,
>        if (count) {
>                void *iobuf = block_get(blk, block);
>
> -               if (!iobuf)
> -                       return -EIO;
> +               if (IS_ERR(iobuf))
> +                       return PTR_ERR(iobuf);
>
>                memcpy(iobuf, buf, count);
>                ret = block_put(blk, iobuf, block);
> --
> 1.7.10
>
>
Compile and run-time tested; results in a proper error message propagated
by the block layer:

imx-esdhc@imx-esdhc0: timeout 1
mci@mci0: Reading block 2560 failed with -110
block_cache: blk->ops->read returned -110

Therefore:

Tested-by: Roberto Nibali <rnibali@gmail.com>
Acked-by: Roberto Nibali <rnibali@gmail.com>

Cheers
Roberto

[-- Attachment #1.2: Type: text/html, Size: 4639 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] block: do not BUG() on failed block_get
  2012-05-30  5:31 ` [PATCH 2/2] block: do not BUG() on failed block_get Sascha Hauer
@ 2012-05-31 12:46   ` Roberto Nibali
  0 siblings, 0 replies; 4+ messages in thread
From: Roberto Nibali @ 2012-05-31 12:46 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


[-- Attachment #1.1: Type: text/plain, Size: 863 bytes --]

Hi

On Wed, May 30, 2012 at 7:31 AM, Sascha Hauer <s.hauer@pengutronix.de>wrote:

> It does not necessarily means a bug when block_get fails here,
> this can also be a failure on the underlying device.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  common/block.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/common/block.c b/common/block.c
> index 437dc95..5983171 100644
> --- a/common/block.c
> +++ b/common/block.c
> @@ -245,7 +245,7 @@ static int block_put(struct block_device *blk, const
> void *buf, int block)
>
>        data = block_get(blk, block);
>        if (IS_ERR(data))
> -               BUG();
> +               return PTR_ERR(data);
>
>        memcpy(data, buf, 1 << blk->blockbits);
>
> --
> 1.7.10
>
>
Tested-by: Roberto Nibali <rnibali@gmail.com>
Acked-by: Roberto Nibali <rnibali@gmail.com>

[-- Attachment #1.2: Type: text/html, Size: 1464 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-31 12:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-30  5:31 [PATCH 1/2] block: propagate error code from block_get Sascha Hauer
2012-05-30  5:31 ` [PATCH 2/2] block: do not BUG() on failed block_get Sascha Hauer
2012-05-31 12:46   ` Roberto Nibali
2012-05-31 12:45 ` [PATCH 1/2] block: propagate error code from block_get Roberto Nibali

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox