devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Matthias Brugger <matthias.bgg@gmail.com>
Cc: linux-kernel@vger.kernel.org, robh+dt@kernel.org,
	pawel.moll@arm.com, mark.rutland@arm.com,
	ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
	rdunlap@infradead.org, daniel.lezcano@linaro.org,
	tglx@linutronix.de, grant.likely@linaro.org,
	thierry.reding@gmail.com, florian.vaussard@epfl.ch,
	jic23@kernel.org, jason@lakedaemon.net, andrew@lunn.ch,
	silvio.fricke@gmail.com, heiko.stuebner@bq.com, olof@lixom.net,
	sebastian.hesselbarth@gmail.com, sboyd@codeaurora.org,
	gregory.clement@free-electrons.com, arnd@arndb.de,
	robherring2@gmail.com, marc.zyngier@arm.com,
	maxime.ripard@free-electrons.com, soren.brinkmann@xilinx.com,
	shawn.guo@freescale.com, anders.berg@lsi.com,
	linus.walleij@linaro.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v9.1] of: Provide function to request and map memory
Date: Fri, 20 Jun 2014 17:00:22 +0100	[thread overview]
Message-ID: <20140620160022.GV32514@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1403267328-23085-1-git-send-email-matthias.bgg@gmail.com>

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@avionic-design.de>
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.

  reply	other threads:[~2014-06-20 16:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-20 11:48 [PATCH v9 0/3] arm: Add basic support for Mediatek Cortex-A7 SoCs Matthias Brugger
     [not found] ` <1403264929-21325-1-git-send-email-matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-20 11:48   ` [PATCH v9 1/3] of: Provide function to request and map memory Matthias Brugger
2014-06-20 12:28     ` [PATCH v9.1] " Matthias Brugger
2014-06-20 16:00       ` Russell King - ARM Linux [this message]
2014-06-20 11:48 ` [PATCH v9 2/3] clocksource: Add support for the Mediatek SoCs Matthias Brugger
2014-06-20 11:48 ` [PATCH v9 3/3] dt-bindings: add mtk-timer bindings Matthias Brugger
2014-06-20 12:36   ` Mark Rutland
2014-07-01 17:46     ` Matthias Brugger
2014-07-01 18:00       ` Sören Brinkmann
2014-07-05  0:28         ` Matthias Brugger
2014-07-07 15:49           ` Sören Brinkmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140620160022.GV32514@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=anders.berg@lsi.com \
    --cc=andrew@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=florian.vaussard@epfl.ch \
    --cc=galak@codeaurora.org \
    --cc=grant.likely@linaro.org \
    --cc=gregory.clement@free-electrons.com \
    --cc=heiko.stuebner@bq.com \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=jason@lakedaemon.net \
    --cc=jic23@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=maxime.ripard@free-electrons.com \
    --cc=olof@lixom.net \
    --cc=pawel.moll@arm.com \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=robherring2@gmail.com \
    --cc=sboyd@codeaurora.org \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=shawn.guo@freescale.com \
    --cc=silvio.fricke@gmail.com \
    --cc=soren.brinkmann@xilinx.com \
    --cc=tglx@linutronix.de \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).