lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <200903251021.13811.knikanth@novell.com>
Date:	Wed, 25 Mar 2009 10:21:13 +0530
From:	Nikanth Karthikesan <knikanth@...ell.com>
To:	rusty@...tcorp.com.au
Cc:	nikanth@...il.com, linux-kernel@...r.kernel.org
Subject: Strange code in include/linux/cpumask.h

Hi Rusty

I do not understand this code.

/**
 * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
 * @bitmap: the bitmap
 *
 * There are a few places where cpumask_var_t isn't appropriate and
 * static cpumasks must be used (eg. very early boot), yet we don't
 * expose the definition of 'struct cpumask'.
 *
 * This does the conversion, and can be used as a constant initializer.
 */
#define to_cpumask(bitmap)                                              \
        ((struct cpumask *)(1 ? (bitmap)                                \
                            : (void *)sizeof(__check_is_bitmap(bitmap))))

static inline int __check_is_bitmap(const unsigned long *bitmap)
{
        return 1;
}

The conditional operator would always evaluates to true and return bitmap. So 
all it seems to does is
#define to_cpumansk(bitmap) (struct cpumask *)(bitmap)

Even If it would return (void *)sizeof(__check_is_bitmap(bitmap)), wouldn't it 
be always
(struct cpumask *) (sizeof(1))!?

Is this some magic for type safety?

Thanks
Nikanth
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ