Re: [patch 1/7] slab: introduce kzfree()

From: Andrew Morton
Date: Mon Feb 23 2009 - 14:43:34 EST


On Mon, 23 Feb 2009 14:51:05 +0000 (GMT)
Hugh Dickins <hugh@xxxxxxxxxxx> wrote:

> On Tue, 24 Feb 2009, Nick Piggin wrote:
> >
> > Well, the buffer is only non-modified in the case of one of the
> > allocators (SLAB). All others overwrite some of the data region
> > with their own metadata.
> >
> > I think it is OK to use const, though. Because k(z)free has the
> > knowledge that the data will not be touched by the caller any
> > longer.
>
> Sorry, you're not adding anything new to the thread here.
>
> Yes, the caller is surrendering the buffer, so we can get
> away with calling the argument const; and Linus argues that's
> helpful in the case of kfree (to allow passing a const pointer
> without having to cast it).
>
> My contention is that kzfree(const void *ptr) is nonsensical
> because it says please zero this buffer without modifying it.

yup. The intent of kzfree() is explicitly, overtly, deliberately to
modify the passed memory before freeing it. Marking it const is dopey.

But the const marker is potentially useful to some caller. An arguably
misdesigned caller.

> But the change has gone in, I seem to be the only one still
> bothered by it, and I've conceded that the "z" might stand
> for zap rather than zero.

Yeah. But it's a very small bother.

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