Re: [PATCH 13/14] regulator: max8925: fix not add device ifmissing init data

From: Mark Brown
Date: Thu Apr 21 2011 - 06:42:14 EST


On Wed, Apr 20, 2011 at 07:55:39PM +0800, Haojian Zhuang wrote:
> If regulator[0] is missed in init data, all regulators of max8925 won't
> be initialized.

With a changelog like this I'd expect a small change to an error check
in the startup code or something but this is a very big change to the
driver initialisation.

> +static struct regulator_init_data regulator_pdata[ARRAY_SIZE(regulator_devs)];

That looks really suspicious, what happens if there's two of these
devices in the system?

> + memcpy(&regulator_pdata[i], &pdata->regulator[i],
> + sizeof(struct regulator_init_data));
> + regulator_devs[i].platform_data = &regulator_pdata[i];
> + regulator_devs[i].pdata_size = sizeof(regulator_pdata[i]);
> + regulator_devs[i].num_resources = 1;
> + regulator_devs[i].resources = &regulator_resources[seq];
> +
> + ret = mfd_add_devices(chip->dev, 0, &regulator_devs[i], 1,
> + &regulator_resources[seq], 0);
> + if (ret < 0) {
> + dev_err(chip->dev, "Failed to add regulator subdev\n");
> + goto out;

It's really unclear why the array is needed at all if you're registering
the devices one at a time.

> - if (pdata && pdata->regulator[0]) {
> - ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
> - ARRAY_SIZE(regulator_devs),
> - &regulator_resources[0], 0);
> - if (ret < 0) {
> - dev_err(chip->dev, "Failed to add regulator subdev\n");
> - goto out_dev;
> - }

Surely the only change that's needed here is to remove the check to see
if pdata->regulator[0] is non-null?
--
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/