LKML Archive on
help / color / mirror / Atom feed
From: "Robert P. J. Day" <>
To: Linux kernel mailing list <>
Subject: coding style and re-inventing the wheel way too many times
Date: Thu, 21 Dec 2006 06:48:45 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0612210614020.32046@localhost.localdomain> (raw)

  this little project of mine of submitting the occasional code
"cleanup" has turned out to be way more daunting than i originally
thought, given how many source files insist on constantly re-inventing
the wheel.  consider a couple useful macros defined in

  #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))

  first, there's the obvious inconsistency in upper versus lower case,
and why no corresponding "round down" macro?  in any event, a rough
first attempt to see what could be re-worded using DIV_ROUND_UP (with,
admittedly, lots of false positives):

  $ grep -Er " ?+ ?([^ -]+) ?- ?1\) ?/ ?\1" *

ouch.  the same could be said for

  #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))

where you can see possible replacements (again, just a hacky first
attempt with lots of bogus "hits" but still):

  $ grep -Er "\+.*(.*)\)* ?&~ ?\(*\1" *

and the list just goes on.

  one thing that might be useful would be to pull out the set of
generically useful macros into a separate header file, say
include/linux/cool_macros.h or something like that, and just put a
pointer to that header file from the CodingStyle file and strongly
encourage kernel programmers to read it and use it.

  the obvious set of macros for that file would be things related to:

  - rounding up and down
  - alignment and masking
  - array size
  - sizeof field
  - container_of
  - variants of min and max

and that sort of thing, and that header file could just be included
from kernel.h.

  in any event, even *i* am not going to go near this kind of cleanup,
but is there anything actually worth doing about it?  just curious.


             reply	other threads:[~2006-12-21 11:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-21 11:48 Robert P. J. Day [this message]
2007-01-23  1:11 ` [ot] " Oleg Verych

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0612210614020.32046@localhost.localdomain \ \ \
    --subject='Re: coding style and re-inventing the wheel way too many times' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).