Skip to content

Commit a64a26e

Browse files
kosakitorvalds
authored andcommitted
cpumask: add cpumask_var_t documentation
cpumask_var_t has one notable difference from cpumask_t. Add the explanation. Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Thiago Farina <tfransosi@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 37e7b5f commit a64a26e

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎include/linux/cpumask.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,20 @@ static inline size_t cpumask_size(void)
617617
* ... use 'tmpmask' like a normal struct cpumask * ...
618618
*
619619
* free_cpumask_var(tmpmask);
620+
*
621+
*
622+
* However, one notable exception is there. alloc_cpumask_var() allocates
623+
* only nr_cpumask_bits bits (in the other hand, real cpumask_t always has
624+
* NR_CPUS bits). Therefore you don't have to dereference cpumask_var_t.
625+
*
626+
* cpumask_var_t tmpmask;
627+
* if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
628+
* return -ENOMEM;
629+
*
630+
* var = *tmpmask;
631+
*
632+
* This code makes NR_CPUS length memcopy and brings to a memory corruption.
633+
* cpumask_copy() provide safe copy functionality.
620634
*/
621635
#ifdef CONFIG_CPUMASK_OFFSTACK
622636
typedef struct cpumask *cpumask_var_t;

0 commit comments

Comments
 (0)