mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Antony Pavlov <antonynpavlov@gmail.com>
Cc: barebox@lists.infradead.org,
	Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: Re: [RFC] drivers: fix dev_request_mem_resource() usage
Date: Thu, 7 May 2020 14:03:47 +0200	[thread overview]
Message-ID: <20200507120347.GC5877@pengutronix.de> (raw)
In-Reply-To: <20200505125506.12843-1-antonynpavlov@gmail.com>

Hi Antony,

On Tue, May 05, 2020 at 03:55:06PM +0300, Antony Pavlov wrote:
> Here is the code from drivers/reset/reset-socfpga.c
> 
> > res = dev_request_mem_resource(dev, 0);
> > data->membase = IOMEM(res->start);
> > if (IS_ERR(data->membase))
> >     return PTR_ERR(data->membase);
> 
> dev_request_mem_resource(dev, 0) returns res or ERR_CASE(res)
> so we can't use IOMEM(res->start) just after
> res = dev_request_mem_resource(dev, 0) call.
> 
> Code should look like this
> 
> > res = dev_request_mem_resource(dev, 0);
> > if (IS_ERR(res))
> >     return PTR_ERR(res);
> > data->membase = IOMEM(res->start);
> 
> but if res isn't used in after that we can
> use dev_request_mem_region() instead of
> dev_request_mem_resource(), e.g.
> 
> > data->membase = dev_request_mem_region(dev, 0);
> > if (IS_ERR(data->membase))
> >     return PTR_ERR(data->membase);

The problem with dev_request_mem_region() is that the returned value
leaves no space for error codes. IS_ERR() returns false positives when
the returned region is within the last 512 bytes of the address space.
This is rare, but has happened. This is why the common pattern is to use
dev_request_mem_resource() which can fail and then convert the resource
into a pointer, which cannot fail.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2020-05-07 12:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05 12:55 Antony Pavlov
2020-05-07 12:03 ` Sascha Hauer [this message]

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=20200507120347.GC5877@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.trumtrar@pengutronix.de \
    /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