Re: [PATCH v9.1] of: Provide function to request and map memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Fri, Jun 20, 2014 at 02:28:48PM +0200, Matthias Brugger wrote:
> +/*
> + * of_io_request_and_map - Requests a resource and maps the memory mapped IO
> + *			   for a given device_node
> + * @device:	the device whose io range will be mapped
> + * @index:	index of the io range
> + * @name:	name of the resource
> + *
> + * Returns a pointer to the requested and mapped memory
> + */
> +void __iomem *of_io_request_and_map(struct device_node *np, int index,
> +					char *name)
> +{
> +	struct resource res;
> +	void __iomem *mem;
> +
> +	if (of_address_to_resource(np, index, &res))
> +		return NULL;
> +
> +	if (!request_mem_region(res.start, resource_size(&res), name))
> +		return NULL;
> +
> +	mem = ioremap(res.start, resource_size(&res));
> +	if (!mem)
> +		release_mem_region(res.start, resource_size(&res));

We did this "return NULL" approach for devm_request_and_ioremap(), and
ended up not liking the number of drivers returning random error codes
on failure (despite the proper return code being documented.)  It's
worth reading the commit text for the commit introducing
devm_ioremap_resource() which replaces devm_request_and_ioremap():

commit 75096579c3ac39ddc2f8b0d9a8924eba31f4d920
Author: Thierry Reding <thierry.reding@xxxxxxxxxxxxxxxxx>
Date:   Mon Jan 21 11:08:54 2013 +0100

    lib: devres: Introduce devm_ioremap_resource()

which may help avoid repeating the same mistakes here.

-- 
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]
  Powered by Linux