lkml.org 
[lkml]   [2020]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] kdev_t: mask mi with MINORMASK in MKDEV macro
From
Date
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.


\
 
 \ /
  Last update: 2020-01-11 05:51    [W:0.044 / U:10.568 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site