X86 platform drivers
 help / color / mirror / Atom feed
* [PATCH] platform/x86: system76: Reducing redundant conditional judgments in system76_add()
@ 2024-08-20  9:02 Xi Huang
  2024-08-20 11:06 ` Ilpo Järvinen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Xi Huang @ 2024-08-20  9:02 UTC (permalink / raw)
  To: jeremy, productdev, hdegoede, ilpo.jarvinen, platform-driver-x86,
	linux-kernel, xuiagnh

In case of an error, goto jumps to the “error” label,
where the if (data->has_open_ec) check is redundant in most cases.
Since the conditions for most goto statements have already
been satisfied by if (data->has_open_ec),the code has been modified to
improve execution speed.

Signed-off-by: Xi Huang <xuiagnh@gmail.com>
---
 drivers/platform/x86/system76_acpi.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c
index 3da753b3d..05b4bf18f 100644
--- a/drivers/platform/x86/system76_acpi.c
+++ b/drivers/platform/x86/system76_acpi.c
@@ -757,33 +757,34 @@ static int system76_add(struct acpi_device *acpi_dev)
 
 	err = input_register_device(data->input);
 	if (err)
-		goto error;
+		if (data->has_open_ec)
+			goto free_error;
+		else
+			return err;
 
 	if (data->has_open_ec) {
 		err = system76_get_object(data, "NFAN", &data->nfan);
 		if (err)
-			goto error;
+			goto free_error;
 
 		err = system76_get_object(data, "NTMP", &data->ntmp);
 		if (err)
-			goto error;
+			goto free_error;
 
 		data->therm = devm_hwmon_device_register_with_info(&acpi_dev->dev,
 			"system76_acpi", data, &thermal_chip_info, NULL);
 		err = PTR_ERR_OR_ZERO(data->therm);
 		if (err)
-			goto error;
+			goto free_error;
 
 		system76_battery_init();
 	}
 
 	return 0;
 
-error:
-	if (data->has_open_ec) {
-		kfree(data->ntmp);
-		kfree(data->nfan);
-	}
+free_error:
+	kfree(data->ntmp);
+	kfree(data->nfan);
 	return err;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-20 19:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-20  9:02 [PATCH] platform/x86: system76: Reducing redundant conditional judgments in system76_add() Xi Huang
2024-08-20 11:06 ` Ilpo Järvinen
2024-08-20 19:18 ` kernel test robot
2024-08-20 19:18 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox