Nish Aravamudan wrote:
On 7/6/06, Jim Cromie <jim.cromie@xxxxxxxxx> wrote:
I am comparing usage of struct cdev in 2 bits of kernel code:
- LDD3 way, which Ive imitated in scx200_gpio.c, is:
BTW, your post was disgustingly full of links to lxr. Just paste the
code. Each code block also appeared to be one long line.
Thanks,
Nish
Yes - it was awful - sorry about that.
Im also puzzled that it got there - I got a 'delivery failed' message that
has no explanation, and apparently isnt entirely true either.
so trying again - in plain text
LDD3 scullc demonstrates this ( as copied in scx200_gpio.c)
for (i = 0; i < num_pins; i++) {
struct cdev *cdev = &scx200_devices[i];
cdev_init(cdev, &scx200_gpio_fops);
cdev->owner = THIS_MODULE;
rc = cdev_add(cdev, MKDEV(major, i), 1);
/* tolerate 'minor' errors */
if (rc)
dev_err(&pdev->dev, "Error %d on minor %d", rc, i);
}
But in drivers/char/cs5535_gpio.c, we have:
cdev_init(&cs5535_gpio_cdev, &cs5535_gpio_fops);
cdev_add(&cs5535_gpio_cdev, dev_id, CS5535_GPIO_COUNT);
The latter is simpler, and more memory efficient, with only 1 struct cdev.
Both 'tolerate' the same errors from cdev_add(), the latter more tacitly.
Are there reasons to prefer the explicit cdev array[], and loop ?
what other situations would compel a cdev array ?
thanks,
-jimc
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/