Re: [PATCH] bitmap: bitmap_parse takes a kernel buffer instead of a user buffer

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

 



> Joe wrote:
>> I guess I am a sucker for no-transient-buffer (bufferless?)
>
> Ah - that explains Joe's preference for putting the actual implementing
> code in the user version - it gets to pull in the user string one
> char at a time, avoiding a malloc'd buffer.

I tend to gree w/ Joe there.

I wonder if a hybrid would be ok, although I the pseudo impl
I propose below is kind of dirty, but some people might find it
justified enough:

static
__bitmap_parse(const void *_buf, size_t size, enum { KERNEL, USER } type,
               unsigned long *dst, int nbits)
{
        const char __user *ubuf = _buf;
        const char *buf = _buf;
        ...
        switch(type) {
        case USER:
                if (get_user(c, ubuf++))
                        return -EFAULT;
                break;
        case KERNEL:
                c = *buf++;
                break;
        default:
                BUG();
        ...
}


int bitmap_parse(const char *buf, unsigned int buflen,
                 unsigned long *maskp, int nmaskbits) {
    return __bitmap_parse(buf, buflen, KERNEL, maskp, nmaskbits);
}


int bitmap_parse_user(const char __user *buf, unsigned int buflen,
                      unsigned long *maskp, int nmaskbits) {
    return __bitmap_parse(buf, buflen, USER, maskp, nmaskbits);
}


[that or exposing __bitmap_user() as a extern / EXPORT and putting
 bitmap_parse{,_user}() as an inline in the header file]

It's nitty-gritty, but it removes the kmalloc from the equation...

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

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux