Re: [PATCH v4 2/3] regulator: MAX77686: Add Maxim 77686 regulatordriver

From: jonghwa3 . lee
Date: Tue May 22 2012 - 00:36:38 EST


On 2012ë 05ì 22ì 06:06, David Rientjes wrote:

> On Mon, 21 May 2012, Jonghwa Lee wrote:
>> +static __devinit int max77686_pmic_probe(struct platform_device *pdev)
>> +{
>> + struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
>> + struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev);
>> + struct regulator_dev **rdev;
>> + struct max77686_data *max77686;
>> + struct regulator_init_data **init_data;
>> + int i, size;
>> + int ret = 0;
>> + struct regulator_config config;
>> + unsigned int data = 0;
>> +
>> + dev_dbg(&pdev->dev, "%s\n", __func__);
>> +
>> + max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
>> + GFP_KERNEL);
>> + if (!max77686)
>> + return -ENOMEM;
>> +
>> + size = sizeof(struct regulator_dev *) * MAX77686_REGULATORS;
>> + max77686->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
>> + if (!max77686->rdev)
>> + return -ENOMEM;
>
> Does this leak max77686?
>


It uses devm_kzalloc which automatically frees memory allocation when
the driver is detached. So we don't need to worry about it.


>> +
>> + rdev = max77686->rdev;
>> + max77686->dev = &pdev->dev;
>> + max77686->iodev = iodev;
>> + if (pdata)
>> + max77686->num_regulators = pdata->num_regulators;
>> + platform_set_drvdata(pdev, max77686);
>> + init_data = devm_kzalloc(&pdev->dev,
>> + sizeof(struct regulator_init_data *)
>> + * MAX77686_REGULATORS, GFP_KERNEL);
>
> No error handling, which will cause a NULL pointer later when you use this
> array.
>


Okay, now i applied it.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>


Thanks and Regard
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/