Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embedded-linux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Maul
embedded-linux
Commits
e59dc838
Commit
e59dc838
authored
6 months ago
by
David Maul
Browse files
Options
Downloads
Patches
Plain Diff
fix: fix segfault when loading module and improve send_buffer size calculation
parent
9b986387
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
kernel/kmod.c
+25
-17
25 additions, 17 deletions
kernel/kmod.c
with
25 additions
and
17 deletions
kernel/kmod.c
+
25
−
17
View file @
e59dc838
...
...
@@ -16,7 +16,7 @@
#define CLASS_NAME "sibyl_class"
#define SLOTS 4
#define SLOT_INTERVAL_NS 100000000
0
#define SLOT_INTERVAL_NS 100000000
#define MAX_MEASUREMENTS 16
...
...
@@ -73,25 +73,33 @@ static uint32_t calculate_crc32(const packet_t *packet) {
static
void
prepare_for_sending
(
void
)
{
packet
->
crc
=
calculate_crc32
(
packet
);
size_t
n
=
0
;
secondary_send_buffer
[
0
]
=
packet
->
magic
;
secondary_send_buffer
[
1
]
=
packet
->
data
.
sender_id
;
secondary_send_buffer
[
2
]
=
packet
->
data
.
count
;
uint8_t
*
bytes
=
(
uint8_t
*
)
packet
->
data
.
measurements
;
n
+=
3
;
for
(
size_t
a
=
0
;
a
<
packet
->
data
.
count
;
a
++
)
{
uint8_t
*
bytes
=
(
uint8_t
*
)
&
(
packet
->
data
.
measurements
[
a
]);
for
(
size_t
b
=
0
;
b
<
sizeof
(
measurement_t
);
b
++
)
{
secondary_send_buffer
[
n
+
b
]
=
bytes
[
b
];
}
for
(
size_t
i
=
0
;
i
<
sizeof
(
measurement_t
)
*
packet
->
data
.
count
;
i
++
)
{
secondary_send_buffer
[
3
+
i
]
=
bytes
[
i
];
n
+=
sizeof
(
measurement_t
);
}
bytes
=
(
uint8_t
*
)
&
packet
->
crc
;
uint8_t
*
bytes
=
(
uint8_t
*
)
&
packet
->
crc
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
uint32_t
);
i
++
)
{
secondary_send_buffer
[
3
+
sizeof
(
measurement_t
)
*
packet
->
data
.
count
+
i
]
=
bytes
[
i
];
secondary_send_buffer
[
n
+
i
]
=
bytes
[
i
];
}
secondary_send_buffer_size
=
3
+
sizeof
(
measurement_t
)
*
packet
->
data
.
count
+
sizeof
(
uint32_t
);
n
+=
sizeof
(
uint32_t
);
secondary_send_buffer_size
=
n
;
// Swap buffers
mutex_lock
(
&
send_buffer_mutex
);
...
...
@@ -220,8 +228,6 @@ static int __init lkm_init(void) {
return
-
EFAULT
;
}
prepare_for_sending
();
// Allocate memory for send buffers
primary_send_buffer
=
(
uint8_t
*
)
vmalloc
(
SEND_BUFFER_SIZE
);
primary_send_buffer_size
=
0
;
...
...
@@ -240,6 +246,8 @@ static int __init lkm_init(void) {
return
-
EFAULT
;
}
prepare_for_sending
();
if
(
alloc_chrdev_region
(
&
dev
,
0
,
1
,
DEVICE_NAME
)
<
0
)
{
vfree
(
primary_send_buffer
);
vfree
(
secondary_send_buffer
);
...
...
@@ -325,6 +333,12 @@ static int __init lkm_init(void) {
}
static
void
__exit
lkm_exit
(
void
)
{
if
(
timed_thread
)
{
kthread_stop
(
timed_thread
);
}
hrtimer_cancel
(
&
timer
);
mutex_destroy
(
&
send_buffer_mutex
);
vfree
(
primary_send_buffer
);
...
...
@@ -339,12 +353,6 @@ static void __exit lkm_exit(void) {
gpio_set_value
(
GPIO_PIN
,
0
);
gpio_free
(
GPIO_PIN
);
if
(
timed_thread
)
{
kthread_stop
(
timed_thread
);
}
hrtimer_cancel
(
&
timer
);
}
module_init
(
lkm_init
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment