lkml.org 
[lkml]   [2017]   [Nov]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH v2 3/3] Sony-laptop: Use common error handling code in sony_nc_setup_rfkill()
From
Date
From: Markus Elfring <elfring@users.sourceforge.net>
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@users.sourceforge.net>
---

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
\
 
 \ /
  Last update: 2017-11-01 19:50    [W:0.118 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site