From: jim.cromie@gmail.com (Jim Cromie)
To: kernelnewbies@lists.kernelnewbies.org
Subject: confused by char dev registration in a gpio driver
Date: Tue, 10 May 2011 11:26:59 -0600 [thread overview]
Message-ID: <BANLkTinSy2f0df_J_M6kb6ZM-Q5sRZ56aA@mail.gmail.com> (raw)
In-Reply-To: <20110503220600.GD14080@kroah.com>
On Tue, May 3, 2011 at 4:06 PM, Greg KH <greg@kroah.com> wrote:
> On Tue, May 03, 2011 at 05:21:11PM -0400, Robert P. J. Day wrote:
>>
>> ? i always thought both of those routines returned a simple zero to
>> indicate success. ?but look at those last few lines -- that return
>> code is assigned to "major", at which point it's *that* value that's
>> printed. ?wouldn't that just be zero all the time?
>>
>> ? and wouldn't it also print that this was a "dynamic" major even if
>> the user specified an explicit major number at load time? ?this second
>> point is more nitpicky, but what about that first point? ?wouldn't a
>> successful registration always print an allocated major number of
>> zero?
>
> I think you are right in that this code is wrong.
>
> The chardev stuff is a mess, I keep meaning for years to clean it up.
> Any proposals on a sane interface for this stuff is greatly appreciated.
>
> thanks,
>
> greg k-h
lets start with a list of grumbles about current api ?
1 - register_chrdev_region() VS alloc_chrdev_region()
ISTM that these could be combined into 1 function:
dev_t devid = MKNOD(major, minor);
register_chrdev_numbers(&devid, count, name);
ie make &devid an in/out parameter, where in-value
distinguishes which alloc/register behavior is desired.
this looks like a minor variation on alloc_chrdev_region()
one downside is need to include kdev_t.h
2 - EXPORTs in drivers/char/char_dev.c
original version (~2.6.12-rc2) had no __double-under exports,
now have:
EXPORT_SYMBOL(__register_chrdev);
EXPORT_SYMBOL(__unregister_chrdev);
__register_chrdev() looks to be a higher level function;
it 1st calls __register_chrdev_region()
then does cdev, kobject stuff too.
Or, why does it have __ in the name ?
__ typically means not for external use, but its exported.
is it because it does the cdev_add "too early"
ie before the caller is really ready to handle service requests ?
theres no caveat mentioned in the /** comments
Are the insanities you alluded to of a different sort,
ie internal suboptimalities ?
- struct inefficiencies ?
struct cdev *cdev; /* will die */
why die ? not needed, or available in another struct ?
- in char_dev.c, there is
static struct char_device_struct {
...} *chrdevs[CHRDEV_MAJOR_HASH_SIZE];
ie 255 elements.
This is == to legacy MAJOR number space,
and is scanned 255..0 to find unused MAJOR number.
It will need new const if MAJOR range increases,
but doesnt waste much memory currently
My 32bit laptop uses 48 devices, so ~200 major slots are
empty/wasted (800 bytes) and ISTM like over-engineering
to fix this preemptively if >255 is unneeded.
OTOH, a hash or rb-tree could use only whats needed.
is there a 'library' hash implementation in the kernel ?
thanks
next prev parent reply other threads:[~2011-05-10 17:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-03 21:21 confused by char dev registration in a gpio driver Robert P. J. Day
2011-05-03 22:06 ` Greg KH
2011-05-10 17:26 ` Jim Cromie [this message]
2011-05-10 18:40 ` Greg KH
2011-05-13 17:05 ` Jim Cromie
2011-05-13 19:05 ` Greg KH
2011-05-09 19:54 ` Jim Cromie
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BANLkTinSy2f0df_J_M6kb6ZM-Q5sRZ56aA@mail.gmail.com \
--to=jim.cromie@gmail.com \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).