Skip to content
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

Open
wants to merge 3 commits into
base: Maryna.Malakhova
Choose a base branch
from

Conversation

marynamalakhova
Copy link

Module has been created that could store parameters list in /sys/kernel/hello/list

04_basic_struct/bstructmodule.c Outdated Show resolved Hide resolved
04_basic_struct/bstructmodule.c Outdated Show resolved Hide resolved
04_basic_struct/bstructmodule.c Outdated Show resolved Hide resolved
04_basic_struct/bstructmodule.c Outdated Show resolved Hide resolved
@marynamalakhova marynamalakhova force-pushed the 04_task_struct branch 5 times, most recently from 8557de9 to 8460748 Compare April 5, 2021 15:06
@@ -0,0 +1,7 @@
TARGET = bstructmodule

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”

@@ -0,0 +1,7 @@
TARGET = bstructmodule
obj-m+=$(TARGET).o

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please cleanup

Comment on lines 4 to 5
#include <linux/init.h> // Macros used to mark up functions __init __exit
#include <linux/module.h> // Core header for loading LKMs into the kernel

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please cleanup

Comment on lines 24 to 26
sscanf(buf, "%d\n", &value);
pr_info("hello_store: value = %d\n", value);
return count;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add error handling

if (!hello_kobj)
return -ENOMEM;
/* Create the files associated with this kobject */
res = sysfs_create_group(hello_kobj, &attr_group);

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?

struct list_head head_list;
};

LIST_HEAD(linkedlist);

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.

if (new_node->node == NULL)
return -ENOMEM;
list_add_tail(&new_node->head_list, &linkedlist);
pr_info("store nodes: Added node = %s", buf);

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)

Copy link
Author

@marynamalakhova marynamalakhova Apr 6, 2021

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

Comment on lines 27 to 30
list_for_each_entry(cur_node, &linkedlist, head_list) {
res = scnprintf(buf+offset, PAGE_SIZE-offset, "%s", cur_node->node);
offset += res;
}

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 #

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.

@AleksandrBulyshchenko AleksandrBulyshchenko added Change requested Change requested and removed Ready for review Ready for review labels Apr 5, 2021
@marynamalakhova marynamalakhova force-pushed the 04_task_struct branch 2 times, most recently from 000b485 to decfb19 Compare April 6, 2021 11:42
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]>
@marynamalakhova marynamalakhova force-pushed the 04_task_struct branch 2 times, most recently from 6a20fcb to ec4e981 Compare April 6, 2021 11:47
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]>
@marynamalakhova marynamalakhova added Ready for review Ready for review and removed Change requested Change requested labels Apr 6, 2021
@marynamalakhova
Copy link
Author

Thank you for the review, I've fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants