* [KJ] is there a short form for "memset(blah, 0, len)"?
@ 2007-02-10 16:14 Robert P. J. Day
2007-02-10 17:01 ` Bernd Petrovitsch
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Robert P. J. Day @ 2007-02-10 16:14 UTC (permalink / raw)
To: kernel-janitors
i doubt anything will ever come of this but, given the number of
calls to "memset(addr, 0, len)", did anyone ever consider defining a
macro short form, say:
clearmem(addr, len)
zeromem(addr, len)
or something like that? just curious.
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [KJ] is there a short form for "memset(blah, 0, len)"?
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
@ 2007-02-10 17:01 ` Bernd Petrovitsch
2007-02-10 18:25 ` Robert P. J. Day
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Bernd Petrovitsch @ 2007-02-10 17:01 UTC (permalink / raw)
To: kernel-janitors
On Sat, 2007-02-10 at 11:14 -0500, Robert P. J. Day wrote:
> i doubt anything will ever come of this but, given the number of
> calls to "memset(addr, 0, len)", did anyone ever consider defining a
> macro short form, say:
>
> clearmem(addr, len)
> zeromem(addr, len)
*BSD had "bzero()".
> or something like that? just curious.
Did you ever read the man page of "bzero()"?
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [KJ] is there a short form for "memset(blah, 0, len)"?
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
2007-02-10 17:01 ` Bernd Petrovitsch
@ 2007-02-10 18:25 ` Robert P. J. Day
2007-02-10 18:55 ` Bernd Petrovitsch
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Robert P. J. Day @ 2007-02-10 18:25 UTC (permalink / raw)
To: kernel-janitors
On Sat, 10 Feb 2007, Bernd Petrovitsch wrote:
> On Sat, 2007-02-10 at 11:14 -0500, Robert P. J. Day wrote:
> > i doubt anything will ever come of this but, given the number of
> > calls to "memset(addr, 0, len)", did anyone ever consider defining a
> > macro short form, say:
> >
> > clearmem(addr, len)
> > zeromem(addr, len)
>
> *BSD had "bzero()".
>
> > or something like that? just curious.
>
> Did you ever read the man page of "bzero()"?
sure, but that's a *userspace* routine. AFAIK, there is no such
routine in the linux kernel. is there a reason there isn't? wouldn't
it be kind of useful?
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [KJ] is there a short form for "memset(blah, 0, len)"?
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
2007-02-10 17:01 ` Bernd Petrovitsch
2007-02-10 18:25 ` Robert P. J. Day
@ 2007-02-10 18:55 ` Bernd Petrovitsch
2007-02-10 19:12 ` Richard Knutsson
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Bernd Petrovitsch @ 2007-02-10 18:55 UTC (permalink / raw)
To: kernel-janitors
On Sat, 2007-02-10 at 13:25 -0500, Robert P. J. Day wrote:
> On Sat, 10 Feb 2007, Bernd Petrovitsch wrote:
>
> > On Sat, 2007-02-10 at 11:14 -0500, Robert P. J. Day wrote:
> > > i doubt anything will ever come of this but, given the number of
> > > calls to "memset(addr, 0, len)", did anyone ever consider defining a
> > > macro short form, say:
> > >
> > > clearmem(addr, len)
> > > zeromem(addr, len)
> >
> > *BSD had "bzero()".
> >
> > > or something like that? just curious.
> >
> > Did you ever read the man page of "bzero()"?
>
> sure, but that's a *userspace* routine. AFAIK, there is no such
Yes, of course. I mentioned it because there is/was already a function
with the above semantics and signature. So why invent another name?
> routine in the linux kernel. is there a reason there isn't? wouldn't
No, because bzero() is - according to the man page - deprecated.
> it be kind of useful?
I don't think so. But who knows what maintainers and others higher in
the food chain think .....
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [KJ] is there a short form for "memset(blah, 0, len)"?
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
` (2 preceding siblings ...)
2007-02-10 18:55 ` Bernd Petrovitsch
@ 2007-02-10 19:12 ` Richard Knutsson
2007-02-10 19:56 ` Robert P. J. Day
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Richard Knutsson @ 2007-02-10 19:12 UTC (permalink / raw)
To: kernel-janitors
Robert P. J. Day wrote:
> On Sat, 10 Feb 2007, Bernd Petrovitsch wrote:
>
>
>> On Sat, 2007-02-10 at 11:14 -0500, Robert P. J. Day wrote:
>>
>>> i doubt anything will ever come of this but, given the number of
>>> calls to "memset(addr, 0, len)", did anyone ever consider defining a
>>> macro short form, say:
>>>
>>> clearmem(addr, len)
>>> zeromem(addr, len)
>>>
>> *BSD had "bzero()".
>>
>>
>>> or something like that? just curious.
>>>
>> Did you ever read the man page of "bzero()"?
>>
>
> sure, but that's a *userspace* routine. AFAIK, there is no such
> routine in the linux kernel. is there a reason there isn't? wouldn't
> it be kind of useful?
>
> grep -Enr "define +.*memset *\(.*0" *
arch/alpha/boot/misc.c:25:#define memzero(s,n) memset ((s),0,(n))
arch/cris/arch-v10/boot/compressed/misc.c:38:#define memzero(s, n) memset ((s), 0, (n))
arch/cris/arch-v32/boot/compressed/misc.c:40:#define memzero(s, n) memset ((s), 0, (n))
arch/i386/boot/compressed/misc.c:110:#define memzero(s, n) memset ((s), 0, (n))
arch/m32r/boot/compressed/misc.c:26:#define memzero(s, n) memset ((s), 0, (n))
arch/sh/boot/compressed/misc.c:30:#define memzero(s, n) memset ((s), 0, (n))
arch/sh64/boot/compressed/misc.c:28:#define memzero(s, n) memset ((s), 0, (n))
...
So it seems memzero() is a candidate, don't you think?
Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [KJ] is there a short form for "memset(blah, 0, len)"?
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
` (3 preceding siblings ...)
2007-02-10 19:12 ` Richard Knutsson
@ 2007-02-10 19:56 ` Robert P. J. Day
2007-02-10 20:03 ` Robert P. J. Day
2007-02-10 20:11 ` Robert P. J. Day
6 siblings, 0 replies; 8+ messages in thread
From: Robert P. J. Day @ 2007-02-10 19:56 UTC (permalink / raw)
To: kernel-janitors
On Sat, 10 Feb 2007, Bernd Petrovitsch wrote:
> On Sat, 2007-02-10 at 13:25 -0500, Robert P. J. Day wrote:
> > On Sat, 10 Feb 2007, Bernd Petrovitsch wrote:
> >
> > > On Sat, 2007-02-10 at 11:14 -0500, Robert P. J. Day wrote:
> > > > i doubt anything will ever come of this but, given the number of
> > > > calls to "memset(addr, 0, len)", did anyone ever consider defining a
> > > > macro short form, say:
> > > >
> > > > clearmem(addr, len)
> > > > zeromem(addr, len)
> > >
> > > *BSD had "bzero()".
> > >
> > > > or something like that? just curious.
> > >
> > > Did you ever read the man page of "bzero()"?
> >
> > sure, but that's a *userspace* routine. AFAIK, there is no such
>
> Yes, of course. I mentioned it because there is/was already a function
> with the above semantics and signature. So why invent another name?
oh, sorry, i misunderstood. i thought you were saying that there
already *was* a bzero() in kernel space. my mistake.
> > routine in the linux kernel. is there a reason there isn't?
> > wouldn't
>
> No, because bzero() is - according to the man page - deprecated.
ah, yes, i just checked up on that. this wasn't a big deal, it just
struck me that there are a *ton* of calls to memset() to do nothing
more than zero a chunk of memory, and it would seem simpler to define
a macro as a wrapper. but i'm not going to make a big deal out of it.
rday
p.s. in general, whenever i see the same construct being used more
than a dozen times, i start thinking of a way to make it shorter.
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [KJ] is there a short form for "memset(blah, 0, len)"?
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
` (4 preceding siblings ...)
2007-02-10 19:56 ` Robert P. J. Day
@ 2007-02-10 20:03 ` Robert P. J. Day
2007-02-10 20:11 ` Robert P. J. Day
6 siblings, 0 replies; 8+ messages in thread
From: Robert P. J. Day @ 2007-02-10 20:03 UTC (permalink / raw)
To: kernel-janitors
On Sat, 10 Feb 2007, Richard Knutsson wrote:
> Robert P. J. Day wrote:
> > On Sat, 10 Feb 2007, Bernd Petrovitsch wrote:
> >
> >
> > > On Sat, 2007-02-10 at 11:14 -0500, Robert P. J. Day wrote:
> > >
> > > > i doubt anything will ever come of this but, given the number of
> > > > calls to "memset(addr, 0, len)", did anyone ever consider defining a
> > > > macro short form, say:
> > > >
> > > > clearmem(addr, len)
> > > > zeromem(addr, len)
> > > >
> > > *BSD had "bzero()".
> > >
> > >
> > > > or something like that? just curious.
> > > >
> > > Did you ever read the man page of "bzero()"?
> > >
> >
> > sure, but that's a *userspace* routine. AFAIK, there is no such
> > routine in the linux kernel. is there a reason there isn't? wouldn't
> > it be kind of useful?
> > grep -Enr "define +.*memset *\(.*0" *
> arch/alpha/boot/misc.c:25:#define memzero(s,n) memset ((s),0,(n))
> arch/cris/arch-v10/boot/compressed/misc.c:38:#define memzero(s, n) memset
> ((s), 0, (n))
> arch/cris/arch-v32/boot/compressed/misc.c:40:#define memzero(s, n) memset
> ((s), 0, (n))
> arch/i386/boot/compressed/misc.c:110:#define memzero(s, n) memset ((s), 0,
> (n))
> arch/m32r/boot/compressed/misc.c:26:#define memzero(s, n) memset ((s), 0,
> (n))
> arch/sh/boot/compressed/misc.c:30:#define memzero(s, n) memset ((s), 0,
> (n))
> arch/sh64/boot/compressed/misc.c:28:#define memzero(s, n) memset ((s), 0,
> (n))
> ...
>
> So it seems memzero() is a candidate, don't you think?
it would seem so, but you should really have let that list go on a bit
longer. all of the above examples are in *userspace*, so adding that
definition to a kernel header file wouldn't help, right? if you let
that command run a bit longer, then you find a few kernel space
examples (some of them *very* badly named):
...
drivers/block/floppy.c:317:#define CLEARSTRUCT(x) memset((x), 0, sizeof(*(x)))
drivers/video/sun3fb.c:67:#define mymemset(x,y) memset(x,0,y)
...
in any event, i think defining memzero() that way is the obvious
enhancement. is there any obvious reason this can't be done?
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [KJ] is there a short form for "memset(blah, 0, len)"?
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
` (5 preceding siblings ...)
2007-02-10 20:03 ` Robert P. J. Day
@ 2007-02-10 20:11 ` Robert P. J. Day
6 siblings, 0 replies; 8+ messages in thread
From: Robert P. J. Day @ 2007-02-10 20:11 UTC (permalink / raw)
To: kernel-janitors
as a short followup, if you see how many memset() calls are used to
just clear memory:
$ grep -Er "memset ?\(.*,0 ?,.*\)" * | less
you can see that adding a memzero() call would definitely be useful.
in addition, there are another ton of calls of the form:
memset(&fpr_final,0, sizeof(fpr_final));
perhaps another simple macro wrapper of the form
#define structzero(s) memset(&s, 0, sizeof(s))
thoughts?
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-02-10 20:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-10 16:14 [KJ] is there a short form for "memset(blah, 0, len)"? Robert P. J. Day
2007-02-10 17:01 ` Bernd Petrovitsch
2007-02-10 18:25 ` Robert P. J. Day
2007-02-10 18:55 ` Bernd Petrovitsch
2007-02-10 19:12 ` Richard Knutsson
2007-02-10 19:56 ` Robert P. J. Day
2007-02-10 20:03 ` Robert P. J. Day
2007-02-10 20:11 ` Robert P. J. Day
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.