ACPI, APEI, HEST Fix the unsuitable usage of platform_data.
PATCH 4/4 ACPI, APEI, HEST Fix the unsuitable usage of platform_data.
platform_data in hest_parse_ghes() is used for saving the address of entry information of erst_tab. When the device is failed to be added, platform_data will be freed by platform_device_put(). But the value saved in platform_data should not be freed here. If it is done, it will make system panic.
So I think platform_data should save the address of allocated memory which saves entry information of erst_tab.
This patch fixed it and I confirmed it on x86_64 next-tree.
--- drivers/acpi/apei/ghes.c | 2 +- drivers/acpi/apei/hest.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-)
drivers/acpi/apei/ghes.c +1 -1
@@ -302,7 +302,7 @@ static int __devinit ghes_probe(struct platform_device *ghes_dev)struct ghes *ghes =NULL ;int rc = -EINVAL ; - generic = ghes_dev->dev.platform_data; + generic = *(struct acpi_hest_generic **)(ghes_dev->dev.platform_data);if (!generic->enabled)return -ENODEV ;
drivers/acpi/apei/hest.c +14 -5
@@ -137,20 +137,29 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)static int hest_parse_ghes (struct acpi_hest_header *hest_hdr,void *data) { -struct acpi_hest_generic *generic; +void **platform_data;struct platform_device *ghes_dev;struct ghes_arr *ghes_arr = data;int rc;if (hest_hdr->type !=ACPI_HEST_TYPE_GENERIC_ERROR )return 0 ; - generic = (struct acpi_hest_generic *)hest_hdr; -if (!generic->enabled) + + platform_data =kmalloc (sizeof (void *),GFP_KERNEL ); +if (!platform_data) +return -ENOMEM ; + + *platform_data = hest_hdr; +if (!((struct acpi_hest_generic *)*platform_data)->enabled)return 0 ; + ghes_dev =platform_device_alloc ("GHES" , hest_hdr->source_id); -if (!ghes_dev) +if (!ghes_dev) { +kfree (platform_data);return -ENOMEM ; - ghes_dev->dev.platform_data = generic; + } + + ghes_dev->dev.platform_data = platform_data; rc =platform_device_add (ghes_dev);if (rc) goto err;
Signature · 1 line
1.7.1.1
Quoted 4 lines · Jin Dongming
platform_datainhest_parse_ghes()is used for saving the address of entry information oferst_tab. When the device is failed to be added,platform_datawill be freed byplatform_device_put(). But the value saved inplatform_datashould not be freed here. If it is done, it will make system panic.
Good catch. Thanks.
Quoted 53 lines
So I think
platform_datashould save the address of allocated memory which saves entry information oferst_tab.This patch fixed it and I confirmed it on
x86_64next-tree.Signed-off-by Jin Dongming <[email protected]>--- drivers/acpi/apei/ghes.c | 2 +- drivers/acpi/apei/hest.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-)drivers/acpi/apei/ghes.c +1
-1@@ -302,7 +302,7 @@ static int __devinit ghes_probe(struct platform_device *ghes_dev)struct ghes *ghes =NULL ;int rc = -EINVAL ; - generic = ghes_dev->dev.platform_data; + generic = *(struct acpi_hest_generic **)(ghes_dev->dev.platform_data);if (!generic->enabled)return -ENODEV ;drivers/acpi/apei/hest.c +9
-4@@ -137,20 +137,29 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)static int hest_parse_ghes (struct acpi_hest_header *hest_hdr,void *data) { -struct acpi_hest_generic *generic; +void **platform_data;struct platform_device *ghes_dev;struct ghes_arr *ghes_arr = data;int rc;if (hest_hdr->type !=ACPI_HEST_TYPE_GENERIC_ERROR )return 0 ; - generic = (struct acpi_hest_generic *)hest_hdr; -if (!generic->enabled) + + platform_data =kmalloc (sizeof (void *),GFP_KERNEL ); +if (!platform_data) +return -ENOMEM ; + + *platform_data = hest_hdr; +if (!((struct acpi_hest_generic *)*platform_data)->enabled)return 0 ; + ghes_dev =platform_device_alloc ("GHES" , hest_hdr->source_id); -if (!ghes_dev)
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 165
Quoted 10 lines
drivers/acpi/apei/hest.c +5
-1+if (!ghes_dev) { +kfree (platform_data);return -ENOMEM ; - ghes_dev->dev.platform_data = generic; + } + + ghes_dev->dev.platform_data = platform_data; rc =platform_device_add (ghes_dev);if (rc) goto err;
Why not use platform_device_add_data?
Best Regards,
Huang Ying
Quoted 65 lines · Huang Ying
Quoted 4 lines · Jin Dongming
platform_datainhest_parse_ghes()is used for saving the address of entry information oferst_tab. When the device is failed to be added,platform_datawill be freed byplatform_device_put(). But the value saved inplatform_datashould not be freed here. If it is done, it will make system panic.Good catch. Thanks.
Quoted 57 lines
So I think
platform_datashould save the address of allocated memory which saves entry information oferst_tab.This patch fixed it and I confirmed it on
x86_64next-tree.Signed-off-by Jin Dongming <[email protected]>--- drivers/acpi/apei/ghes.c | 2 +- drivers/acpi/apei/hest.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-)drivers/acpi/apei/ghes.c +1
-1@@ -302,7 +302,7 @@ static int __devinit ghes_probe(struct platform_device *ghes_dev)struct ghes *ghes =NULL ;int rc = -EINVAL ; - generic = ghes_dev->dev.platform_data; + generic = *(struct acpi_hest_generic **)(ghes_dev->dev.platform_data);if (!generic->enabled)return -ENODEV ;drivers/acpi/apei/hest.c +11
-5@@ -137,20 +137,29 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)static int hest_parse_ghes (struct acpi_hest_header *hest_hdr,void *data) { -struct acpi_hest_generic *generic; +void **platform_data;struct platform_device *ghes_dev;struct ghes_arr *ghes_arr = data;int rc;if (hest_hdr->type !=ACPI_HEST_TYPE_GENERIC_ERROR )return 0 ; - generic = (struct acpi_hest_generic *)hest_hdr; -if (!generic->enabled) + + platform_data =kmalloc (sizeof (void *),GFP_KERNEL ); +if (!platform_data) +return -ENOMEM ; + + *platform_data = hest_hdr; +if (!((struct acpi_hest_generic *)*platform_data)->enabled)return 0 ; + ghes_dev =platform_device_alloc ("GHES" , hest_hdr->source_id); -if (!ghes_dev) +if (!ghes_dev) { +kfree (platform_data);return -ENOMEM ; - ghes_dev->dev.platform_data = generic;
Quoted 8 lines
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 165
Quoted 6 lines
drivers/acpi/apei/hest.c +3
-0+ } + + ghes_dev->dev.platform_data = platform_data; rc =platform_device_add (ghes_dev);if (rc) goto err;Why not use
platform_device_add_data?
Here what should be done is to transport the pointer of hest_hdr to platform_data, so I think that it could be done successfully by allocating 8byte of memory. If the platform_device_add_data() is used, the more memory will be allocated.
So I think this method is better than using platform_device_add_data().
Quoted 12 lines
Best Regards,
Huang Ying--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 6 lines · Jin Dongming
Quoted 1 line
Why not use
platform_device_add_data?Here what should be done is to transport the pointer of
hest_hdrtoplatform_data, so I think that it could be done successfully by allocating 8byte of memory. If theplatform_device_add_data()is used, the more memory will be allocated.So I think this method is better than using
platform_device_add_data().
You can specify allocation size for platform_device_add_data(), so no more memory will be allocated.
Best Regards,
Huang Ying
Quoted 6 lines · Huang Ying
Quoted 5 lines · Jin Dongming
Quoted 1 line
Why not use
platform_device_add_data?Here what should be done is to transport the pointer of
hest_hdrtoplatform_data, so I think that it could be done successfully by allocating 8byte of memory. If theplatform_device_add_data()is used, the more memory will be allocated.
Quoted 7 lines
Quoted 1 line
So I think this method is better than using
platform_device_add_data().You can specify allocation size for
platform_device_add_data(), so no more memory will be allocated.Best Regards,
Huang Ying
I am sorry for replying late.
I will modify my patch and resend it again.
Best Regards,
Jin Dongming
Quoted 9 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/