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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <200707061046.37035.netdev@axxeo.de>
Date:	Fri, 6 Jul 2007 10:46:35 +0200
From:	Ingo Oeser <netdev@...eo.de>
To:	"Kok, Auke" <auke-jan.h.kok@...el.com>
Cc:	Jeff Garzik <jeff@...zik.org>,
	Arjan van de Ven <arjan@...ux.intel.com>,
	Ayyappan Veeraiyan <ayyappan.veeraiyan@...el.com>,
	netdev@...r.kernel.org, akpm@...ux-foundation.org
Subject: Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI	Express adapters...

Hi Auke,

Kok, Auke schrieb:
> tg3.c:
> 
> 	if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
> 	    (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))
> 
> is obviously _not_ easier to read than
> 
>          if (tp->tg3_flags.pcix_target_hwbug || tp->tg3_flags.ich_workaround)
> 

Yes, but what about:

static bool tg3_has_pcix_target_hwdebug(const struct tg3 *tp)
{
	return (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) != 0;
}

static bool tg3_has_ich_workaround(const struct tg3 *tp)
{
	return (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) != 0;
}

if (tg3_has_pcix_target_hwdebug(tp) || tg3_has_ich_workaround(tp)) {
	/* do foo */
}

That is just as nice as bitfields and makes that stuff more readable.
This is also a migration path while going from bitfields to flags incrementally.

If you find out that two of these tests are always done together you could even 
test two of them in one.

> I would say that this method is definately worse for readability. 

Yes, open coding this bit masking mess IS making code hardly readable!

> I would much rather then stick with 'bool' instead.

If you can afford the space, that is just as good. If you are undecided,
try the accessors. You can even write code, which generates them once. 

Maybe we could get such nice script for generating 
a set of bitmasks and accessors in the kernel :-)

Source would than be a struct definition with bitfields.

All points raised be the people here are actually valid and I consider
bitfields nice and clear for specification and example code, 
but avoid them while doing real coding.


Best Regards

Ingo Oeser
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ