Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Container registry
Model registry
Operate
Environments
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
acfe57a5
Commit
acfe57a5
authored
6 years ago
by
Martine Lenders
Browse files
Options
Downloads
Patches
Plain Diff
gnrc_pktbuf_static: reduce checks to be in line with new alignment
parent
8a75d8d1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c
+7
-11
7 additions, 11 deletions
sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c
with
7 additions
and
11 deletions
sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c
+
7
−
11
View file @
acfe57a5
...
@@ -108,8 +108,7 @@ gnrc_pktsnip_t *gnrc_pktbuf_mark(gnrc_pktsnip_t *pkt, size_t size, gnrc_nettype_
...
@@ -108,8 +108,7 @@ gnrc_pktsnip_t *gnrc_pktbuf_mark(gnrc_pktsnip_t *pkt, size_t size, gnrc_nettype_
{
{
gnrc_pktsnip_t
*
marked_snip
;
gnrc_pktsnip_t
*
marked_snip
;
/* size required for chunk */
/* size required for chunk */
size_t
required_new_size
=
(
size
<
sizeof
(
_unused_t
))
?
size_t
required_new_size
=
_align
(
size
);
_align
(
sizeof
(
_unused_t
))
:
_align
(
size
);
void
*
new_data_marked
;
void
*
new_data_marked
;
mutex_lock
(
&
_mutex
);
mutex_lock
(
&
_mutex
);
...
@@ -130,8 +129,7 @@ gnrc_pktsnip_t *gnrc_pktbuf_mark(gnrc_pktsnip_t *pkt, size_t size, gnrc_nettype_
...
@@ -130,8 +129,7 @@ gnrc_pktsnip_t *gnrc_pktbuf_mark(gnrc_pktsnip_t *pkt, size_t size, gnrc_nettype_
}
}
/* marked data would not fit _unused_t marker => move data around to allow
/* marked data would not fit _unused_t marker => move data around to allow
* for proper free */
* for proper free */
if
((
pkt
->
size
!=
size
)
&&
if
((
pkt
->
size
!=
size
)
&&
(
size
<
required_new_size
))
{
((
size
<
required_new_size
)
||
((
pkt
->
size
-
size
)
<
sizeof
(
_unused_t
))))
{
void
*
new_data_rest
;
void
*
new_data_rest
;
new_data_marked
=
_pktbuf_alloc
(
size
);
new_data_marked
=
_pktbuf_alloc
(
size
);
if
(
new_data_marked
==
NULL
)
{
if
(
new_data_marked
==
NULL
)
{
...
@@ -169,8 +167,7 @@ gnrc_pktsnip_t *gnrc_pktbuf_mark(gnrc_pktsnip_t *pkt, size_t size, gnrc_nettype_
...
@@ -169,8 +167,7 @@ gnrc_pktsnip_t *gnrc_pktbuf_mark(gnrc_pktsnip_t *pkt, size_t size, gnrc_nettype_
int
gnrc_pktbuf_realloc_data
(
gnrc_pktsnip_t
*
pkt
,
size_t
size
)
int
gnrc_pktbuf_realloc_data
(
gnrc_pktsnip_t
*
pkt
,
size_t
size
)
{
{
size_t
aligned_size
=
(
size
<
sizeof
(
_unused_t
))
?
size_t
aligned_size
=
_align
(
size
);
_align
(
sizeof
(
_unused_t
))
:
_align
(
size
);
mutex_lock
(
&
_mutex
);
mutex_lock
(
&
_mutex
);
assert
(
pkt
!=
NULL
);
assert
(
pkt
!=
NULL
);
...
@@ -189,8 +186,7 @@ int gnrc_pktbuf_realloc_data(gnrc_pktsnip_t *pkt, size_t size)
...
@@ -189,8 +186,7 @@ int gnrc_pktbuf_realloc_data(gnrc_pktsnip_t *pkt, size_t size)
pkt
->
data
=
NULL
;
pkt
->
data
=
NULL
;
}
}
/* if new size is bigger than old size */
/* if new size is bigger than old size */
else
if
((
size
>
pkt
->
size
)
||
/* new size does not fit */
else
if
(
size
>
pkt
->
size
)
{
/* new size does not fit */
((
pkt
->
size
-
aligned_size
)
<
sizeof
(
_unused_t
)))
{
/* resulting hole would not fit marker */
void
*
new_data
=
_pktbuf_alloc
(
size
);
void
*
new_data
=
_pktbuf_alloc
(
size
);
if
(
new_data
==
NULL
)
{
if
(
new_data
==
NULL
)
{
DEBUG
(
"pktbuf: error allocating new data section
\n
"
);
DEBUG
(
"pktbuf: error allocating new data section
\n
"
);
...
@@ -396,7 +392,7 @@ static void *_pktbuf_alloc(size_t size)
...
@@ -396,7 +392,7 @@ static void *_pktbuf_alloc(size_t size)
{
{
_unused_t
*
prev
=
NULL
,
*
ptr
=
_first_unused
;
_unused_t
*
prev
=
NULL
,
*
ptr
=
_first_unused
;
size
=
(
size
<
sizeof
(
_unused_t
))
?
_align
(
sizeof
(
_unused_t
))
:
_align
(
size
);
size
=
_align
(
size
);
while
(
ptr
&&
(
size
>
ptr
->
size
))
{
while
(
ptr
&&
(
size
>
ptr
->
size
))
{
prev
=
ptr
;
prev
=
ptr
;
ptr
=
ptr
->
next
;
ptr
=
ptr
->
next
;
...
@@ -466,11 +462,11 @@ static void _pktbuf_free(void *data, size_t size)
...
@@ -466,11 +462,11 @@ static void _pktbuf_free(void *data, size_t size)
ptr
=
ptr
->
next
;
ptr
=
ptr
->
next
;
}
}
new
->
next
=
ptr
;
new
->
next
=
ptr
;
new
->
size
=
(
size
<
sizeof
(
_unused_t
))
?
_align
(
sizeof
(
_unused_t
))
:
_align
(
size
);
new
->
size
=
_align
(
size
);
/* calculate number of bytes between new _unused_t chunk and end of packet
/* calculate number of bytes between new _unused_t chunk and end of packet
* buffer */
* buffer */
bytes_at_end
=
((
&
_pktbuf
[
0
]
+
GNRC_PKTBUF_SIZE
)
-
(((
uint8_t
*
)
new
)
+
new
->
size
));
bytes_at_end
=
((
&
_pktbuf
[
0
]
+
GNRC_PKTBUF_SIZE
)
-
(((
uint8_t
*
)
new
)
+
new
->
size
));
if
(
bytes_at_end
<
_align
(
sizeof
(
_unused_t
))
)
{
if
(
bytes_at_end
<
sizeof
(
_unused_t
))
{
/* new is very last segment and there is a little bit of memory left
/* new is very last segment and there is a little bit of memory left
* that wouldn't fit _unused_t (cut of in _pktbuf_alloc()) => re-add it */
* that wouldn't fit _unused_t (cut of in _pktbuf_alloc()) => re-add it */
new
->
size
+=
bytes_at_end
;
new
->
size
+=
bytes_at_end
;
...
...
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