-
Notifications
You must be signed in to change notification settings - Fork 28
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
04 task struct #126
base: Maryna.Malakhova
Are you sure you want to change the base?
04 task struct #126
Conversation
8557de9
to
8460748
Compare
04_basic_struct/Makefile
Outdated
@@ -0,0 +1,7 @@ | |||
TARGET = bstructmodule |
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.
The task says Implement object with name “hello”
04_basic_struct/Makefile
Outdated
@@ -0,0 +1,7 @@ | |||
TARGET = bstructmodule | |||
obj-m+=$(TARGET).o |
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.
please cleanup
04_basic_struct/bstructmodule.c
Outdated
#include <linux/init.h> // Macros used to mark up functions __init __exit | ||
#include <linux/module.h> // Core header for loading LKMs into the kernel |
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.
please cleanup
04_basic_struct/bstructmodule.c
Outdated
sscanf(buf, "%d\n", &value); | ||
pr_info("hello_store: value = %d\n", value); | ||
return count; |
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.
please add error handling
04_basic_struct/bstructmodule.c
Outdated
if (!hello_kobj) | ||
return -ENOMEM; | ||
/* Create the files associated with this kobject */ | ||
res = sysfs_create_group(hello_kobj, &attr_group); |
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.
What's the purpose of using group API for a single attribute?
04_basic_struct/bstructmodule.c
Outdated
struct list_head head_list; | ||
}; | ||
|
||
LIST_HEAD(linkedlist); |
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's usually bad idea to define global variables with such generic name.
Please limit its scope.
04_basic_struct/bstructmodule.c
Outdated
if (new_node->node == NULL) | ||
return -ENOMEM; | ||
list_add_tail(&new_node->head_list, &linkedlist); | ||
pr_info("store nodes: Added node = %s", buf); |
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's not a big deal, but prefer referencing actually added node instead of user buffer.
Also please don't forget newline explicit character for complete messages. (in other places as well)
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.
kstrdup allocates space for and copy an existing string. That's why nodes have been already stored with the end of the string. When we are printing out the nodes extra newline explicit character seems redundant
04_basic_struct/bstructmodule.c
Outdated
list_for_each_entry(cur_node, &linkedlist, head_list) { | ||
res = scnprintf(buf+offset, PAGE_SIZE-offset, "%s", cur_node->node); | ||
offset += res; | ||
} |
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.
IMO it makes sense to somehow separate entries in the output.
/mnt # | ||
/mnt # lsmod | ||
/mnt # | ||
|
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.
Please don't mix implementation and test logs in the same commit.
000b485
to
decfb19
Compare
Added simple module that provides basic operations with /sys/kernel/hello/list Variable BUILD_KERNEL should be set in the environment for building BUILD_KERNEL should define path to the linux kernel source folder Signed-off-by: Maryna Malakhova <[email protected]>
6a20fcb
to
ec4e981
Compare
Add list of strings insted of int value Signed-off-by: Maryna Malakhova <[email protected]>
Add BBB log Signed-off-by: Maryna Malakhova <[email protected]>
ec4e981
to
9c710d9
Compare
Thank you for the review, I've fixed |
Module has been created that could store parameters list in /sys/kernel/hello/list