Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC ADC 100M 14b 4cha - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC ADC 100M 14b 4cha - Software
Commits
7e4a858d
Commit
7e4a858d
authored
Apr 21, 2016
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel: check overflow in a single place
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
9064247e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
44 deletions
+42
-44
fa-zio-drv.c
kernel/fa-zio-drv.c
+42
-5
fa-zio-trg.c
kernel/fa-zio-trg.c
+0
-5
fmc-adc-100m14b4cha.h
kernel/fmc-adc-100m14b4cha.h
+0
-34
No files found.
kernel/fa-zio-drv.c
View file @
7e4a858d
...
...
@@ -341,6 +341,42 @@ static const struct zio_sysfs_operations zfad_s_op = {
};
static
inline
int
zfat_overflow_detection
(
struct
zio_ti
*
ti
)
{
struct
fa_dev
*
fa
=
ti
->
cset
->
zdev
->
priv_d
;
struct
zio_attribute
*
ti_zattr
=
ti
->
zattr_set
.
std_zattr
;
uint32_t
nshot_t
,
nsamples
;
size_t
shot_size
;
if
(
ti
->
cset
->
trig
!=
&
zfat_type
)
nshot_t
=
1
;
/* with any other trigger work in one-shot mode */
else
nshot_t
=
ti_zattr
[
ZIO_ATTR_TRIG_N_SHOTS
].
value
;
/*
* +2 because of the timetag at the end
*/
nsamples
=
ti_zattr
[
ZIO_ATTR_TRIG_PRE_SAMP
].
value
+
ti_zattr
[
ZIO_ATTR_TRIG_POST_SAMP
].
value
;
shot_size
=
((
nsamples
+
2
)
*
ti
->
cset
->
ssize
)
*
FA100M14B4C_NCHAN
;
if
(
(
shot_size
*
nshot_t
)
>
FA100M14B4C_MAX_ACQ_BYTE
)
{
dev_err
(
&
ti
->
head
.
dev
,
"Cannot acquire, dev memory overflow
\n
"
);
return
-
ENOMEM
;
}
/* in case of multi shot, each shot cannot exceed the dpram size */
if
(
(
nshot_t
>
1
)
&&
(
nsamples
>
fa
->
mshot_max_samples
)
)
{
dev_err
(
&
ti
->
head
.
dev
,
"Cannot acquire such amount of samples "
"(req: %d , max: %d) in multi shot mode."
"dev memory overflow
\n
"
,
nsamples
,
fa
->
mshot_max_samples
);
return
-
ENOMEM
;
}
return
0
;
}
/*
* zfad_input_cset_software
* @fa the adc instance to use
...
...
@@ -355,12 +391,7 @@ static const struct zio_sysfs_operations zfad_s_op = {
static
int
zfad_input_cset_software
(
struct
fa_dev
*
fa
,
struct
zio_cset
*
cset
)
{
struct
zfad_block
*
tmp
;
int
err
;
/* Check if device memory allows this acquisition */
err
=
zfat_overflow_detection
(
cset
->
ti
);
if
(
err
)
return
err
;
tmp
=
kzalloc
(
sizeof
(
struct
zfad_block
),
GFP_ATOMIC
);
if
(
!
tmp
)
return
-
ENOMEM
;
...
...
@@ -391,6 +422,12 @@ static int zfad_input_cset_software(struct fa_dev *fa, struct zio_cset *cset)
static
int
zfad_input_cset
(
struct
zio_cset
*
cset
)
{
struct
fa_dev
*
fa
=
cset
->
zdev
->
priv_d
;
int
err
;
/* Check if device memory allows this acquisition */
err
=
zfat_overflow_detection
(
cset
->
ti
);
if
(
err
)
return
err
;
dev_dbg
(
&
fa
->
fmc
->
dev
,
"Ready to acquire
\n
"
);
/* ZIO should configure only the interleaved channel */
...
...
kernel/fa-zio-trg.c
View file @
7e4a858d
...
...
@@ -307,11 +307,6 @@ static int zfat_arm_trigger(struct zio_ti *ti)
dev_dbg
(
msgdev
,
"Arming trigger
\n
"
);
/* Check if device memory allows this trigger configuration */
err
=
zfat_overflow_detection
(
ti
);
if
(
err
)
return
err
;
/* Update the current control: sequence, nsamples and tstamp */
interleave
->
current_ctrl
->
nsamples
=
ti
->
nsamples
;
...
...
kernel/fmc-adc-100m14b4cha.h
View file @
7e4a858d
...
...
@@ -401,40 +401,6 @@ struct zfad_block {
/* Global variable exported by fa-zio-trg.c */
extern
struct
zio_trigger_type
zfat_type
;
static
inline
int
zfat_overflow_detection
(
struct
zio_ti
*
ti
)
{
struct
fa_dev
*
fa
=
ti
->
cset
->
zdev
->
priv_d
;
struct
zio_attribute
*
ti_zattr
=
ti
->
zattr_set
.
std_zattr
;
uint32_t
nshot_t
,
nsamples
;
size_t
shot_size
;
if
(
ti
->
cset
->
trig
!=
&
zfat_type
)
nshot_t
=
1
;
/* with any other trigger work in one-shot mode */
else
nshot_t
=
ti_zattr
[
ZIO_ATTR_TRIG_N_SHOTS
].
value
;
/*
* +2 because of the timetag at the end
*/
nsamples
=
ti_zattr
[
ZIO_ATTR_TRIG_PRE_SAMP
].
value
+
ti_zattr
[
ZIO_ATTR_TRIG_POST_SAMP
].
value
;
shot_size
=
((
nsamples
+
2
)
*
ti
->
cset
->
ssize
)
*
FA100M14B4C_NCHAN
;
if
(
(
shot_size
*
nshot_t
)
>
FA100M14B4C_MAX_ACQ_BYTE
)
{
dev_err
(
&
ti
->
head
.
dev
,
"Cannot acquire, dev memory overflow
\n
"
);
return
-
ENOMEM
;
}
/* in case of multi shot, each shot cannot exceed the dpram size */
if
(
(
nshot_t
>
1
)
&&
(
nsamples
>
fa
->
mshot_max_samples
)
)
{
dev_err
(
&
ti
->
head
.
dev
,
"Cannot acquire such amount of samples "
"(req: %d , max: %d) in multi shot mode."
"dev memory overflow
\n
"
,
nsamples
,
fa
->
mshot_max_samples
);
return
-
ENOMEM
;
}
return
0
;
}
static
inline
struct
fa_dev
*
get_zfadc
(
struct
device
*
dev
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment