Skip to contentSkip to conversation

mtd: blktrans: change blktrans_getgeo rerurn value

PATCH In review Wenlin Kang 5 participants 12 messages May 13, 2015 – May 27, 2015 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: blktrans: change blktrans_getgeo rerurn value

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +1 -1
index 2b0c5287..f8bb16e 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 	if (!dev->mtd)
 		goto unlock;
 
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;
 unlock:
 	mutex_unlock(&dev->lock);
 	blktrans_dev_put(dev);
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Wenlin,

In the subject:

s/rerurn/return/

Quoted 18 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 276

Quoted 5 lines
drivers/mtd/mtd_blkdevs.c +1 -1
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 	if (!dev->mtd)
 		goto unlock;
 
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 279

Quoted 3 lines
drivers/mtd/mtd_blkdevs.c +0 -0
 unlock:
 	mutex_unlock(&dev->lock);
 	blktrans_dev_put(dev);

Thanks,
Brian

#2 lore raw
Quoted 28 lines · Brian Norris

Hi Wenlin,

In the subject:

s/rerurn/return/

Quoted 21 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 	if (!dev->mtd)
 		goto unlock;
 
Quoted 6 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 276

Quoted 2 lines
drivers/mtd/mtd_blkdevs.c +1 -1
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

I would recommend -EOPNOTSUPP as this as nothing to do with unimplemented functions or hardware support. This is just unsupported due to the value being NULL and therefore the hardware support is not there. Just My Option,
Nick

Quoted 11 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 279

Quoted 3 lines
drivers/mtd/mtd_blkdevs.c +0 -0
 unlock:
 	mutex_unlock(&dev->lock);
 	blktrans_dev_put(dev);

Thanks,
Brian

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#3 lore raw
Quoted 7 lines · nick
Quoted 5 lines · Brian Norris

Hi Wenlin,

In the subject:

s/rerurn/return/

Thanks for pointing out this, I will modify it.

Quoted 28 lines
Quoted 23 lines · Wenlin Kang
Quoted 21 lines

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
  drivers/mtd/mtd_blkdevs.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  	if (!dev->mtd)
  		goto unlock;
 
Quoted 5 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 276

Quoted 2 lines
drivers/mtd/mtd_blkdevs.c +1 -1
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

Quoted 5 lines

I would recommend -EOPNOTSUPP as this as nothing to do with unimplemented functions or hardware support. This is just unsupported due to the value being NULL and therefore the hardware support is not there. Just My Option,
Nick

As you said, -EOPNOTSUPP might be better,thanks.

Hi Brian

I have remade the patch and attached it, would you please check it again? thanks.

Quoted 11 lines
Quoted 10 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 279

Quoted 3 lines
drivers/mtd/mtd_blkdevs.c +0 -0
  unlock:
  	mutex_unlock(&dev->lock);
  	blktrans_dev_put(dev);

Thanks,
Brian

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 2 lines
Thanks,
Wenlin Kang
Quoted 1 line

From d8fa6589438a6992ed13b91c0124ed6cd8114eff Mon Sep 17 00:00:00 2001

From: Wenlin Kang <[email protected]>
Date: Thu, 21 May 2015 14:11:58 +0800
Subject: [PATCH] mtd: blktrans: change blktrans_getgeo return value

Modify function blktrans_getgeo()'s return value to -EOPNOTSUPP when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +1 -1
index 2b0c5287..2012216 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 	if (!dev->mtd)
 		goto unlock;
 
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -EOPNOTSUPP;
 unlock:
 	mutex_unlock(&dev->lock);
 	blktrans_dev_put(dev);
Signature · 1 line
1.7.9.5
#4 lore raw
Quoted 28 lines · Wenlin Kang
Quoted 27 lines · nick
Quoted 26 lines · Brian Norris
Quoted 18 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 275

Quoted 4 lines
drivers/mtd/mtd_blkdevs.c +1 -1
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 	if (!dev->mtd)
 		goto unlock;
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

Quoted 7 lines
Quoted 5 lines

I would recommend -EOPNOTSUPP as this as nothing to do with unimplemented functions or hardware support. This is just unsupported due to the value being NULL and therefore the hardware support is not there. Just My Option,
Nick

As you said, -EOPNOTSUPP might be better,thanks.

Nick's opinion is irrelevant here:

https://lkml.org/lkml/2014/8/4/206

Quoted 2 lines

I have remade the patch and attached it, would you please check it again? thanks.

Please send patches inline (e.g., via git-send-email), not as attachments. But this is pretty trivial, and it's what I already tested.

So, applied to l2-mtd.git.

Brian

#5 lore raw
Quoted 39 lines · Brian Norris
Quoted 28 lines · Wenlin Kang
Quoted 27 lines · nick
Quoted 26 lines · Brian Norris
Quoted 18 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
  drivers/mtd/mtd_blkdevs.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 275

Quoted 4 lines
drivers/mtd/mtd_blkdevs.c +1 -1
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  	if (!dev->mtd)
  		goto unlock;
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

Quoted 6 lines
Quoted 5 lines

I would recommend -EOPNOTSUPP as this as nothing to do with unimplemented functions or hardware support. This is just unsupported due to the value being NULL and therefore the hardware support is not there. Just My Option,
Nick

As you said, -EOPNOTSUPP might be better,thanks.

Nick's opinion is irrelevant here:

https://lkml.org/lkml/2014/8/4/206

Quoted 9 lines
Quoted 2 lines

I have remade the patch and attached it, would you please check it again? thanks.

Please send patches inline (e.g., via git-send-email), not as attachments. But this is pretty trivial, and it's what I already tested.

So, applied to l2-mtd.git.

Brian

OK, thanks, I have resent the patch to you and list by git send-email, please check it.

Signature · 2 lines
Thanks,
Wenlin Kang
#6 lore raw
In reply to Brian Norris
Quoted 28 lines · Brian Norris

Hi Wenlin,

In the subject:

s/rerurn/return/

Quoted 21 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
      if (!dev->mtd)
              goto unlock;
 
Quoted 5 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 276

Quoted 2 lines
drivers/mtd/mtd_blkdevs.c +1 -1
-     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

I'd vote for -ENOTTY as this is what HDIO_GETGEIO returns if the function is not implemented and blktrans_getgeo() is only a wrapper around that.

See https://www.kernel.org/doc/Documentation/ioctl/hdio.txt
and block/ioctl.c.

Signature · 2 lines
Thanks,
//richard
#7 lore raw
Quoted 30 lines · Richard Weinberger
Quoted 22 lines · Brian Norris
Quoted 21 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
      if (!dev->mtd)
              goto unlock;
 
Quoted 5 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 276

Quoted 2 lines
drivers/mtd/mtd_blkdevs.c +1 -1
-     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

Quoted 3 lines

I'd vote for -ENOTTY as this is what HDIO_GETGEIO returns if the function is not implemented and blktrans_getgeo() is only a wrapper around that.

I suppose that makes more sense.

Quoted 1 line

See https://www.kernel.org/doc/Documentation/ioctl/hdio.txt

But this only mentions EINVAL...

Quoted 1 line

and block/ioctl.c.

Anyway, I pushed EOPNOTSUPP, but I can fix that up if we agree.

Brian

#8 lore raw
Quoted 34 lines · Brian Norris
Quoted 24 lines · Richard Weinberger
Quoted 22 lines · Brian Norris
Quoted 21 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
  drivers/mtd/mtd_blkdevs.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
       if (!dev->mtd)
               goto unlock;
 
Quoted 7 lines
Quoted 4 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 276

Quoted 2 lines
drivers/mtd/mtd_blkdevs.c +1 -1
-     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

I'd vote for -ENOTTY as this is what HDIO_GETGEIO returns if the function is not implemented and blktrans_getgeo() is only a wrapper around that.

I suppose that makes more sense.

Quoted 9 lines
Quoted 1 line

See https://www.kernel.org/doc/Documentation/ioctl/hdio.txt

But this only mentions EINVAL...

Quoted 1 line

and block/ioctl.c.

Anyway, I pushed EOPNOTSUPP, but I can fix that up if we agree.

Brian

Hi Brian

I just read block/compat_ioctl.c, in that I found the follow,

51 static int compat_hdio_getgeo(struct gendisk *disk, struct
block_device *bdev,
52 struct compat_hd_geometry __user *ugeo)
53 {
54 struct hd_geometry geo;
55 int ret;
56
57 if (!ugeo)
58 return -EINVAL;
59 if (!disk->fops->getgeo)
60 return -ENOTTY;

So, as Richard said, -ENOTTY should also be OK, and before last commit(048d87199566663e4edc4880df3703c04bcf41d9), it's -ENOTTY, so I think you can modify it, or let know whether I need to resent it again.

Signature · 2 lines
Thanks,
Wenlin Kang
#9 lore raw
In reply to Brian Norris

Am 21.05.2015 um 10:05 schrieb Brian Norris:

Quoted 35 lines · Richard Weinberger
Quoted 30 lines
Quoted 22 lines · Brian Norris
Quoted 21 lines · Wenlin Kang

Modify function blktrans_getgeo()'s return value to -ENXIO when dev->tr->getgeo == NULL.

We shouldn't make the return value to 0 when dev->tr->getgeo == NULL, because the function blktrans_getgeo() has an output value "hd_geometry" which is usually used by some application, if return 0, it will make some application get the wrong information.

---
 drivers/mtd/mtd_blkdevs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +0 -0
index 2b0c5287..f8bb16e 100644
@@ -273,7 +273,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
      if (!dev->mtd)
              goto unlock;
 
Quoted 5 lines

drivers/mtd/mtd_blkdevs.c static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) · line 276

Quoted 2 lines
drivers/mtd/mtd_blkdevs.c +1 -1
-     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : 0;
+     ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENXIO;

Good catch. I don't think ENXIO is correct in this case, though. Maybe -EOPNOTSUPP or -ENOSYS? The latter might make more sense I guess.

Quoted 3 lines

I'd vote for -ENOTTY as this is what HDIO_GETGEIO returns if the function is not implemented and blktrans_getgeo() is only a wrapper around that.

Quoted 5 lines

I suppose that makes more sense.

Quoted 1 line

See https://www.kernel.org/doc/Documentation/ioctl/hdio.txt

But this only mentions EINVAL...

Because ENOTTY is covered by ioctl().
If you request a non-existing function this error code will be returned.

Thanks,
//richard

#10 lore raw

PATCH 1/1 mtd: blktrans: use better error code for unimplemented ioctl()

In commit 50183936254b ("mtd: blktrans: change blktrans_getgeo return value") we fixed the problem that ioctl(HDIO_GETGEO) might return 0 (success) for mtdblock devices which did not implement the feature and would leave a blank (zero) result.

But now, let's get the error code right. Other code paths on this ioctl tend to use -ENOTTY to notify the user that the ioctl() is not supported for the device, so let's use that instead of -EOPNOTSUPP.

---
Against l2-mtd.git (linux-next)

 drivers/mtd/mtd_blkdevs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtd_blkdevs.c +1 -1
index c545c9325acf..41acc507b22e 100644
@@ -278,7 +278,7 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 	if (!dev->mtd)
 		goto unlock;
 
-	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -EOPNOTSUPP;
+	ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENOTTY;
 unlock:
 	mutex_unlock(&dev->lock);
 	blktrans_dev_put(dev);
Signature · 1 line
1.9.1
Applied
#11 lore raw

Re: [PATCH] mtd: blktrans: use better error code for unimplemented ioctl()

Quoted 5 lines · Brian Norris

In commit 50183936254b ("mtd: blktrans: change blktrans_getgeo return value") we fixed the problem that ioctl(HDIO_GETGEO) might return 0 (success) for mtdblock devices which did not implement the feature and would leave a blank (zero) result.

Quoted 8 lines

But now, let's get the error code right. Other code paths on this ioctl tend to use -ENOTTY to notify the user that the ioctl() is not supported for the device, so let's use that instead of -EOPNOTSUPP.

---
Against l2-mtd.git (linux-next)

Applied.