Skip to contentSkip to conversation

ACPI: APEI: Remove redundant assignments in erst_dbg_{ioctl|write}()

PATCH In review Thorsten Blum 3 participants 3 messages Sep 3, 2025 – Sep 15, 2025

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

PATCH 1/1 ACPI: APEI: Remove redundant assignments in erst_dbg_{ioctl|write}()

Use the result of copy_from_user() directly instead of assigning it to the local variable 'rc' and then overwriting it in erst_dbg_write() or immediately returning from erst_dbg_ioctl().

---
 drivers/acpi/apei/erst-dbg.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/acpi/apei/erst-dbg.c +3 -5
index 246076341e8c..ff0e8bf8e97a 100644
@@ -60,9 +60,8 @@ static long erst_dbg_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 
 	switch (cmd) {
 	case APEI_ERST_CLEAR_RECORD:
-		rc = copy_from_user(&record_id, (void __user *)arg,
-				    sizeof(record_id));
-		if (rc)
+		if (copy_from_user(&record_id, (void __user *)arg,
+				   sizeof(record_id)))
 			return -EFAULT;
 		return erst_clear(record_id);
 	case APEI_ERST_GET_RECORD_COUNT:
@@ -175,8 +174,7 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
 		erst_dbg_buf = p;
 		erst_dbg_buf_len = usize;
 	}
-	rc = copy_from_user(erst_dbg_buf, ubuf, usize);
-	if (rc) {
+	if (copy_from_user(erst_dbg_buf, ubuf, usize)) {
 		rc = -EFAULT;
 		goto out;
 	}
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Thorsten Blum

Use the result of copy_from_user() directly instead of assigning it to the local variable 'rc' and then overwriting it in erst_dbg_write() or immediately returning from erst_dbg_ioctl().

---
  drivers/acpi/apei/erst-dbg.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
drivers/acpi/apei/erst-dbg.c +2 -3
index 246076341e8c..ff0e8bf8e97a 100644
@@ -60,9 +60,8 @@ static long erst_dbg_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 
  	switch (cmd) {
  	case APEI_ERST_CLEAR_RECORD:
-		rc = copy_from_user(&record_id, (void __user *)arg,
-				    sizeof(record_id));
-		if (rc)
+		if (copy_from_user(&record_id, (void __user *)arg,
+				   sizeof(record_id)))
  			return -EFAULT;
  		return erst_clear(record_id);
  	case APEI_ERST_GET_RECORD_COUNT:

drivers/acpi/apei/erst-dbg.c static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf, · line 180

Quoted 9 lines
drivers/acpi/apei/erst-dbg.c +1 -2
@@ -175,8 +174,7 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
  		erst_dbg_buf = p;
  		erst_dbg_buf_len = usize;
  	}
-	rc = copy_from_user(erst_dbg_buf, ubuf, usize);
-	if (rc) {
+	if (copy_from_user(erst_dbg_buf, ubuf, usize)) {
  		rc = -EFAULT;
  		goto out;
  	}

Hi Thorsten,
Thanks for the patch.

The changes look good to me.

Since this is a code cleanup with no functional changes, could you please mention "no functional change" or similar wording in the commit message to make it clear?

With that addressed:

Thanks,
Shuai

#2 lore raw
Quoted 43 lines · Shuai Xue
Quoted 26 lines · Thorsten Blum

Use the result of copy_from_user() directly instead of assigning it to the local variable 'rc' and then overwriting it in erst_dbg_write() or immediately returning from erst_dbg_ioctl().

---
  drivers/acpi/apei/erst-dbg.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
drivers/acpi/apei/erst-dbg.c +2 -3
index 246076341e8c..ff0e8bf8e97a 100644
@@ -60,9 +60,8 @@ static long erst_dbg_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 
      switch (cmd) {
      case APEI_ERST_CLEAR_RECORD:
-             rc = copy_from_user(&record_id, (void __user *)arg,
-                                 sizeof(record_id));
-             if (rc)
+             if (copy_from_user(&record_id, (void __user *)arg,
+                                sizeof(record_id)))
                      return -EFAULT;
              return erst_clear(record_id);
      case APEI_ERST_GET_RECORD_COUNT:

drivers/acpi/apei/erst-dbg.c static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf, · line 180

Quoted 9 lines
drivers/acpi/apei/erst-dbg.c +1 -2
@@ -175,8 +174,7 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
              erst_dbg_buf = p;
              erst_dbg_buf_len = usize;
      }
-     rc = copy_from_user(erst_dbg_buf, ubuf, usize);
-     if (rc) {
+     if (copy_from_user(erst_dbg_buf, ubuf, usize)) {
              rc = -EFAULT;
              goto out;
      }

Hi Thorsten,
Thanks for the patch.

Quoted 5 lines

The changes look good to me.

Since this is a code cleanup with no functional changes, could you please mention "no functional change" or similar wording in the commit message to make it clear?

Added.

Quoted 2 lines

With that addressed:

And patch applied as 6.18 material, thanks!