Skip to contentSkip to conversation

ACPICIA: kfree() NULL pointer cleanup

PATCH In review Bojan Prtvar 4 participants 4 messages Sep 7, 2013 – Sep 9, 2013

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

PATCH 1/1 ACPICIA: kfree() NULL pointer cleanup

Checking for NULL pointers before kfree() is redundant.

---
This is janitorial work, please review carefully.

 drivers/acpi/acpica/evgpeblk.c |    8 ++------
 drivers/acpi/acpica/evrgnini.c |    4 +---
 drivers/acpi/acpica/evxfgpe.c  |    4 +---
 drivers/acpi/acpica/exfldio.c  |    4 +---
 drivers/acpi/acpica/exnames.c  |    4 +---
 drivers/acpi/acpica/nsxfname.c |   16 ++++------------
 drivers/acpi/acpica/uterror.c  |    4 +---
 7 files changed, 11 insertions(+), 33 deletions(-)
drivers/acpi/acpica/evgpeblk.c +2 -6
index c1aa1ed..c25446e 100644
@@ -303,12 +303,8 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
 	return_ACPI_STATUS(AE_OK);
 
       error_exit:
-	if (gpe_register_info) {
-		ACPI_FREE(gpe_register_info);
-	}
-	if (gpe_event_info) {
-		ACPI_FREE(gpe_event_info);
-	}
+	ACPI_FREE(gpe_register_info);
+	ACPI_FREE(gpe_event_info);
 
 	return_ACPI_STATUS(status);
 }
drivers/acpi/acpica/evrgnini.c +1 -3
index 8354c4f..26b54c2 100644
@@ -193,9 +193,7 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
 
 	*region_context = NULL;
 	if (function = ACPI_REGION_DEACTIVATE) {
-		if (pci_id) {
-			ACPI_FREE(pci_id);
-		}
+		ACPI_FREE(pci_id);
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/evxfgpe.c +1 -3
index 7662f1a..271e530 100644
@@ -304,9 +304,7 @@ unlock_and_exit:
 
 	/* Delete the notify object if it was not used above */
 
-	if (new_notify) {
-		ACPI_FREE(new_notify);
-	}
+	ACPI_FREE(new_notify);
 	return_ACPI_STATUS(status);
 }
 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
drivers/acpi/acpica/exfldio.c +1 -3
index 7e0afe7..a29e4b6 100644
@@ -1005,8 +1005,6 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
       exit:
 	/* Free temporary buffer if we used one */
 
-	if (new_buffer) {
-		ACPI_FREE(new_buffer);
-	}
+	ACPI_FREE(new_buffer);
 	return_ACPI_STATUS(status);
 }
drivers/acpi/acpica/exnames.c +1 -3
index 14689de..4357121 100644
@@ -422,9 +422,7 @@ acpi_ex_get_name_string(acpi_object_type data_type,
 	}
 
 	if (ACPI_FAILURE(status)) {
-		if (name_string) {
-			ACPI_FREE(name_string);
-		}
+		ACPI_FREE(name_string);
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/nsxfname.c +4 -12
index f3a4d95..24fb89b 100644
@@ -490,18 +490,10 @@ acpi_get_object_info(acpi_handle handle,
 	status = AE_OK;
 
       cleanup:
-	if (hid) {
-		ACPI_FREE(hid);
-	}
-	if (uid) {
-		ACPI_FREE(uid);
-	}
-	if (sub) {
-		ACPI_FREE(sub);
-	}
-	if (cid_list) {
-		ACPI_FREE(cid_list);
-	}
+	ACPI_FREE(hid);
+	ACPI_FREE(uid);
+	ACPI_FREE(sub);
+	ACPI_FREE(cid_list);
 	return (status);
 }
 
drivers/acpi/acpica/uterror.c +1 -3
index 154fdca..0f97110 100644
@@ -228,9 +228,7 @@ acpi_ut_namespace_error(const char *module_name,
 			acpi_os_printf("[COULD NOT EXTERNALIZE NAME]");
 		}
 
-		if (name) {
-			ACPI_FREE(name);
-		}
+		ACPI_FREE(name);
 	}
 
 	acpi_os_printf(" Namespace lookup failure, %s",
Signature · 1 line
1.7.1
#1 lore raw
Quoted 1 line · Bojan Prtvar

Checking for NULL pointers before kfree() is redundant.

Please don't do this. The ACPICA code comes from an external code base that is automatically converted to Linux and such changes will disrupt the convertion process.

Thanks,
Rafael

Quoted 134 lines

---
This is janitorial work, please review carefully.

 drivers/acpi/acpica/evgpeblk.c |    8 ++------
 drivers/acpi/acpica/evrgnini.c |    4 +---
 drivers/acpi/acpica/evxfgpe.c  |    4 +---
 drivers/acpi/acpica/exfldio.c  |    4 +---
 drivers/acpi/acpica/exnames.c  |    4 +---
 drivers/acpi/acpica/nsxfname.c |   16 ++++------------
 drivers/acpi/acpica/uterror.c  |    4 +---
 7 files changed, 11 insertions(+), 33 deletions(-)
drivers/acpi/acpica/evgpeblk.c +2 -6
index c1aa1ed..c25446e 100644
@@ -303,12 +303,8 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
 	return_ACPI_STATUS(AE_OK);
 
       error_exit:
-	if (gpe_register_info) {
-		ACPI_FREE(gpe_register_info);
-	}
-	if (gpe_event_info) {
-		ACPI_FREE(gpe_event_info);
-	}
+	ACPI_FREE(gpe_register_info);
+	ACPI_FREE(gpe_event_info);
 
 	return_ACPI_STATUS(status);
 }
drivers/acpi/acpica/evrgnini.c +1 -3
index 8354c4f..26b54c2 100644
@@ -193,9 +193,7 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
 
 	*region_context = NULL;
 	if (function = ACPI_REGION_DEACTIVATE) {
-		if (pci_id) {
-			ACPI_FREE(pci_id);
-		}
+		ACPI_FREE(pci_id);
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/evxfgpe.c +1 -3
index 7662f1a..271e530 100644
@@ -304,9 +304,7 @@ unlock_and_exit:
 
 	/* Delete the notify object if it was not used above */
 
-	if (new_notify) {
-		ACPI_FREE(new_notify);
-	}
+	ACPI_FREE(new_notify);
 	return_ACPI_STATUS(status);
 }
 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
drivers/acpi/acpica/exfldio.c +1 -3
index 7e0afe7..a29e4b6 100644
@@ -1005,8 +1005,6 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
       exit:
 	/* Free temporary buffer if we used one */
 
-	if (new_buffer) {
-		ACPI_FREE(new_buffer);
-	}
+	ACPI_FREE(new_buffer);
 	return_ACPI_STATUS(status);
 }
drivers/acpi/acpica/exnames.c +1 -3
index 14689de..4357121 100644
@@ -422,9 +422,7 @@ acpi_ex_get_name_string(acpi_object_type data_type,
 	}
 
 	if (ACPI_FAILURE(status)) {
-		if (name_string) {
-			ACPI_FREE(name_string);
-		}
+		ACPI_FREE(name_string);
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/nsxfname.c +4 -12
index f3a4d95..24fb89b 100644
@@ -490,18 +490,10 @@ acpi_get_object_info(acpi_handle handle,
 	status = AE_OK;
 
       cleanup:
-	if (hid) {
-		ACPI_FREE(hid);
-	}
-	if (uid) {
-		ACPI_FREE(uid);
-	}
-	if (sub) {
-		ACPI_FREE(sub);
-	}
-	if (cid_list) {
-		ACPI_FREE(cid_list);
-	}
+	ACPI_FREE(hid);
+	ACPI_FREE(uid);
+	ACPI_FREE(sub);
+	ACPI_FREE(cid_list);
 	return (status);
 }
 
drivers/acpi/acpica/uterror.c +1 -3
index 154fdca..0f97110 100644
@@ -228,9 +228,7 @@ acpi_ut_namespace_error(const char *module_name,
 			acpi_os_printf("[COULD NOT EXTERNALIZE NAME]");
 		}
 
-		if (name) {
-			ACPI_FREE(name);
-		}
+		ACPI_FREE(name);
 	}
 
 	acpi_os_printf(" Namespace lookup failure, %s",
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#2 lore raw
In reply to Bojan Prtvar

drivers/acpi/acpica/evgpeblk.c acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block) · line 307

Quoted 10 lines · Bojan Prtvar

Checking for NULL pointers before kfree() is redundant.
error_exit:

drivers/acpi/acpica/evgpeblk.c +2 -6
-	if (gpe_register_info) {
-		ACPI_FREE(gpe_register_info);
-	}
-	if (gpe_event_info) {
-		ACPI_FREE(gpe_event_info);
-	}
+	ACPI_FREE(gpe_register_info);
+	ACPI_FREE(gpe_event_info);

This isn't right. If you have certain debugging turned on then ACPI_FREE() does not accept NULL pointers.

regards,
dan carpenter

#3 lore raw
In reply to Bojan Prtvar

The codes below should also be maintained in the ACPICA so that we won't introduce unwanted source differences between the Linux and the ACPICA.

Thanks and best regards
-Lv

Quoted 144 lines

-----Original Message-----
From: Bojan Prtvar [mailto:[email protected]]
Sent: Saturday, September 07, 2013 11:07 PM
To: [email protected]; [email protected]; Zheng, Lv; Moore, Robert; Guan, Chao; Tang, Feng
Cc: [email protected]; Bojan Prtvar
Subject: [PATCH] ACPICIA: kfree() NULL pointer cleanup

Checking for NULL pointers before kfree() is redundant.

---
This is janitorial work, please review carefully.

 drivers/acpi/acpica/evgpeblk.c |    8 ++------
 drivers/acpi/acpica/evrgnini.c |    4 +---
 drivers/acpi/acpica/evxfgpe.c  |    4 +---
 drivers/acpi/acpica/exfldio.c  |    4 +---
 drivers/acpi/acpica/exnames.c  |    4 +---
 drivers/acpi/acpica/nsxfname.c |   16 ++++------------
 drivers/acpi/acpica/uterror.c  |    4 +---
 7 files changed, 11 insertions(+), 33 deletions(-)
drivers/acpi/acpica/evgpeblk.c +2 -6
index c1aa1ed..c25446e 100644
@@ -303,12 +303,8 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
 	return_ACPI_STATUS(AE_OK);
 
       error_exit:
-	if (gpe_register_info) {
-		ACPI_FREE(gpe_register_info);
-	}
-	if (gpe_event_info) {
-		ACPI_FREE(gpe_event_info);
-	}
+	ACPI_FREE(gpe_register_info);
+	ACPI_FREE(gpe_event_info);
 
 	return_ACPI_STATUS(status);
 }
drivers/acpi/acpica/evrgnini.c +1 -3
index 8354c4f..26b54c2 100644
@@ -193,9 +193,7 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
 
 	*region_context = NULL;
 	if (function = ACPI_REGION_DEACTIVATE) {
-		if (pci_id) {
-			ACPI_FREE(pci_id);
-		}
+		ACPI_FREE(pci_id);
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/evxfgpe.c +1 -3
index 7662f1a..271e530 100644
@@ -304,9 +304,7 @@ unlock_and_exit:
 
 	/* Delete the notify object if it was not used above */
 
-	if (new_notify) {
-		ACPI_FREE(new_notify);
-	}
+	ACPI_FREE(new_notify);
 	return_ACPI_STATUS(status);
 }
 ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
drivers/acpi/acpica/exfldio.c +1 -3
index 7e0afe7..a29e4b6 100644
@@ -1005,8 +1005,6 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
       exit:
 	/* Free temporary buffer if we used one */
 
-	if (new_buffer) {
-		ACPI_FREE(new_buffer);
-	}
+	ACPI_FREE(new_buffer);
 	return_ACPI_STATUS(status);
 }
drivers/acpi/acpica/exnames.c +1 -3
index 14689de..4357121 100644
@@ -422,9 +422,7 @@ acpi_ex_get_name_string(acpi_object_type data_type,
 	}
 
 	if (ACPI_FAILURE(status)) {
-		if (name_string) {
-			ACPI_FREE(name_string);
-		}
+		ACPI_FREE(name_string);
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/nsxfname.c +4 -12
index f3a4d95..24fb89b 100644
@@ -490,18 +490,10 @@ acpi_get_object_info(acpi_handle handle,
 	status = AE_OK;
 
       cleanup:
-	if (hid) {
-		ACPI_FREE(hid);
-	}
-	if (uid) {
-		ACPI_FREE(uid);
-	}
-	if (sub) {
-		ACPI_FREE(sub);
-	}
-	if (cid_list) {
-		ACPI_FREE(cid_list);
-	}
+	ACPI_FREE(hid);
+	ACPI_FREE(uid);
+	ACPI_FREE(sub);
+	ACPI_FREE(cid_list);
 	return (status);
 }
 
drivers/acpi/acpica/uterror.c +1 -4
index 154fdca..0f97110 100644
@@ -228,9 +228,7 @@ acpi_ut_namespace_error(const char *module_name,
 			acpi_os_printf("[COULD NOT EXTERNALIZE NAME]");
 		}
 
-		if (name) {
-			ACPI_FREE(name);
-		}
+		ACPI_FREE(name);
 	}
 
 	acpi_os_printf(" Namespace lookup failure, %s",
--

1.7.1