Re: memfill

Matthew Wilcox
2017-02-07T19:03:59Z

On Tue, Feb 07, 2017 at 05:29:15PM +0000, David Howells wrote:
> Matthew Wilcox <willy@infradead.org> wrote:
>
> > You've misunderstood the purpose of memfill. memfill allows the caller
> > to specify a pattern which is not a single byte in size, eg memfill(addr,
> > 0x12345678, 64) would result in 0x12345678 being reproduced 16 times.
> > memset(addr, 0x12345678, 64) would result in 0x78 being reproduced
> > 64 times.
>
> Ah. Should it take a unsigned int rather than an unsigned long?

Well, our one user so far is looking to use an unsigned long (indeed,
wouldn't be able to use it if it took an unsigned int). If we have users
who want to memfill with an unsigned int, they can do something like:

void memfill_int(int *a, unsigned int v, size_t n)
{
if ((unsigned long)a & (sizeof(unsigned long) - 1)) {
*a++ = v;
n -= sizeof(unsigned int);
}
memfill((unsigned long *)a, v | ((v << 16) << 16), n);
if (n & (sizeof(unsigned long) - 1)
a[n / sizeof(v)] = v;
}

... but since we know of no users today, I don't want to put that in.