Skip to content

basecamp: Add task06#134

Open
ant112342 wants to merge 4 commits intoKernel-GL-HRK:anton.kotsiubailofrom
ant112342:task06
Open

basecamp: Add task06#134
ant112342 wants to merge 4 commits intoKernel-GL-HRK:anton.kotsiubailofrom
ant112342:task06

Conversation

@ant112342
Copy link

Signed-off-by: Anton Kotsiubailo antohakotsubailo@gmail.com

Signed-off-by: Anton Kotsiubailo <antohakotsubailo@gmail.com>
@ant112342 ant112342 added the Ready for review Ready for review label Mar 22, 2021
@ant112342 ant112342 requested a review from Anton-Soroka March 22, 2021 10:35
ekovalyov and others added 2 commits March 24, 2021 15:01
Signed-off-by: Anton Kotsiubailo <antohakotsubailo@gmail.com>
@alexposukhov
Copy link
Contributor

Please change fd07a2d commit description
Remove .:

return res;
}

void x_cleanup(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

__exit modificator

Copy link
Author

Choose a reason for hiding this comment

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

done

int res;
x_class = class_create(THIS_MODULE, "x-class");
if (IS_ERR(x_class))
pr_err("bad class create\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Add empty line or enclose into curly brackets

Copy link
Author

Choose a reason for hiding this comment

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

fixed

int __init x_init(void)
{
int res;
x_class = class_create(THIS_MODULE, "x-class");
Copy link
Contributor

Choose a reason for hiding this comment

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

Add empty line after declared variables

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +18 to +19
#define CLASS_ATTR(_name, _mode, _show, _store) \
struct class_attribute class_attr_##_name = \
Copy link
Contributor

Choose a reason for hiding this comment

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

make \ -on the same indentation

Copy link
Author

Choose a reason for hiding this comment

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

done

/tmp # cat /sys/class/x-class/xxx
[ 563.686241] read 19
[ 563.686318] time: 363851968
[ 563.686369] previous time: -193400624
Copy link
Contributor

Choose a reason for hiding this comment

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

Convert the time you show to UTC time format

@alexposukhov alexposukhov added Change requested Change requested and removed Ready for review Ready for review labels Mar 25, 2021
@ant112342 ant112342 added Ready for review Ready for review and removed Change requested Change requested labels Mar 26, 2021
Changed time format for task06.

Signed-off-by: Anton Kotsiubailo <antohakotsubailo@gmail.com>
Copy link

@Anton-Soroka Anton-Soroka left a comment

Choose a reason for hiding this comment

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

Sorry, I can't check your task without Makefile
Please do following:

  1. Add Makefile
  2. Fix code according to comments
  3. Update text logs for fixed code
  4. 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";

Choose a reason for hiding this comment

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

buf_msg is not needed

Comment on lines +34 to +35
strcpy(buf, buf_msg);
pr_info("read %ld\n", (long)strlen(buf));

Choose a reason for hiding this comment

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

This is not needed

MODULE_VERSION("0.1");
MODULE_LICENSE("Dual MIT/GPL"); // this affects the kernel behavior

#define LEN_MSG 160

Choose a reason for hiding this comment

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

LEN_MSG is not needed

if (IS_ERR(x_class)) {
pr_err("bad class create\n");
}
res = class_create_file(x_class, &class_attr_xxx);

Choose a reason for hiding this comment

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

pay attention to return code
add proper error handling

Comment on lines +37 to +39
time = ktime_to_timespec(prev);
pr_info("previous time: %d.%09ld sec\n", time.tv_sec, time.tv_nsec);
prev = currtime - pasttime;

Choose a reason for hiding this comment

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

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;

Choose a reason for hiding this comment

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

prev is not needed

x_class = class_create(THIS_MODULE, "x-class");
if (IS_ERR(x_class)) {
pr_err("bad class create\n");
}

Choose a reason for hiding this comment

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

add proper error handling
you should exit here

@@ -0,0 +1,71 @@
// SPDX-License-Identifier: GPL-2.0
#include <asm/uaccess.h>

Choose a reason for hiding this comment

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

check patch WARNING: Use #include <linux/uaccess.h> instead of <asm/uaccess.h>
Additional question - are you sure all these includes needed here?

@Anton-Soroka Anton-Soroka added Change requested Change requested and removed Ready for review Ready for review labels Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Change requested Change requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants