diff mbox series

[2/2] PCI: switchtec: Remove useless assignments in switchtec_dev_read()

Message ID 20221215182140.129559-3-helgaas@kernel.org
State New
Headers show
Series PCI: switchtec: Trivial cleanups | expand

Commit Message

Bjorn Helgaas Dec. 15, 2022, 6:21 p.m. UTC
From: Bjorn Helgaas <bhelgaas@google.com>

Some switchtec_dev_read() error cases assign to "rc", then branch to "out".
But the code at "out" never uses "rc".  Drop the useless assignments.  No
functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/switch/switchtec.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Logan Gunthorpe Dec. 15, 2022, 6:34 p.m. UTC | #1
On 2022-12-15 11:21, Bjorn Helgaas wrote:
> From: Bjorn Helgaas <bhelgaas@google.com>
> 
> Some switchtec_dev_read() error cases assign to "rc", then branch to "out".
> But the code at "out" never uses "rc".  Drop the useless assignments.  No
> functional change intended.

Ah, hmm, yes. I think if copy_to_user() fails, the function should
probably return -EFAULT. So perhaps an unlock and specific return as is
done in previous conditions in the same function?

Thanks,

Logan
Bjorn Helgaas Dec. 15, 2022, 7:07 p.m. UTC | #2
On Thu, Dec 15, 2022 at 11:34:06AM -0700, Logan Gunthorpe wrote:
> On 2022-12-15 11:21, Bjorn Helgaas wrote:
> > From: Bjorn Helgaas <bhelgaas@google.com>
> > 
> > Some switchtec_dev_read() error cases assign to "rc", then branch to "out".
> > But the code at "out" never uses "rc".  Drop the useless assignments.  No
> > functional change intended.
> 
> Ah, hmm, yes. I think if copy_to_user() fails, the function should
> probably return -EFAULT. So perhaps an unlock and specific return as is
> done in previous conditions in the same function?

Sure, I'll post a v2 that does that.
diff mbox series

Patch

diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index d7ae84070e29..c04c7ee35184 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -605,18 +605,14 @@  static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
 
 	rc = copy_to_user(data, &stuser->return_code,
 			  sizeof(stuser->return_code));
-	if (rc) {
-		rc = -EFAULT;
+	if (rc)
 		goto out;
-	}
 
 	data += sizeof(stuser->return_code);
 	rc = copy_to_user(data, &stuser->data,
 			  size - sizeof(stuser->return_code));
-	if (rc) {
-		rc = -EFAULT;
+	if (rc)
 		goto out;
-	}
 
 	stuser_set_state(stuser, MRPC_IDLE);