[PATCH] ibmasmfs: Use common error handling code in command_file_read()

Markus Elfring posted 1 patch 2 months, 1 week ago
drivers/misc/ibmasm/ibmasmfs.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH] ibmasmfs: Use common error handling code in command_file_read()
Posted by Markus Elfring 2 months, 1 week ago
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 18 Sep 2024 19:50:27 +0200

Add a label so that a bit of exception handling can be better reused
at the end of this function implementation.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/misc/ibmasm/ibmasmfs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index c44de892a61e..93b69f473452 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -280,14 +280,15 @@ static ssize_t command_file_read(struct file *file, char __user *buf, size_t cou
 	spin_unlock_irqrestore(&command_data->sp->lock, flags);

 	if (cmd->status != IBMASM_CMD_COMPLETE) {
-		command_put(cmd);
-		return -EIO;
+		len = -EIO;
+		goto put_command;
 	}
 	len = min(count, cmd->buffer_size);
 	if (copy_to_user(buf, cmd->buffer, len)) {
-		command_put(cmd);
-		return -EFAULT;
+		len = -EFAULT;
+		goto put_command;
 	}
+put_command:
 	command_put(cmd);

 	return len;
--
2.46.0