Skip to content

Commit 7931e28

Browse files
Lee, Chun-Yirafaeljw
authored andcommitted
thermal/int340x_thermal: handle data_vault when the value is ZERO_SIZE_PTR
In some case, the GDDV returns a package with a buffer which has zero length. It causes that kmemdup() returns ZERO_SIZE_PTR (0x10). Then the data_vault_read() got NULL point dereference problem when accessing the 0x10 value in data_vault. [ 71.024560] BUG: kernel NULL pointer dereference, address: 0000000000000010 This patch uses ZERO_OR_NULL_PTR() for checking ZERO_SIZE_PTR or NULL value in data_vault. Signed-off-by: "Lee, Chun-Yi" <jlee@suse.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 1c23f9e commit 7931e28

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/thermal/intel/int340x_thermal/int3400_thermal.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static void int3400_setup_gddv(struct int3400_thermal_priv *priv)
527527
priv->data_vault = kmemdup(obj->package.elements[0].buffer.pointer,
528528
obj->package.elements[0].buffer.length,
529529
GFP_KERNEL);
530-
if (!priv->data_vault)
530+
if (ZERO_OR_NULL_PTR(priv->data_vault))
531531
goto out_free;
532532

533533
bin_attr_data_vault.private = priv->data_vault;
@@ -597,7 +597,7 @@ static int int3400_thermal_probe(struct platform_device *pdev)
597597
goto free_imok;
598598
}
599599

600-
if (priv->data_vault) {
600+
if (!ZERO_OR_NULL_PTR(priv->data_vault)) {
601601
result = sysfs_create_group(&pdev->dev.kobj,
602602
&data_attribute_group);
603603
if (result)
@@ -615,7 +615,8 @@ static int int3400_thermal_probe(struct platform_device *pdev)
615615
free_sysfs:
616616
cleanup_odvp(priv);
617617
if (priv->data_vault) {
618-
sysfs_remove_group(&pdev->dev.kobj, &data_attribute_group);
618+
if (!ZERO_OR_NULL_PTR(priv->data_vault))
619+
sysfs_remove_group(&pdev->dev.kobj, &data_attribute_group);
619620
kfree(priv->data_vault);
620621
}
621622
free_uuid:
@@ -647,7 +648,7 @@ static int int3400_thermal_remove(struct platform_device *pdev)
647648
if (!priv->rel_misc_dev_res)
648649
acpi_thermal_rel_misc_device_remove(priv->adev->handle);
649650

650-
if (priv->data_vault)
651+
if (!ZERO_OR_NULL_PTR(priv->data_vault))
651652
sysfs_remove_group(&pdev->dev.kobj, &data_attribute_group);
652653
sysfs_remove_group(&pdev->dev.kobj, &uuid_attribute_group);
653654
sysfs_remove_group(&pdev->dev.kobj, &imok_attribute_group);

0 commit comments

Comments
 (0)