-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TASK4: Implement sysfs attributes example #136
base: Victor.Krasnoshchok
Are you sure you want to change the base?
TASK4: Implement sysfs attributes example #136
Conversation
Implement a kernel module which contains a kobject instance containing a linked list and having a sysfs attribute named "list". Writing to it should create a new node holding the string received from user and attach it to the aforementioned list. Reading the attribute should print all the exisitng nodes in the list. Signed-off-by: Victor Krasnoshchok <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two minor comments which are confronted with general recommendations LKM.
Nice done.
04_basic_struct/sysfs_list.c
Outdated
kfree(curr_data_item->payload); | ||
list_del(&curr_data_item->list_node); | ||
kfree(curr_data_item); | ||
++nodes_cnt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not necessary please avoid pre-increment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but I didn't get what's wrong with pre-increment itself. As far as I remember, pre-incrementing works slightly faster (takes something like 1 or 2 instructions less than post-incrementing) by avoiding the need for a temporary storage for the value being incremented. Here I use nodes_cnt variable just to track how many nodes I had in the list before freeing; it wasn't required in the assignment, I just added this log line for myself for debugging purposes, since I failed to find any API which returns list nodes count by a single call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I've just checked https://www.kernel.org/doc/html/v4.10/process/coding-style.html - there seems to be no recommendations regarding using or not using prefix increment operation. The only mentions of "increment" word are these:
no space before the postfix increment & decrement unary operators:
++ --
no space after the prefix increment & decrement unary operators:
++ --
Fix coding style issues raised in CR Kernel-GL-HRK#136. Signed-off-by: Victor Krasnoshchok <[email protected]>
Implement a kernel module which contains a
kobject instance containing a linked list and
having a sysfs attribute named "list". Writing
to it should create a new node holding the
string received from user and attach it to the
aforementioned list. Reading the attribute
should print all the exisitng nodes in the list.
Signed-off-by: Victor Krasnoshchok [email protected]