[PATCH v2 3/3] Sony-laptop: Use common error handling code in sony_nc_setup_rfkill()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 1 Nov 2017 19:17:01 +0100

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

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---

v2:
This software refactoring was repeated after the error code handling was
adjusted for two function calls.

 drivers/platform/x86/sony-laptop.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index 62aa2c37b8d2..8e2ee1e221fe 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -1661,31 +1661,32 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
 		return -ENOMEM;
 
 	err = sony_call_snc_handle(sony_rfkill_handle, 0x200, &result);
-	if (err < 0) {
-		rfkill_destroy(rfk);
-		return err;
-	}
+	if (err < 0)
+		goto destroy_rfk;
+
 	hwblock = !(result & 0x1);
 
 	err = sony_call_snc_handle(sony_rfkill_handle,
 				   sony_rfkill_address[nc_type],
 				   &result);
-	if (err < 0) {
-		rfkill_destroy(rfk);
-		return err;
-	}
+	if (err < 0)
+		goto destroy_rfk;
+
 	swblock = !(result & 0x2);
 
 	rfkill_init_sw_state(rfk, swblock);
 	rfkill_set_hw_state(rfk, hwblock);
 
 	err = rfkill_register(rfk);
-	if (err) {
-		rfkill_destroy(rfk);
-		return err;
-	}
+	if (err)
+		goto destroy_rfk;
+
 	sony_rfkill_devices[nc_type] = rfk;
 	return err;
+
+destroy_rfk:
+	rfkill_destroy(rfk);
+	return err;
 }
 
 static void sony_nc_rfkill_update(void)
-- 
2.14.3




[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux