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]
Date:	Tue, 17 Apr 2007 10:11:44 -0700
From:	Zach Brown <zach.brown@...cle.com>
To:	Pavel Emelianov <xemul@...ru>
Cc:	Andrew Morton <akpm@...l.org>,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
	devel@...nvz.org, Kirill Korotaev <dev@...nvz.org>
Subject: Re: [PATCH] Introduce a handy list_first_entry macro

On Tue, Apr 17, 2007 at 03:18:56PM +0400, Pavel Emelianov wrote:
> There are many places in the kernel where the construction like
> 
>    foo = list_entry(head->next, struct foo_struct, list);
> 
> are used. 
> The code might look more descriptive and neat if using the macro
> 
>    list_first_entry(head, type, member) \
>              list_entry((head)->next, type, member)

> -			dquot = list_entry(dirty->next, struct dquot, dq_dirty);
> +			dquot = list_first_entry(dirty, struct dquot, dq_dirty);

I think it's more than just descriptive and neat.  A common sneaky bug
is to accidentally pass &list->next into list_entry() instead of
list->next. This is easy to do because one is used to typing &list in
list_empty(), etc.  So by following ->next in the macro we make the list
argument consistent in list_empty() and list_first_entry() and hopefully
reduce the risk of making that mistake.

I like it.

- z
-
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