tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kmem_alloc(0, f)



> Date: Mon, 31 Jul 2017 09:55:22 +0200
> From: Joerg Sonnenberger <joerg%bec.de@localhost>
> 
> On Sun, Jul 30, 2017 at 03:23:50PM -0000, Michael van Elst wrote:
> > So what does kmem_alloc(0, KM_SLEEP) do? fail where KM_SLEEP says it
> > cannot fail? I don't think that it can return a zero sized allocation
> > (i.e. ptr != NULL that cannot be dereferenced).
> 
> Just return a NULL pointer? That said, I do prefer just declaring it
> invalid...

On reflection, perhaps the danger of kmem_alloc(0, f) would be
rendered moot by having a kmem array API that gracefully handles empty
arrays.  The length of an array is usually much more variable and more
likely to be supplied by userland than the element size, so it's
probably much less of a problem to panic on zero size -- chances are
such bugs will be caught sooner, as long as we are careful to identify
which parameter is size and which parameter is element count.


Home | Main Index | Thread Index | Old Index