public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines
@ 2021-10-20  3:23 Aubrey Li
  2021-10-20  3:23 ` [PATCH v1 2/2] ACPI/PRM: Handle memory allocation and memory remap failure Aubrey Li
  2021-10-26 13:30 ` [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Aubrey Li @ 2021-10-20  3:23 UTC (permalink / raw)
  To: rjw, lenb; +Cc: linux-acpi, linux-kernel, Aubrey Li, Aubrey Li

Just remove unnecessary blank lines, no other code changes

Signed-off-by: Aubrey Li <aubrey.li@linux.intel.com>
---
 drivers/acpi/prmt.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c
index 89c22bc..aa02221 100644
--- a/drivers/acpi/prmt.c
+++ b/drivers/acpi/prmt.c
@@ -49,7 +49,6 @@ struct prm_context_buffer {
 };
 #pragma pack()
 
-
 static LIST_HEAD(prm_module_list);
 
 struct prm_handler_info {
@@ -73,7 +72,6 @@ struct prm_module_info {
 	struct prm_handler_info handlers[];
 };
 
-
 static u64 efi_pa_va_lookup(u64 pa)
 {
 	efi_memory_desc_t *md;
@@ -88,7 +86,6 @@ static u64 efi_pa_va_lookup(u64 pa)
 	return 0;
 }
 
-
 #define get_first_handler(a) ((struct acpi_prmt_handler_info *) ((char *) (a) + a->handler_info_offset))
 #define get_next_handler(a) ((struct acpi_prmt_handler_info *) (sizeof(struct acpi_prmt_handler_info) + (char *) a))
 
@@ -171,7 +168,6 @@ static void *find_guid_info(const guid_t *guid, u8 mode)
 	return NULL;
 }
 
-
 static struct prm_module_info *find_prm_module(const guid_t *guid)
 {
 	return (struct prm_module_info *)find_guid_info(guid, GET_MODULE);
-- 
2.7.4


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

* [PATCH v1 2/2] ACPI/PRM: Handle memory allocation and memory remap failure
  2021-10-20  3:23 [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines Aubrey Li
@ 2021-10-20  3:23 ` Aubrey Li
  2021-10-26 13:30 ` [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Aubrey Li @ 2021-10-20  3:23 UTC (permalink / raw)
  To: rjw, lenb; +Cc: linux-acpi, linux-kernel, Aubrey Li, Aubrey Li

Handle memory allocation and memory remap failure in acpi_parse_prmt()
when system runs out of memory to avoid the potential NULL pointer
dereference errors.

Signed-off-by: Aubrey Li <aubrey.li@linux.intel.com>
---
 drivers/acpi/prmt.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c
index aa02221..4d3a219 100644
--- a/drivers/acpi/prmt.c
+++ b/drivers/acpi/prmt.c
@@ -96,7 +96,7 @@ acpi_parse_prmt(union acpi_subtable_headers *header, const unsigned long end)
 	struct acpi_prmt_handler_info *handler_info;
 	struct prm_handler_info *th;
 	struct prm_module_info *tm;
-	u64 mmio_count = 0;
+	u64 *mmio_count;
 	u64 cur_handler = 0;
 	u32 module_info_size = 0;
 	u64 mmio_range_size = 0;
@@ -105,6 +105,8 @@ acpi_parse_prmt(union acpi_subtable_headers *header, const unsigned long end)
 	module_info = (struct acpi_prmt_module_info *) header;
 	module_info_size = struct_size(tm, handlers, module_info->handler_info_count);
 	tm = kmalloc(module_info_size, GFP_KERNEL);
+	if (!tm)
+		goto parse_prmt_out1;
 
 	guid_copy(&tm->guid, (guid_t *) module_info->module_guid);
 	tm->major_rev = module_info->major_rev;
@@ -117,14 +119,24 @@ acpi_parse_prmt(union acpi_subtable_headers *header, const unsigned long end)
 		 * Each module is associated with a list of addr
 		 * ranges that it can use during the service
 		 */
-		mmio_count = *(u64 *) memremap(module_info->mmio_list_pointer, 8, MEMREMAP_WB);
-		mmio_range_size = struct_size(tm->mmio_info, addr_ranges, mmio_count);
+		mmio_count = (u64 *) memremap(module_info->mmio_list_pointer, 8, MEMREMAP_WB);
+		if (!mmio_count)
+			goto parse_prmt_out2;
+
+		mmio_range_size = struct_size(tm->mmio_info, addr_ranges, *mmio_count);
 		tm->mmio_info = kmalloc(mmio_range_size, GFP_KERNEL);
+		if (!tm->mmio_info)
+			goto parse_prmt_out3;
+
 		temp_mmio = memremap(module_info->mmio_list_pointer, mmio_range_size, MEMREMAP_WB);
+		if (!temp_mmio)
+			goto parse_prmt_out4;
 		memmove(tm->mmio_info, temp_mmio, mmio_range_size);
 	} else {
-		mmio_range_size = struct_size(tm->mmio_info, addr_ranges, mmio_count);
-		tm->mmio_info = kmalloc(mmio_range_size, GFP_KERNEL);
+		tm->mmio_info = kmalloc(sizeof(*tm->mmio_info), GFP_KERNEL);
+		if (!tm->mmio_info)
+			goto parse_prmt_out2;
+
 		tm->mmio_info->mmio_count = 0;
 	}
 
@@ -142,6 +154,15 @@ acpi_parse_prmt(union acpi_subtable_headers *header, const unsigned long end)
 	} while (++cur_handler < tm->handler_count && (handler_info = get_next_handler(handler_info)));
 
 	return 0;
+
+parse_prmt_out4:
+	kfree(tm->mmio_info);
+parse_prmt_out3:
+	memunmap(mmio_count);
+parse_prmt_out2:
+	kfree(tm);
+parse_prmt_out1:
+	return -ENOMEM;
 }
 
 #define GET_MODULE	0
-- 
2.7.4


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

* Re: [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines
  2021-10-20  3:23 [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines Aubrey Li
  2021-10-20  3:23 ` [PATCH v1 2/2] ACPI/PRM: Handle memory allocation and memory remap failure Aubrey Li
@ 2021-10-26 13:30 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2021-10-26 13:30 UTC (permalink / raw)
  To: Aubrey Li
  Cc: Rafael J. Wysocki, Len Brown, ACPI Devel Maling List,
	Linux Kernel Mailing List, Aubrey Li

On Wed, Oct 20, 2021 at 5:23 AM Aubrey Li <aubrey.li@intel.com> wrote:
>
> Just remove unnecessary blank lines, no other code changes
>
> Signed-off-by: Aubrey Li <aubrey.li@linux.intel.com>
> ---
>  drivers/acpi/prmt.c | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c
> index 89c22bc..aa02221 100644
> --- a/drivers/acpi/prmt.c
> +++ b/drivers/acpi/prmt.c
> @@ -49,7 +49,6 @@ struct prm_context_buffer {
>  };
>  #pragma pack()
>
> -
>  static LIST_HEAD(prm_module_list);
>
>  struct prm_handler_info {
> @@ -73,7 +72,6 @@ struct prm_module_info {
>         struct prm_handler_info handlers[];
>  };
>
> -
>  static u64 efi_pa_va_lookup(u64 pa)
>  {
>         efi_memory_desc_t *md;
> @@ -88,7 +86,6 @@ static u64 efi_pa_va_lookup(u64 pa)
>         return 0;
>  }
>
> -
>  #define get_first_handler(a) ((struct acpi_prmt_handler_info *) ((char *) (a) + a->handler_info_offset))
>  #define get_next_handler(a) ((struct acpi_prmt_handler_info *) (sizeof(struct acpi_prmt_handler_info) + (char *) a))
>
> @@ -171,7 +168,6 @@ static void *find_guid_info(const guid_t *guid, u8 mode)
>         return NULL;
>  }
>
> -
>  static struct prm_module_info *find_prm_module(const guid_t *guid)
>  {
>         return (struct prm_module_info *)find_guid_info(guid, GET_MODULE);
> --

Applied as 5.16 material along with the [2/2], thanks!

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

end of thread, other threads:[~2021-10-26 13:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-20  3:23 [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines Aubrey Li
2021-10-20  3:23 ` [PATCH v1 2/2] ACPI/PRM: Handle memory allocation and memory remap failure Aubrey Li
2021-10-26 13:30 ` [PATCH v1 1/2] ACPI/PRM: Remove unnecessary blank lines Rafael J. Wysocki

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