Skip to contentSkip to conversation

test_firmware: remove unnecessary test_fw_mutex in test_dev_config_show_xxx

PATCH Applied Scott Branden 3 participants 5 messages Apr 15, 2020 – Apr 16, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test_firmware: remove unnecessary test_fw_mutex in test_dev_config_show_xxx

Remove unnecessary use of test_fw_mutex in test_dev_config_show_xxx functions that show simple bool, int, and u8.

---
 lib/test_firmware.c | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)
lib/test_firmware.c +3 -23
index 0c7fbcf07ac5..9fee2b93a8d1 100644
@@ -310,27 +310,13 @@ static int test_dev_config_update_bool(const char *buf, size_t size,
 	return ret;
 }
 
-static ssize_t
-test_dev_config_show_bool(char *buf,
-			  bool config)
+static ssize_t test_dev_config_show_bool(char *buf, bool val)
 {
-	bool val;
-
-	mutex_lock(&test_fw_mutex);
-	val = config;
-	mutex_unlock(&test_fw_mutex);
-
 	return snprintf(buf, PAGE_SIZE, "%d\n", val);
 }
 
-static ssize_t test_dev_config_show_int(char *buf, int cfg)
+static ssize_t test_dev_config_show_int(char *buf, int val)
 {
-	int val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
 	return snprintf(buf, PAGE_SIZE, "%d\n", val);
 }
 
@@ -354,14 +340,8 @@ static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg)
 	return size;
 }
 
-static ssize_t test_dev_config_show_u8(char *buf, u8 cfg)
+static ssize_t test_dev_config_show_u8(char *buf, u8 val)
 {
-	u8 val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
 	return snprintf(buf, PAGE_SIZE, "%u\n", val);
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · Scott Branden

Remove unnecessary use of test_fw_mutex in test_dev_config_show_xxx functions that show simple bool, int, and u8.

I would expect at least a READ_ONCE(), yes?

Quoted 59 lines
---
 lib/test_firmware.c | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)
lib/test_firmware.c +3 -23
index 0c7fbcf07ac5..9fee2b93a8d1 100644
@@ -310,27 +310,13 @@ static int test_dev_config_update_bool(const char *buf, size_t size,
 	return ret;
 }
 
-static ssize_t
-test_dev_config_show_bool(char *buf,
-			  bool config)
+static ssize_t test_dev_config_show_bool(char *buf, bool val)
 {
-	bool val;
-
-	mutex_lock(&test_fw_mutex);
-	val = config;
-	mutex_unlock(&test_fw_mutex);
-
 	return snprintf(buf, PAGE_SIZE, "%d\n", val);
 }
 
-static ssize_t test_dev_config_show_int(char *buf, int cfg)
+static ssize_t test_dev_config_show_int(char *buf, int val)
 {
-	int val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
 	return snprintf(buf, PAGE_SIZE, "%d\n", val);
 }
 
@@ -354,14 +340,8 @@ static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg)
 	return size;
 }
 
-static ssize_t test_dev_config_show_u8(char *buf, u8 cfg)
+static ssize_t test_dev_config_show_u8(char *buf, u8 val)
 {
-	u8 val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
 	return snprintf(buf, PAGE_SIZE, "%u\n", val);
 }
 
Signature · 1 line
2.17.1
Signature · 1 line
Kees Cook
#2 lore raw

Hi Kees,

Quoted 4 lines · Kees Cook
Quoted 2 lines · Scott Branden

Remove unnecessary use of test_fw_mutex in test_dev_config_show_xxx functions that show simple bool, int, and u8.

I would expect at least a READ_ONCE(), yes?

I don't understand why you need a READ_ONCE when removing a mutex around an assignment of a parameter passed into a function being assigned to a local variable.

Could you please explain your expectations.

Quoted 59 lines
Quoted 59 lines
---
  lib/test_firmware.c | 26 +++-----------------------
  1 file changed, 3 insertions(+), 23 deletions(-)
lib/test_firmware.c +3 -23
index 0c7fbcf07ac5..9fee2b93a8d1 100644
@@ -310,27 +310,13 @@ static int test_dev_config_update_bool(const char *buf, size_t size,
  	return ret;
  }
 
-static ssize_t
-test_dev_config_show_bool(char *buf,
-			  bool config)
+static ssize_t test_dev_config_show_bool(char *buf, bool val)
  {
-	bool val;
-
-	mutex_lock(&test_fw_mutex);
-	val = config;
-	mutex_unlock(&test_fw_mutex);
-
  	return snprintf(buf, PAGE_SIZE, "%d\n", val);
  }
 
-static ssize_t test_dev_config_show_int(char *buf, int cfg)
+static ssize_t test_dev_config_show_int(char *buf, int val)
  {
-	int val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
  	return snprintf(buf, PAGE_SIZE, "%d\n", val);
  }
 
@@ -354,14 +340,8 @@ static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg)
  	return size;
  }
 
-static ssize_t test_dev_config_show_u8(char *buf, u8 cfg)
+static ssize_t test_dev_config_show_u8(char *buf, u8 val)
  {
-	u8 val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
  	return snprintf(buf, PAGE_SIZE, "%u\n", val);
  }
 
Signature · 1 line
2.17.1
Reviewed-by
#3 lore raw
Quoted 4 lines · Scott Branden

Hi Kees,

Quoted 1 line · Kees Cook

On Tue, Apr 14, 2020 at 05:25:17PM -0700, Scott Branden wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Remove unnecessary use of test_fw_mutex in test_dev_config_show_xxx functions that show simple bool, int, and u8.

I would expect at least a READ_ONCE(), yes?

I don't understand why you need a READ_ONCE when removing a mutex around an assignment
of a parameter passed into a function being assigned to a local variable.

Could you please explain your expectations.

Oops, yes, you're right. I misread and was thinking this was reading from a global. This looks fine.

-Kees

Quoted 55 lines
Quoted 54 lines
Quoted 54 lines
---
  lib/test_firmware.c | 26 +++-----------------------
  1 file changed, 3 insertions(+), 23 deletions(-)
lib/test_firmware.c +3 -23
index 0c7fbcf07ac5..9fee2b93a8d1 100644
@@ -310,27 +310,13 @@ static int test_dev_config_update_bool(const char *buf, size_t size,
  	return ret;
  }
-static ssize_t
-test_dev_config_show_bool(char *buf,
-			  bool config)
+static ssize_t test_dev_config_show_bool(char *buf, bool val)
  {
-	bool val;
-
-	mutex_lock(&test_fw_mutex);
-	val = config;
-	mutex_unlock(&test_fw_mutex);
-
  	return snprintf(buf, PAGE_SIZE, "%d\n", val);
  }
-static ssize_t test_dev_config_show_int(char *buf, int cfg)
+static ssize_t test_dev_config_show_int(char *buf, int val)
  {
-	int val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
  	return snprintf(buf, PAGE_SIZE, "%d\n", val);
  }
@@ -354,14 +340,8 @@ static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg)
  	return size;
  }
-static ssize_t test_dev_config_show_u8(char *buf, u8 cfg)
+static ssize_t test_dev_config_show_u8(char *buf, u8 val)
  {
-	u8 val;
-
-	mutex_lock(&test_fw_mutex);
-	val = cfg;
-	mutex_unlock(&test_fw_mutex);
-
  	return snprintf(buf, PAGE_SIZE, "%u\n", val);
  }
Signature · 1 line
2.17.1
Signature · 1 line
Kees Cook
Reviewed-by
#4 lore raw
Quoted 12 lines · Kees Cook
Quoted 11 lines · Scott Branden

Hi Kees,

Quoted 4 lines · Kees Cook
Quoted 2 lines · Scott Branden

Remove unnecessary use of test_fw_mutex in test_dev_config_show_xxx functions that show simple bool, int, and u8.

I would expect at least a READ_ONCE(), yes?

I don't understand why you need a READ_ONCE when removing a mutex around an assignment
of a parameter passed into a function being assigned to a local variable.

Quoted 6 lines
Quoted 1 line

Could you please explain your expectations.

Oops, yes, you're right. I misread and was thinking this was reading from a global. This looks fine.

Luis