basecamp: Add task06#134
Conversation
Signed-off-by: Anton Kotsiubailo <antohakotsubailo@gmail.com>
Signed-off-by: Anton Kotsiubailo <antohakotsubailo@gmail.com>
|
Please change fd07a2d commit description |
06_timers/kernel_space/time.c
Outdated
| return res; | ||
| } | ||
|
|
||
| void x_cleanup(void) |
| int res; | ||
| x_class = class_create(THIS_MODULE, "x-class"); | ||
| if (IS_ERR(x_class)) | ||
| pr_err("bad class create\n"); |
There was a problem hiding this comment.
Add empty line or enclose into curly brackets
| int __init x_init(void) | ||
| { | ||
| int res; | ||
| x_class = class_create(THIS_MODULE, "x-class"); |
There was a problem hiding this comment.
Add empty line after declared variables
06_timers/kernel_space/time.c
Outdated
| #define CLASS_ATTR(_name, _mode, _show, _store) \ | ||
| struct class_attribute class_attr_##_name = \ |
There was a problem hiding this comment.
make \ -on the same indentation
06_timers/kernel_space/log.rst
Outdated
| /tmp # cat /sys/class/x-class/xxx | ||
| [ 563.686241] read 19 | ||
| [ 563.686318] time: 363851968 | ||
| [ 563.686369] previous time: -193400624 |
There was a problem hiding this comment.
Convert the time you show to UTC time format
Changed time format for task06. Signed-off-by: Anton Kotsiubailo <antohakotsubailo@gmail.com>
Anton-Soroka
left a comment
There was a problem hiding this comment.
Sorry, I can't check your task without Makefile
Please do following:
- Add Makefile
- Fix code according to comments
- Update text logs for fixed code
- Ensure that make and checkpatch shows zero warnings.
| struct class_attribute class_attr_##_name = \ | ||
| __ATTR(_name, _mode, _show, _store) | ||
|
|
||
| static char buf_msg[LEN_MSG + 1] = "Hello from module!\n"; |
| strcpy(buf, buf_msg); | ||
| pr_info("read %ld\n", (long)strlen(buf)); |
| MODULE_VERSION("0.1"); | ||
| MODULE_LICENSE("Dual MIT/GPL"); // this affects the kernel behavior | ||
|
|
||
| #define LEN_MSG 160 |
| if (IS_ERR(x_class)) { | ||
| pr_err("bad class create\n"); | ||
| } | ||
| res = class_create_file(x_class, &class_attr_xxx); |
There was a problem hiding this comment.
pay attention to return code
add proper error handling
| time = ktime_to_timespec(prev); | ||
| pr_info("previous time: %d.%09ld sec\n", time.tv_sec, time.tv_nsec); | ||
| prev = currtime - pasttime; |
There was a problem hiding this comment.
previous time displayed incorrectly
according to your code you need to print pasttime variable
prev variable is not needed
| static char buf_msg[LEN_MSG + 1] = "Hello from module!\n"; | ||
| static ktime_t currtime; | ||
| static ktime_t pasttime; | ||
| static ktime_t prev; |
| x_class = class_create(THIS_MODULE, "x-class"); | ||
| if (IS_ERR(x_class)) { | ||
| pr_err("bad class create\n"); | ||
| } |
There was a problem hiding this comment.
add proper error handling
you should exit here
| @@ -0,0 +1,71 @@ | |||
| // SPDX-License-Identifier: GPL-2.0 | |||
| #include <asm/uaccess.h> | |||
There was a problem hiding this comment.
check patch WARNING: Use #include <linux/uaccess.h> instead of <asm/uaccess.h>
Additional question - are you sure all these includes needed here?
Signed-off-by: Anton Kotsiubailo antohakotsubailo@gmail.com