TASK4: Implement sysfs attributes example#136
TASK4: Implement sysfs attributes example#136militant-daos wants to merge 2 commits intoKernel-GL-HRK:Victor.Krasnoshchokfrom
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 <ct3da21164@protonmail.ch>
ziod
left a comment
There was a problem hiding this comment.
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.
It is not necessary please avoid pre-increment
There was a problem hiding this comment.
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.
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 <ct3da21164@protonmail.ch>
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 ct3da21164@protonmail.ch