Re: [RFC] drivers: fix dev_request_mem_resource() usage

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

 



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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux