Re: [PATCH] max8907: fix use of possibly NULL idata

From: Stephen Warren
Date: Thu Aug 23 2012 - 14:25:17 EST


On 08/23/2012 12:19 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren@xxxxxxxxxx>
>
> If a regulator is not used by a board, it's quite legitimate not to
> provide platform data or a device tree node to configure it (i.e.
> regulator_init_data). In that case, during MAX8907 regulator's
> probe(), the idata variable will be NULL for that regulator. Prevent
> dereferincing it.
>
> If the MBATT regulator's init_data is not specified, or no name was
> specified in the constraints, the regulator will be named based on
> the regulator descriptor, so initialize mbatt_rail_name from there.

Laxman,

The TPS6586x driver avoids this NULL-dereference issue by simply not
registering any regulators when idata is NULL. See
drivers/mfd/tps6586x.c:tps6586x_parse_dt():

> for (i = 0, j = 0; i < num && j < count; i++) {
> struct regulator_init_data *reg_idata;
>
> if (!tps6586x_matches[i].init_data)
> continue;

If I interpreted Mark Brown correctly, this isn't correct; all the
regulators within the chip should always be registered, just without any
user-supplied constraints. Assuming I didn't misinterpret Mark, can you
please fix the TPS6586x driver to always register the regulators, and
apply the fix below. Could you please check the TPS65911 driver and see
what the status is there too? Thanks very much!
--
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/