Skip to content

TASK4: Implement sysfs attributes example#136

Open
militant-daos wants to merge 2 commits intoKernel-GL-HRK:Victor.Krasnoshchokfrom
militant-daos:task04
Open

TASK4: Implement sysfs attributes example#136
militant-daos wants to merge 2 commits intoKernel-GL-HRK:Victor.Krasnoshchokfrom
militant-daos:task04

Conversation

@militant-daos
Copy link

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

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>
@militant-daos militant-daos requested a review from ziod December 20, 2021 10:38
Copy link

@ziod ziod left a 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.

kfree(curr_data_item->payload);
list_del(&curr_data_item->list_node);
kfree(curr_data_item);
++nodes_cnt;
Copy link

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

Copy link
Author

@militant-daos militant-daos Dec 29, 2021

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.

Copy link
Author

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 <ct3da21164@protonmail.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants