summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-01-03 16:17:21 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-02-07 08:58:31 +0100
commit3535439f5c5faffeabe0c8f4a4694f1b24352db5 (patch)
tree7a7af09af7ea5f94bacb4276f55df5cff06d0fc7
parentlibdl: Fix potential overwrite of dest buffer (diff)
downloadrtems-3535439f5c5faffeabe0c8f4a4694f1b24352db5.tar.bz2
tftpfs: Use self-contained mutex
Update #2843.
-rw-r--r--cpukit/libnetworking/lib/tftpDriver.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/cpukit/libnetworking/lib/tftpDriver.c b/cpukit/libnetworking/lib/tftpDriver.c
index 1a5823bc12..97c9998aec 100644
--- a/cpukit/libnetworking/lib/tftpDriver.c
+++ b/cpukit/libnetworking/lib/tftpDriver.c
@@ -30,6 +30,7 @@
#include <rtems/seterr.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/tftp.h>
+#include <rtems/thread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -151,7 +152,7 @@ struct tftpStream {
*/
typedef struct tftpfs_info_s {
uint32_t flags;
- rtems_id tftp_mutex;
+ rtems_mutex tftp_mutex;
int nStreams;
struct tftpStream ** volatile tftpStreams;
} tftpfs_info_t;
@@ -180,7 +181,6 @@ int rtems_tftpfs_initialize(
const void *data
)
{
- rtems_status_code sc;
const char *device = mt_entry->dev;
size_t devicelen = strlen (device);
tftpfs_info_t *fs;
@@ -213,18 +213,7 @@ int rtems_tftpfs_initialize(
* NOTE: This could be in an fsinfo for this filesystem type.
*/
- sc = rtems_semaphore_create (
- rtems_build_name('T', 'F', 'T', 'P'),
- 1,
- RTEMS_BINARY_SEMAPHORE |
- RTEMS_PRIORITY |
- RTEMS_INHERIT_PRIORITY,
- 0,
- &fs->tftp_mutex
- );
-
- if (sc != RTEMS_SUCCESSFUL)
- goto error;
+ rtems_mutex_init (&fs->tftp_mutex, "TFTPFS");
if (data) {
char* config = (char*) data;
@@ -256,10 +245,10 @@ releaseStream (tftpfs_info_t *fs, int s)
{
if (fs->tftpStreams[s] && (fs->tftpStreams[s]->socket >= 0))
close (fs->tftpStreams[s]->socket);
- rtems_semaphore_obtain (fs->tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+ rtems_mutex_lock (&fs->tftp_mutex);
free (fs->tftpStreams[s]);
fs->tftpStreams[s] = NULL;
- rtems_semaphore_release (fs->tftp_mutex);
+ rtems_mutex_unlock (&fs->tftp_mutex);
}
static void
@@ -269,7 +258,7 @@ rtems_tftpfs_shutdown (rtems_filesystem_mount_table_entry_t* mt_entry)
int s;
for (s = 0; s < fs->nStreams; s++)
releaseStream (fs, s);
- rtems_semaphore_delete (fs->tftp_mutex);
+ rtems_mutex_destroy (&fs->tftp_mutex);
free (fs);
free (mt_entry->mt_fs_root->location.node_access);
}
@@ -536,7 +525,6 @@ static int rtems_tftp_open_worker(
char *cp2;
char *remoteFilename;
rtems_interval now;
- rtems_status_code sc;
char *hostname;
/*
@@ -583,9 +571,7 @@ static int rtems_tftp_open_worker(
/*
* Find a free stream
*/
- sc = rtems_semaphore_obtain (fs->tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- return EBUSY;
+ rtems_mutex_lock (&fs->tftp_mutex);
for (s = 0 ; s < fs->nStreams ; s++) {
if (fs->tftpStreams[s] == NULL)
break;
@@ -599,13 +585,13 @@ static int rtems_tftp_open_worker(
np = realloc (fs->tftpStreams, ++fs->nStreams * sizeof *fs->tftpStreams);
if (np == NULL) {
- rtems_semaphore_release (fs->tftp_mutex);
+ rtems_mutex_unlock (&fs->tftp_mutex);
return ENOMEM;
}
fs->tftpStreams = np;
}
tp = fs->tftpStreams[s] = malloc (sizeof (struct tftpStream));
- rtems_semaphore_release (fs->tftp_mutex);
+ rtems_mutex_unlock (&fs->tftp_mutex);
if (tp == NULL)
return ENOMEM;
iop->data0 = s;