Skip to contentSkip to conversation

ACPI / sysfs: fix error code in get_status()

PATCH Applied Dan Carpenter 2 participants 2 messages May 5, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI / sysfs: fix error code in get_status()

The problem with ornamental, do-nothing gotos is that they lead to "forgot to set the error code" bugs. We should be returning -EINVAL here but we don't. It leads to an uninitalized variable in counter_show():

drivers/acpi/sysfs.c:603 counter_show()
error: uninitialized symbol 'status'.

Fixes 1c8fce27e275 ('ACPI: introduce drivers/acpi/sysfs.c')
drivers/acpi/sysfs.c +3 -4
index 0243d37..4b3a9e2 100644
@@ -555,23 +555,22 @@ static void acpi_global_event_handler(u32 event_type, acpi_handle device,
 static int get_status(u32 index, acpi_event_status *status,
 		      acpi_handle *handle)
 {
-	int result = 0;
+	int result;
 
 	if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
-		goto end;
+		return -EINVAL;
 
 	if (index < num_gpes) {
 		result = acpi_get_gpe_device(index, handle);
 		if (result) {
 			ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
 					"Invalid GPE 0x%x", index));
-			goto end;
+			return result;
 		}
 		result = acpi_get_gpe_status(*handle, index, status);
 	} else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
 		result = acpi_get_event_status(index - num_gpes, status);
 
-end:
 	return result;
 }
 
#1 lore raw
Quoted 10 lines · Dan Carpenter

The problem with ornamental, do-nothing gotos is that they lead to "forgot to set the error code" bugs. We should be returning -EINVAL here but we don't. It leads to an uninitalized variable in counter_show():

drivers/acpi/sysfs.c:603 counter_show()
error: uninitialized symbol 'status'.

Fixes 1c8fce27e275 ('ACPI: introduce drivers/acpi/sysfs.c')

Good catch!

Quoted 20 lines
drivers/acpi/sysfs.c +2 -2
index 0243d37..4b3a9e2 100644
@@ -555,23 +555,22 @@ static void acpi_global_event_handler(u32 event_type, acpi_handle device,
 static int get_status(u32 index, acpi_event_status *status,
 		      acpi_handle *handle)
 {
-	int result = 0;
+	int result;
 
 	if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
-		goto end;
+		return -EINVAL;
 
 	if (index < num_gpes) {
 		result = acpi_get_gpe_device(index, handle);
 		if (result) {
 			ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
 					"Invalid GPE 0x%x", index));

drivers/acpi/sysfs.c static void acpi_global_event_handler(u32 event_type, acpi_handle device, · line 575

Quoted 10 lines
drivers/acpi/sysfs.c +1 -2
-			goto end;
+			return result;
 		}
 		result = acpi_get_gpe_status(*handle, index, status);
 	} else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
 		result = acpi_get_event_status(index - num_gpes, status);
 
-end:
 	return result;
 }

Applied, thanks!