Blame SOURCES/autofs-5.1.7-add-ext_mount_hash_mutex-lock-helpers.patch

96dc52
autofs-5.1.7 - add ext_mount_hash_mutex lock helpers
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
Coverity: check_return: Calling "pthread_mutex_lock" without checking
96dc52
	  return value.
96dc52
96dc52
Well, I use helpers to do this in many places so can't really disagree.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG    |    1 +
96dc52
 lib/mounts.c |   26 ++++++++++++++++++++------
96dc52
 2 files changed, 21 insertions(+), 6 deletions(-)
96dc52
96dc52
diff --git a/CHANGELOG b/CHANGELOG
96dc52
index b1b28888..ff44ac25 100644
96dc52
--- a/CHANGELOG
96dc52
+++ b/CHANGELOG
96dc52
@@ -65,6 +65,7 @@
96dc52
 - fix double free in parse_mapent().
96dc52
 - refactor lookup_prune_one_cache() a bit.
96dc52
 - cater for empty mounts list in mnts_get_expire_list().
96dc52
+- add ext_mount_hash_mutex lock helpers.
96dc52
 
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
diff --git a/lib/mounts.c b/lib/mounts.c
96dc52
index 3996eb5e..c24d1a88 100644
96dc52
--- a/lib/mounts.c
96dc52
+++ b/lib/mounts.c
96dc52
@@ -788,6 +788,20 @@ char *make_mnt_name_string(char *path)
96dc52
 	return mnt_name;
96dc52
 }
96dc52
 
96dc52
+static void ext_mount_hash_mutex_lock(void)
96dc52
+{
96dc52
+	int status = pthread_mutex_lock(&ext_mount_hash_mutex);
96dc52
+	if (status)
96dc52
+		fatal(status);
96dc52
+}
96dc52
+
96dc52
+static void ext_mount_hash_mutex_unlock(void)
96dc52
+{
96dc52
+	int status = pthread_mutex_unlock(&ext_mount_hash_mutex);
96dc52
+	if (status)
96dc52
+		fatal(status);
96dc52
+}
96dc52
+
96dc52
 static struct ext_mount *ext_mount_lookup(const char *mp)
96dc52
 {
96dc52
 	uint32_t hval = hash(mp, HASH_SIZE(ext_mounts_hash));
96dc52
@@ -806,7 +820,7 @@ int ext_mount_add(const char *path, const char *umount)
96dc52
 	struct ext_mount *em;
96dc52
 	int ret = 0;
96dc52
 
96dc52
-	pthread_mutex_lock(&ext_mount_hash_mutex);
96dc52
+	ext_mount_hash_mutex_lock();
96dc52
 
96dc52
 	em = ext_mount_lookup(path);
96dc52
 	if (em) {
96dc52
@@ -840,7 +854,7 @@ int ext_mount_add(const char *path, const char *umount)
96dc52
 
96dc52
 	ret = 1;
96dc52
 done:
96dc52
-	pthread_mutex_unlock(&ext_mount_hash_mutex);
96dc52
+	ext_mount_hash_mutex_unlock();
96dc52
 	return ret;
96dc52
 }
96dc52
 
96dc52
@@ -849,7 +863,7 @@ int ext_mount_remove(const char *path)
96dc52
 	struct ext_mount *em;
96dc52
 	int ret = 0;
96dc52
 
96dc52
-	pthread_mutex_lock(&ext_mount_hash_mutex);
96dc52
+	ext_mount_hash_mutex_lock();
96dc52
 
96dc52
 	em = ext_mount_lookup(path);
96dc52
 	if (!em)
96dc52
@@ -867,7 +881,7 @@ int ext_mount_remove(const char *path)
96dc52
 		ret = 1;
96dc52
 	}
96dc52
 done:
96dc52
-	pthread_mutex_unlock(&ext_mount_hash_mutex);
96dc52
+	ext_mount_hash_mutex_unlock();
96dc52
 	return ret;
96dc52
 }
96dc52
 
96dc52
@@ -876,13 +890,13 @@ int ext_mount_inuse(const char *path)
96dc52
 	struct ext_mount *em;
96dc52
 	int ret = 0;
96dc52
 
96dc52
-	pthread_mutex_lock(&ext_mount_hash_mutex);
96dc52
+	ext_mount_hash_mutex_lock();
96dc52
 	em = ext_mount_lookup(path);
96dc52
 	if (!em)
96dc52
 		goto done;
96dc52
 	ret = em->ref;
96dc52
 done:
96dc52
-	pthread_mutex_unlock(&ext_mount_hash_mutex);
96dc52
+	ext_mount_hash_mutex_unlock();
96dc52
 	return ret;
96dc52
 }
96dc52