LDD3 | Notes of Linux Device Driver , 3rd edition

 by   testrain C Version: Current License: No License

kandi X-RAY | LDD3 Summary

kandi X-RAY | LDD3 Summary

LDD3 is a C library. LDD3 has no bugs, it has no vulnerabilities and it has low support. You can download it from GitHub.

Notes of Linux Device Driver, 3rd edition.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              LDD3 has a low active ecosystem.
              It has 5 star(s) with 10 fork(s). There are 1 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              LDD3 has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of LDD3 is current.

            kandi-Quality Quality

              LDD3 has no bugs reported.

            kandi-Security Security

              LDD3 has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              LDD3 does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              LDD3 releases are not available. You will need to build from source code and install.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of LDD3
            Get all kandi verified functions for this library.

            LDD3 Key Features

            No Key Features are available at this moment for LDD3.

            LDD3 Examples and Code Snippets

            No Code Snippets are available at this moment for LDD3.

            Community Discussions

            QUESTION

            How many reference counts does kobject_create_and_add create?
            Asked 2021-Feb-11 at 07:02

            According to LDD3, both kobject_init and kobject_add increase the reference count. So kobject_create_and_add should create an object with 2 references. Right?

            But in linux/sample/kobject/kobject-example.c, the module kobject_create_and_add an object, but only put it once, when exiting. It implies there's only one reference count. What's wrong?

            ...

            ANSWER

            Answered 2021-Feb-11 at 07:02

            So kobject_create_and_add should create an object with 2 references. Right?

            Not really. It creates an object (which should set its reference counter to 1) and then adds it to the parent object (which should increment the parent object's reference counter). Two different objects are involved, and two different reference counters are handled.

            Calling kobject_put() decrements the reference counter of the object and, when the new reference counter value tests accordingly, calls kobject_release() on the object internally. The latter invokes kobject_cleanup(), which, in turn, invokes kobject_put() on the parent object thus taking care of its reference counter, too.

            Source https://stackoverflow.com/questions/66149001

            QUESTION

            copy_to_user() keeps printing message infinitely
            Asked 2020-Dec-01 at 14:51

            I am learning the "Linux device drivers". I created a character device named char_device. When I read the data from the device it keeps printing the message to terminal infinitely crashing the machine.

            Source code of the read operation in the driver:

            ...

            ANSWER

            Answered 2020-Nov-30 at 14:43

            Programs such as cat will read the current input file until it encounters an end-of-file condition or a read error. By convention, a read() return value of 0 indicates an end-of-file condition when a non-zero amount of data is requested. A return value of -1 indicates a read error with the error number in the errno variable.

            At the kernel level, the read file operation handler should return 0 to indicate an end-of-file condition (but may also do so when the requested amount in 0), and should return a negated errno value to indicate a read error.

            OP's current read file operation handler, my_read, copies the contents of a string literal, "Hello from the kernel world!\n", to the user memory buffer, limited to the requested read amount or the length of the string, whichever is smallest. It never returns an end-of-file condition. The only time it returns 0 is when the requested amount is 0, but that is not a valid end-of-file condition.

            One thing that my_read could do is to use the passed in file position information to determine where to start reading, and to limit the amount to be copied. It should update the position accordingly. Then it can return 0 when to indicate end-of-file when there is no more data to be copied. Here is a possible implementation:

            Source https://stackoverflow.com/questions/65074491

            QUESTION

            Questions on scull_follow function in linux device drivers 3rd edition
            Asked 2020-Jul-11 at 07:38

            I never found the definition for scull_follow in the book, so I'm trying to understand it based off a github repo(https://github.com/martinezjavier/ldd3). Here is the code I am trying to understand:

            ...

            ANSWER

            Answered 2020-Jul-11 at 07:38

            QUESTION

            Can we write to jiffies variable
            Asked 2020-Feb-04 at 15:30

            From http://www.makelinux.net/ldd3/chp-7-sect-1.shtml

            Needless to say, both jiffies and jiffies_64 must be considered read-only

            I wrote a program to verify and it successfully updates the jiffies value.

            ...

            ANSWER

            Answered 2020-Feb-04 at 13:53

            What you are reading is merely a warning. It is an unwritten contract between you (kernel module developer) and the kernel. You shouldn't modify the value of jiffies since it is not up to you to do so, and is updated by the kernel according to a set of complicated rules that you should not worry about. The jiffies value is used internally by the scheduler, so bad things can happen modifying it. Chances are that the variable you see in your module is only a thread-local copy of the real one, so modifying could have no effect. In any case, you shouldn't do it. It is only provided to you as additional information that your module might need to know to implement some logic.

            Of course, since you are working in C, there is no concept of "permissions" for variables. Anything that is mapped in a readable and writable region of memory can be modified, you could even modify data in read-only memory by changing the permissions first. You can do all sorts of bad stuff if you want. There are a lot of things you're not supposed to alter, even if you have the ability to do so.

            Source https://stackoverflow.com/questions/60058639

            QUESTION

            Why need IRQ-safe version of seqlock for read access?
            Asked 2019-Dec-04 at 17:22

            When write accessing a shared resource protected by a seqlock, a writer must obtain an exclusive lock before entering the critical section. So, as with spinlocks, it makes sense for write accessing with seqlock to have common variants like *_irqsave and *_bh. But LDD3 (on page 128) says:

            If your seqlock might be accessed from an interrupt handler, you should use the IRQ-safe versions instead:

            ...

            ANSWER

            Answered 2019-Dec-04 at 17:22

            Since 3.9 kernel there are no such functions.
            In general you're right: seqlock readers should be able to work with inconsistent data.
            So if we read the counter, then some interrupt arrives, then we make sure that data is in inconsistent state - just do re-reading.

            P.S. LDD3 - this tutorial is quite good, but not so relevant.

            In such cases you can do some git investigation. Here it that commit.

            Source https://stackoverflow.com/questions/59150014

            QUESTION

            Problem running "Hello World" linux module
            Asked 2018-Dec-10 at 10:59

            I'm trying to compile and run a "Hello World" module from the book "Linux Device Drivers" the program ~/ldd3/hello.c I'm trying to compile is:

            ...

            ANSWER

            Answered 2018-Dec-10 at 10:59

            In order to see kernel messages, you can use dmesg. Alternatively, you can see the syslog tail var/log/syslog.

            Source https://stackoverflow.com/questions/53704179

            QUESTION

            What is the difference between kobject, device_create and my code?
            Asked 2018-Jun-04 at 12:52

            I am currently reading a book entitled "Linux device drivers" from O'Reilly.

            Thing is that this book imo isn't really a guide on how to write drivers but it instead explains all the apis and their prinicples. So I tried writing a small driver -which doesn't do anything interesting -with what I read so far. Thing is:

            • I don't know which file I can execute cat on or echo to in order to invoke my callback functions

            • it looks nothing like all the other code snippets I found online

            The different pieces of code:

            I can see that my code successfully created a bunch of files under /sys/kernel. Now what is the difference in endgoal between my code and the two other snippets? Should I use device_create/kobjects or maybe none of those? The book I am reading doesn't mention anywhere the functions used by the 2 other pieces of code. So not sure which way I am supposed to follow...

            Thanks_xe

            ...

            ANSWER

            Answered 2018-May-29 at 02:07

            device_create() creates a device and registers it with sysfs, and create necessary kobjects.

            To create necessary kobjects, kobject-related functions(kobject_init(), kobject_add(), ...) are called in device_create().

            If you need to create a device, you should call one of device creation functions like device_create().

            Source https://stackoverflow.com/questions/50573746

            QUESTION

            How does linux pick connect the mouse on my display to a driver in /dev/input/mouse*?
            Asked 2018-Apr-23 at 17:11

            I am currently reading LDD3, and have some question about how Linux actually proesses input from a device in /dev/input/mouse*?

            When I cat /dev/input/mouse2 (for my logitech mouse) I see input when I move.

            How does the kernel take the bytes from this char device and make it display the mouse on my screen? I have also read about the Linux input subsystem kernel API, which confuses me because why would I need to write to an inode I create at /dev/input/mouse* when I can just send information directly through this API?

            ...

            ANSWER

            Answered 2018-Apr-23 at 17:11

            The Linux kernel doesn't process /dev/input/mouse*

            The kernel is what provides /dev/input/mouse*

            Userspace programs like X.org can then read this device and show a cursor moving accordingly.

            Source https://stackoverflow.com/questions/49986139

            QUESTION

            Kernel block device
            Asked 2018-Apr-12 at 16:08

            I'm currently trying to implement a (not that ?) simple kernel block device driver.

            I inspired mainly from the book Linux Device Drivers, 3rd Edition which is not totally up-to-date anymore as it was published in 2005.

            Anyway the logic is still there and I learnt a lot from it. However examples are not really effective as many things have changed since 2005.

            I found a github repository where examples should be updated to work on recent kernels but I think there is still some things to update as I can't adapt examples to make it work on kernel 4.9.0

            Here is how my module is made:

            At initialization :

            • Register the module as block device with register_blkdev
            • Allocate the device data buffer
            • Initialize spinlock
            • Initialize request queue
            • Configure request queue
            • Allocate gendisk structure
            • Fill gendisk structure
            • Create the disk with add_disk

            Then I implemented a function to handle request events from request queue and treat read and write events on the block device.

            Here is the function : (It's highly inspired from LLD-3rd with some modifications to match current kernel functions)

            ...

            ANSWER

            Answered 2018-Apr-12 at 16:08

            The message from the commit containing the culprit change, authored by Ming Lei:

            block: remove struct request buffer member

            This was used in the olden days, back when onions were proper yellow. Basically it mapped to the current buffer to be transferred. With highmem being added more than a decade ago, most drivers map pages out of a bio, and rq->buffer isn't pointing at anything valid.

            Convert old style drivers to just use bio_data().

            There are some good resources for reading about BIO, such as this post on lwn. A relevant snippet:

            char *bio_data(struct bio *bio)

              Returns the kernel virtual address for the data buffer.

            So it looks like you will have more success using bio_data(rq->bio) in place of rq->buffer.

            Edit by author:
            Also found this link which is in two parts and presents in first part the bio layer and in second part the request layer.

            Source https://stackoverflow.com/questions/49781081

            QUESTION

            Getting information from the device tree and requesting irq
            Asked 2018-Feb-07 at 14:50
            Context

            In the device tree I am using, in one of its node, the filed interrupts is:

            ...

            ANSWER

            Answered 2018-Feb-07 at 14:50

            What are exactly the <0x0 0x1d 0x4> numbers? I know that, in according to elinux.org, (interrupts = <0x0 0x1d 0x4>;)

            Firstly you need to look at the interrupt-parent of the device node, this parent will #interrupt-cells property which specifies number of bits needed to encode a interrupt source, so from your entry interrupts = <0x0 0x1d 0x4>; means the following:

            Source https://stackoverflow.com/questions/48665718

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install LDD3

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/testrain/LDD3.git

          • CLI

            gh repo clone testrain/LDD3

          • sshUrl

            git@github.com:testrain/LDD3.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link