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

Task5: Hello module with proc_fs #101

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

EugeneKolesnyk
Copy link

No description provided.

Signed-off-by: EugeneKolesnyk <[email protected]>
…rning during compilation

Signed-off-by: EugeneKolesnyk <[email protected]>
Signed-off-by: EugeneKolesnyk <[email protected]>
Signed-off-by: EugeneKolesnyk <[email protected]>
Signed-off-by: EugeneKolesnyk <[email protected]>
@EugeneKolesnyk EugeneKolesnyk added the Ready for review Ready to be reviewed label Mar 8, 2023

static int __init hello_init(void)
{
procfs_buffer_size = sprintf(procfs_buffer, "%d + %d = %d\n", num1, num2, num1 + num2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Code style issues are here and below

Copy link
Author

Choose a reason for hiding this comment

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

Fixed code style issues

proc_file = proc_create(PROC_FILE_NAME, 0666, proc_folder, &fops);
if (!proc_file) {
pr_err("HELLO: Error: Could not initialize /proc/%s/%s\n", PROC_DIR_NAME, PROC_FILE_NAME);
proc_remove(proc_file);
Copy link
Contributor

Choose a reason for hiding this comment

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

No sense to call proc_remove(proc_file); here because proc_file is not valid.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed


static void __exit hello_exit(void)
{
pr_info("HELLO: Goodbye Kernel!\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Code style issues are here and below

Copy link
Author

Choose a reason for hiding this comment

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

Fixed code style issues


to_copy = min(count, procfs_buffer_size);

not_copied = copy_to_user(buffer, procfs_buffer, to_copy);
Copy link
Contributor

Choose a reason for hiding this comment

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

Per my understanding, if procfs_buffer_size variable is maintained and updated in the code below it is assumed that procfs_buffer contents can be read by the user space app by multiple reads.
For example 100 bytes buffer can be read by 2 hello_read calls with count set to 25 and 75.
But, data is copied to the user provided buffer from the beginning of the procfs_buffer, so the same data will be copied twice, what, per my understanding, is not expected.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

@AndriySmolskyy AndriySmolskyy left a comment

Choose a reason for hiding this comment

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

Please see my comments in the task5-proc_fs/hello.c file.

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

Successfully merging this pull request may close these issues.

2 participants