linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kdev_t: mask mi with MINORMASK in MKDEV macro
@ 2020-01-10  6:37 Zhiqiang Liu
  2020-01-11  4:50 ` Bart Van Assche
  0 siblings, 1 reply; 3+ messages in thread
From: Zhiqiang Liu @ 2020-01-10  6:37 UTC (permalink / raw)
  To: linux-kernel, linux-block, dhowells, akpm, torvalds
  Cc: bywxiaobai, Mingfangsen, Guiyao, zhangsaisai, renxudong


In MKDEV macro, if mi is larger than MINORMASK, the major will be
affected by mi. For example, set dev = MKDEV(2, (1U << MINORBITS)),
then MAJOR(dev) will be equal to 3, incorrectly.

Here, we mask mi with MINORMASK in MKDEV macro.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
 include/linux/kdev_t.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/kdev_t.h b/include/linux/kdev_t.h
index 85b5151911cf..40a9423720b2 100644
--- a/include/linux/kdev_t.h
+++ b/include/linux/kdev_t.h
@@ -9,7 +9,7 @@

 #define MAJOR(dev)	((unsigned int) ((dev) >> MINORBITS))
 #define MINOR(dev)	((unsigned int) ((dev) & MINORMASK))
-#define MKDEV(ma,mi)	(((ma) << MINORBITS) | (mi))
+#define MKDEV(ma, mi)	(((ma) << MINORBITS) | ((mi) & MINORMASK))

 #define print_dev_t(buffer, dev)					\
 	sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
-- 
2.19.1


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

* Re: [PATCH] kdev_t: mask mi with MINORMASK in MKDEV macro
  2020-01-10  6:37 [PATCH] kdev_t: mask mi with MINORMASK in MKDEV macro Zhiqiang Liu
@ 2020-01-11  4:50 ` Bart Van Assche
  2020-01-12  8:21   ` Zhiqiang Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Van Assche @ 2020-01-11  4:50 UTC (permalink / raw)
  To: Zhiqiang Liu, linux-kernel, linux-block, dhowells, akpm, torvalds
  Cc: bywxiaobai, Mingfangsen, Guiyao, zhangsaisai, renxudong

On 2020-01-09 22:37, Zhiqiang Liu wrote:
> 
> In MKDEV macro, if mi is larger than MINORMASK, the major will be
> affected by mi. For example, set dev = MKDEV(2, (1U << MINORBITS)),
> then MAJOR(dev) will be equal to 3, incorrectly.
> 
> Here, we mask mi with MINORMASK in MKDEV macro.
> 
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> ---
>  include/linux/kdev_t.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/kdev_t.h b/include/linux/kdev_t.h
> index 85b5151911cf..40a9423720b2 100644
> --- a/include/linux/kdev_t.h
> +++ b/include/linux/kdev_t.h
> @@ -9,7 +9,7 @@
> 
>  #define MAJOR(dev)	((unsigned int) ((dev) >> MINORBITS))
>  #define MINOR(dev)	((unsigned int) ((dev) & MINORMASK))
> -#define MKDEV(ma,mi)	(((ma) << MINORBITS) | (mi))
> +#define MKDEV(ma, mi)	(((ma) << MINORBITS) | ((mi) & MINORMASK))
> 
>  #define print_dev_t(buffer, dev)					\
>  	sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))

Shouldn't the users of MKDEV() be fixed instead of changing the MKDEV()
definition?

Thanks,

Bart.



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

* Re: [PATCH] kdev_t: mask mi with MINORMASK in MKDEV macro
  2020-01-11  4:50 ` Bart Van Assche
@ 2020-01-12  8:21   ` Zhiqiang Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Zhiqiang Liu @ 2020-01-12  8:21 UTC (permalink / raw)
  To: Bart Van Assche, linux-kernel, linux-block, dhowells, akpm, torvalds
  Cc: bywxiaobai, Mingfangsen, Guiyao, zhangsaisai, renxudong

On 2020/1/11 12:50, Bart Van Assche wrote:
> On 2020-01-09 22:37, Zhiqiang Liu wrote:
>>
>> In MKDEV macro, if mi is larger than MINORMASK, the major will be
>> affected by mi. For example, set dev = MKDEV(2, (1U << MINORBITS)),
>> then MAJOR(dev) will be equal to 3, incorrectly.
>>
>> Here, we mask mi with MINORMASK in MKDEV macro.
>>
>> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>> ---
>>  include/linux/kdev_t.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/kdev_t.h b/include/linux/kdev_t.h
>> index 85b5151911cf..40a9423720b2 100644
>> --- a/include/linux/kdev_t.h
>> +++ b/include/linux/kdev_t.h
>> @@ -9,7 +9,7 @@
>>
>>  #define MAJOR(dev)	((unsigned int) ((dev) >> MINORBITS))
>>  #define MINOR(dev)	((unsigned int) ((dev) & MINORMASK))
>> -#define MKDEV(ma,mi)	(((ma) << MINORBITS) | (mi))
>> +#define MKDEV(ma, mi)	(((ma) << MINORBITS) | ((mi) & MINORMASK))
>>
>>  #define print_dev_t(buffer, dev)					\
>>  	sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
> 
> Shouldn't the users of MKDEV() be fixed instead of changing the MKDEV()
> definition?
> 
> Thanks,
> 
> Bart.
Thanks for your reply.
I think that your opinion is much better. Users of MKDEV() should
make sure that the mi is not larger than MINORMASK. If we mask mi with
MINORMASK in MKDEV(), ma will be not affected by mi. But, the result
may be not the expected value of users.

So, please ignore the patch.


> 
> 
> 


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

end of thread, other threads:[~2020-01-12  8:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10  6:37 [PATCH] kdev_t: mask mi with MINORMASK in MKDEV macro Zhiqiang Liu
2020-01-11  4:50 ` Bart Van Assche
2020-01-12  8:21   ` Zhiqiang Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).