Subject: [RFC PATCH v2 1/2] mfd: syscon: Support early initialization

From: [email-masked] (Tushar Behera)
Date: Fri, 09 May 2014 17:43:21 +0530

On 02/19/2014 04:34 PM, Michal Simek wrote:
> Some platforms need to get system controller ready as soon as
> possible. The patch provides early_syscon_initialization which
> create early mapping for all syscon compatible devices in
> early_syscon_probe. Regmap is get via
> syscon_early_regmap_lookup_by_phandle()
> 
> Regular device probes attach device to regmap via
> regmap_attach_dev().
> 
> For early syscon initialization is necessary to extend struct
> syscon and provide remove function which unmap all early init
> structures.
> 
> Signed-off-by: Michal Simek <[email-masked]> ---
> 

I don't have V3 in my mailbox, hence replying to this thread. The
content is applicable to V3.

[...]
> @@ -95,6 +98,24 @@ struct regmap
> *syscon_regmap_lookup_by_pdevname(const char *s) } 
> EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_pdevname);
> 
> +struct regmap *syscon_early_regmap_lookup_by_phandle(struct
> device_node *np, +						     const char *property) +{ +	struct
> device_node *syscon_np; +	struct syscon *syscon; + +	syscon_np =
> of_parse_phandle(np, property, 0); +	if (!syscon_np) +		return
> ERR_PTR(-ENODEV); + +	syscon = syscon_np->data; + +
> of_node_put(syscon_np); + +	return syscon->regmap;

This fails while derefencing syscon if if early_syscon_init() has not
yet been not yet been called. Something like this would be helpful.

struct regmap *regmap = ERR_PTR(-ENODEV);

syscon = syscon_np->data;
if (syscon)
	regmap = syscon->regmap;

return regmap;

- -- 
Tushar Behera