Commit 1bcbe6a6 authored by Federico Vaga's avatar Federico Vaga

sw:lib: bugfix close only opened devices

The funciton ``trtl_close()`` was closing all possible file descriptors
based on the maximum number of CPUs and HMQs configurable on Mock-Turtle.
Consequentially ``trtl_close()`` may close random file descriptors because
fd_cpu and fd_hmq may contain random value for unused entries.

Instead, the ``trtl_close()`` should close **only** those devices really
existing according to the configuration ROM.
Reported-by: Dimitris Lampridis's avatarDimitris Lampridis <dimitris.lampridis@cern.ch>
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 1c2e49ef
......@@ -344,10 +344,10 @@ void trtl_close(struct trtl_dev *trtl)
/* Close all the file descriptors */
if (wdesc->fd_dev >= 0)
close(wdesc->fd_dev);
for (i = 0; i < TRTL_MAX_CPU; ++i) {
for (i = 0; i < wdesc->cfgrom.n_cpu; ++i) {
if (wdesc->fd_cpu[i] >= 0)
close(wdesc->fd_cpu[i]);
for (k = 0; k < TRTL_MAX_MQ_CHAN; ++k) {
for (k = 0; k < wdesc->cfgrom.n_hmq[i]; ++k) {
if (wdesc->fd_hmq[i][k] >= 0)
close(wdesc->fd_hmq[i][k]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment