public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: James Morris <jmorris@intercode.com.au>
Cc: Jeff Garzik <jgarzik@pobox.com>,
	Stephen Smalley <sds@epoch.ncsc.mil>,
	Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@osdl.org>,
	Alexander Viro <viro@parcelfarce.linux.theplanet.co.uk>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	Greg Kroah-Hartman <greg@kroah.com>,
	Chris Wright <chris@wirex.com>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Add SELinux module to 2.5.74-bk1
Date: Tue, 8 Jul 2003 12:33:04 +0100	[thread overview]
Message-ID: <20030708123304.A17486@infradead.org> (raw)
In-Reply-To: <Mutt.LNX.4.44.0307081942550.7740-100000@excalibur.intercode.com.au>; from jmorris@intercode.com.au on Tue, Jul 08, 2003 at 07:49:41PM +1000

On Tue, Jul 08, 2003 at 07:49:41PM +1000, James Morris wrote:
> +struct hashtab {
> +	struct hashtab_node **htable;	/* hash table */
> +	u32 size;			/* number of slots in hash table */
> +	u32 nel;			/* number of elements in hash table */
> +	u32 (*hash_value)(struct hashtab *h, void *key);
> +					/* hash function */
> +	int (*keycmp)(struct hashtab *h, void *key1, void *key2);
> +					/* key comparison function */

We use this callbacks in a bunch opf places, maybe add hash_value_t
and keycmp_t typedefs for them to avoid typing the prototypes all
the time?

> +/*
> +   Creates a new hash table with the specified characteristics.
> +
> +   Returns NULL if insufficent space is available or
> +   the new hash table otherwise.
> + */

Standrad kernel komments are either

/* foo */

or 

/*
 * Foo bar whiz blanbggvsgvb.
 */

> +struct hashtab *
> +hashtab_create(u32 (*hash_value)(struct hashtab *h, void *key),
> +               int (*keycmp)(struct hashtab *h, void *key1, void *key2),
> +               u32 size);

Documentation/CodingStyle says the type should be on the same line
as the function name.  I don't see that religious but it seems Linus
does according to a recent thread :)

> +/*
> +   Inserts the specified (key, datum) pair into the specified hash table.
> +
> +   Returns -ENOMEM on memory allocation error,
> +   -EEXIST if there is already an entry with the same key,
> +   -EINVAL for general errors or
> +   0 otherwise.
> + */

Maybe add kerneldoc comments in the source file instead of the
header comments?

> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/hashtab.h>
> +
> +struct hashtab *
> +hashtab_create(u32 (*hash_value)(struct hashtab *h, void *key),
> +               int (*keycmp)(struct hashtab *h, void *key1, void *key2),
> +               u32 size)
> +{
> +	u32 i;
> +	struct hashtab *p;
> +
> +	p = kmalloc(sizeof(*p), GFP_KERNEL);

Pass the GFP_ mask down to hashtab_create() maybe?

> +	p->htable = kmalloc(sizeof(p) * size, GFP_KERNEL);
> +	if (p->htable == NULL) {
> +		kfree(p);
> +		return NULL;
> +	}
> +
> +	for (i = 0; i < size; i++)
> +		p->htable[i] = NULL;

memset instead?

> +		memset(newnode, 0, sizeof(*newnode));
> +		newnode->key = key;
> +		newnode->datum = datum;
> +		if (prev) {
> +			newnode->next = prev->next;
> +			prev->next = newnode;

Use hlists?

> +config HASHTAB
> +	tristate "Generic hash table support"

Should this really be a user option or rather implicitly selected
by it's users?

>  CPPFLAGS	:= -D__KERNEL__ -Iinclude
>  CFLAGS 		:= $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
> -	  	   -fno-strict-aliasing -fno-common
> +	  	   -fno-strict-aliasing -fno-common -g

accident?


  parent reply	other threads:[~2003-07-08 11:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-03 17:44 [PATCH] Add SELinux module to 2.5.74-bk1 Stephen Smalley
2003-07-03 17:51 ` Jeff Garzik
2003-07-03 17:55   ` Chris Wright
2003-07-03 17:56   ` Greg KH
2003-07-03 18:05   ` Stephen Smalley
2003-07-04 15:41     ` Jeff Garzik
2003-07-08  9:49   ` James Morris
2003-07-08 10:09     ` Andrew Morton
2003-07-08 13:20       ` James Morris
2003-07-08 13:45       ` Alan Cox
2003-07-08 15:00         ` James Morris
2003-07-08 11:33     ` Christoph Hellwig [this message]
2003-07-08 13:50       ` James Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030708123304.A17486@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chris@wirex.com \
    --cc=greg@kroah.com \
    --cc=jgarzik@pobox.com \
    --cc=jmorris@intercode.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sds@epoch.ncsc.mil \
    --cc=torvalds@osdl.org \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox