* cdev_init and struct file_operations
@ 2014-08-27 0:48 John de la Garza
2014-08-27 1:18 ` Valdis.Kletnieks at vt.edu
0 siblings, 1 reply; 3+ messages in thread
From: John de la Garza @ 2014-08-27 0:48 UTC (permalink / raw)
To: kernelnewbies
In the book Linux Device Drivers a struct cdev is setup like this:
static void scull_setup_cdev(struct scull_dev *dev, int index)
{
int err, devno = MKDEV(scull_major, scull_minor + index);
cdev_init(&dev->cdev, &scull_fops);
dev->cdev.owner = THIS_MODULE;
dev->cdev.ops = &scull_fops;
...
the code for cdev_init does this:
void cdev_init(struct cdev *cdev, const struct file_operations *fops)
{
memset(cdev, 0, sizeof *cdev);
INIT_LIST_HEAD(&cdev->list);
kobject_init(&cdev->kobj, &ktype_cdev_default);
cdev->ops = fops;
}
Why does the code from ldd3 set dev->cdev.ops = &scull_fops again?
Doesn't cdev_init already do that?
^ permalink raw reply [flat|nested] 3+ messages in thread
* cdev_init and struct file_operations
2014-08-27 0:48 cdev_init and struct file_operations John de la Garza
@ 2014-08-27 1:18 ` Valdis.Kletnieks at vt.edu
2014-08-27 14:35 ` John de la Garza
0 siblings, 1 reply; 3+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2014-08-27 1:18 UTC (permalink / raw)
To: kernelnewbies
On Tue, 26 Aug 2014 20:48:41 -0400, John de la Garza said:
> In the book Linux Device Drivers a struct cdev is setup like this:
>
> static void scull_setup_cdev(struct scull_dev *dev, int index)
> {
> int err, devno = MKDEV(scull_major, scull_minor + index);
>
> cdev_init(&dev->cdev, &scull_fops);
> dev->cdev.owner = THIS_MODULE;
> dev->cdev.ops = &scull_fops;
> ...
>
>
> the code for cdev_init does this:
> void cdev_init(struct cdev *cdev, const struct file_operations *fops)
> {
> memset(cdev, 0, sizeof *cdev);
> INIT_LIST_HEAD(&cdev->list);
> kobject_init(&cdev->kobj, &ktype_cdev_default);
> cdev->ops = fops;
> }
>
> Why does the code from ldd3 set dev->cdev.ops = &scull_fops again?
Probably because when ldd3 was written several years ago, cdev_init()
didn't set it, so it wasn't "again"....
> Doesn't cdev_init already do that?
It does *now*.
Remember that ldd3 was written about 6 million lines of code ago....
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140826/c1d339be/attachment.bin
^ permalink raw reply [flat|nested] 3+ messages in thread
* cdev_init and struct file_operations
2014-08-27 1:18 ` Valdis.Kletnieks at vt.edu
@ 2014-08-27 14:35 ` John de la Garza
0 siblings, 0 replies; 3+ messages in thread
From: John de la Garza @ 2014-08-27 14:35 UTC (permalink / raw)
To: kernelnewbies
On Tue, Aug 26, 2014 at 09:18:57PM -0400, Valdis.Kletnieks at vt.edu wrote:
> On Tue, 26 Aug 2014 20:48:41 -0400, John de la Garza said:
> > Why does the code from ldd3 set dev->cdev.ops = &scull_fops again?
>
> Probably because when ldd3 was written several years ago, cdev_init()
> didn't set it, so it wasn't "again"....
>
> > Doesn't cdev_init already do that?
>
> It does *now*.
>
> Remember that ldd3 was written about 6 million lines of code ago....
It did then, too (unless I'm missing something)
linux$ git branch
* (detached from v2.6.12)
master
from v2.6.12
void cdev_init(struct cdev *cdev, struct file_operations *fops)
{
memset(cdev, 0, sizeof *cdev);
INIT_LIST_HEAD(&cdev->list);
cdev->kobj.ktype = &ktype_cdev_default;
kobject_init(&cdev->kobj);
cdev->ops = fops;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-08-27 14:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-27 0:48 cdev_init and struct file_operations John de la Garza
2014-08-27 1:18 ` Valdis.Kletnieks at vt.edu
2014-08-27 14:35 ` John de la Garza
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.