All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: nbd: fix sanity check for first_minor
@ 2021-10-09  5:35 Yan, Zheng
  2021-10-09  8:46 ` Pavel Skripkin
  0 siblings, 1 reply; 2+ messages in thread
From: Yan, Zheng @ 2021-10-09  5:35 UTC (permalink / raw)
  To: linux-block, linux-kernel; +Cc: axboe, paskripkin, Yan, Zheng

From: "Yan, Zheng" <yanzheng03@kuaishou.com>

Device's minor is a 20-bits number, max value is 0xfffff.

Fixes: b1a811633f ("block: nbd: add sanity check for first_minor").
Signed-off-by: "Yan, Zheng" <yanzheng03@kuaishou.com>
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 1183f7872b71..53cd038c96e9 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1753,7 +1753,7 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
 	 * byte in __device_add_disk().
 	 */
 	disk->first_minor = index << part_shift;
-	if (disk->first_minor > 0xff) {
+	if (disk->first_minor > MINORMASK) {
 		err = -EINVAL;
 		goto out_free_idr;
 	}
-- 
2.12.2


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

* Re: [PATCH] block: nbd: fix sanity check for first_minor
  2021-10-09  5:35 [PATCH] block: nbd: fix sanity check for first_minor Yan, Zheng
@ 2021-10-09  8:46 ` Pavel Skripkin
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Skripkin @ 2021-10-09  8:46 UTC (permalink / raw)
  To: Yan, Zheng, axboe, Christoph Hellwig
  Cc: Yan, Zheng, linux-block, linux-kernel

On 10/9/21 08:35, Yan, Zheng wrote:

+CC Christoph

> From: "Yan, Zheng" <yanzheng03@kuaishou.com>
> 
> Device's minor is a 20-bits number, max value is 0xfffff.
> 
> Fixes: b1a811633f ("block: nbd: add sanity check for first_minor").
> Signed-off-by: "Yan, Zheng" <yanzheng03@kuaishou.com>
> ---
>   drivers/block/nbd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index 1183f7872b71..53cd038c96e9 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -1753,7 +1753,7 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
>   	 * byte in __device_add_disk().
>   	 */
>   	disk->first_minor = index << part_shift;
> -	if (disk->first_minor > 0xff) {
> +	if (disk->first_minor > MINORMASK) {
>   		err = -EINVAL;
>   		goto out_free_idr;
>   	}
> 

I've looked into what confused me with 0xff and I found that uapi's 
kdev_t.h has following MINOR definition:

#define MINOR(dev)	((dev) & 0xff)


But kernel's kdev_t.h is really allows 20 bit minor number :)

Also, can you, please, fix up comment above this check, since it 
contains info about max minor 0xff and it can confuse readers.




With regards,
Pavel Skripkin

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

end of thread, other threads:[~2021-10-09  8:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-09  5:35 [PATCH] block: nbd: fix sanity check for first_minor Yan, Zheng
2021-10-09  8:46 ` Pavel Skripkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.