Bug 44561

Summary: Missing check of the return value of platform_device_add_data() in function pcf50633_probe()
Product: Drivers Reporter: RUC_Soft_Sec (rucsoftsec)
Component: OtherAssignee: Alan (alan)
Status: RESOLVED CODE_FIX    
Severity: normal CC: alan, florian
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.39 Subsystem:
Regression: No Bisected commit-id:

Description RUC_Soft_Sec 2012-07-12 15:13:31 UTC
Function platform_device_add_data() will return a negative number(-ENOMEM) when fails to add the platform-specific data, and its return value shall be checked before the following call to function paltform_device_add(). But in function pcf50633_probe(), at drivers/mfd/pcf50633-core.c:254, there is no checking of the return value of platform_device_add_data() at line 315, which may make the following codes run in an unexpected status.
The related codes in pcf50633_probe() are as following.
pcf50633_probe() @@drivers/mfd/pcf50633-core.c:315
 315                platform_device_add_data(pdev, &pdata->reg_init_data[i],
 316                                        sizeof(pdata->reg_init_data[i]));
 317                pcf->regulator_pdev[i] = pdev;
 318
 319                platform_device_add(pdev);

Generally, the return value of function platform_device_add_data() shall be checked to make sure that the add operation succeeds. Like the following codes in another function.
hest_parse_ghes @@drivers/acpi/apei/hest.c:153
 153        rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
 154        if (rc)
 155                goto err;
 156
 157        rc = platform_device_add(ghes_dev);
 158        if (rc)
 159                goto err;

Thank you

RUC_Soft_Sec
Comment 1 Florian Mickler 2012-08-04 19:11:00 UTC
A patch referencing this bug report has been merged in Linux v3.6-rc1:

commit 18273c5b463d9f98ef81f1a6217a7f4168dd809a
Author: Alan Cox <alan@lxorguk.ukuu.org.uk>
Date:   Fri Jul 13 16:43:32 2012 +0100

    mfd: Add missing out of memory check for pcf50633