Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1540121 > unrolled thread
| Started by | Arvind Yadav <arvind.yadav.cs@gmail.com> |
|---|---|
| First post | 2016-12-12 04:10 +0100 |
| Last post | 2016-12-12 19:20 +0100 |
| Articles | 8 — 5 participants |
Back to article view | Back to linux.kernel
[V2] mtd: devices: docg3:- Handle return value of devm_ioremap. Arvind Yadav <arvind.yadav.cs@gmail.com> - 2016-12-12 04:10 +0100
Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. Marek Vasut <marek.vasut@gmail.com> - 2016-12-12 05:20 +0100
Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-12-12 09:50 +0100
Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. arvind Yadav <arvind.yadav.cs@gmail.com> - 2016-12-12 17:10 +0100
Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. Robert Jarzmik <robert.jarzmik@free.fr> - 2016-12-12 17:40 +0100
Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-12-12 18:10 +0100
Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-12-12 18:10 +0100
Re: [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. arvind Yadav <arvind.yadav.cs@gmail.com> - 2016-12-12 19:20 +0100
| From | Arvind Yadav <arvind.yadav.cs@gmail.com> |
|---|---|
| Date | 2016-12-12 04:10 +0100 |
| Subject | [V2] mtd: devices: docg3:- Handle return value of devm_ioremap. |
| Message-ID | <sNpa1-7mg-9@gated-at.bofh.it> |
Here, If devm_ioremap will fail. It will return NULL.
Kernel can run into a NULL-pointer dereference.
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
drivers/mtd/devices/docg3.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index b833e6c..ffe3db0 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -2083,9 +2083,14 @@ static int __init docg3_probe(struct platform_device *pdev)
dev_err(dev, "No I/O memory resource defined\n");
return ret;
}
- base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
ret = -ENOMEM;
+ base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
+ if (!base) {
+ dev_err(dev, "failed to map I/O memory\n");
+ return ret;
+ }
+
cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,
GFP_KERNEL);
if (!cascade)
--
2.7.4
[toc] | [next] | [standalone]
| From | Marek Vasut <marek.vasut@gmail.com> |
|---|---|
| Date | 2016-12-12 05:20 +0100 |
| Message-ID | <sNqfL-83e-1@gated-at.bofh.it> |
| In reply to | #1540121 |
On 12/12/2016 04:00 AM, Arvind Yadav wrote:
> Here, If devm_ioremap will fail. It will return NULL.
> Kernel can run into a NULL-pointer dereference.
>
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/mtd/devices/docg3.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
> index b833e6c..ffe3db0 100644
> --- a/drivers/mtd/devices/docg3.c
> +++ b/drivers/mtd/devices/docg3.c
> @@ -2083,9 +2083,14 @@ static int __init docg3_probe(struct platform_device *pdev)
> dev_err(dev, "No I/O memory resource defined\n");
> return ret;
> }
> - base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
>
> ret = -ENOMEM;
> + base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
> + if (!base) {
> + dev_err(dev, "failed to map I/O memory\n");
> + return ret;
Um, return -ENOMEM right away ?
Otherwise,
Acked-by: Marek Vasut <marek.vasut@gmail.com>
> + }
> +
> cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,
> GFP_KERNEL);
> if (!cascade)
>
--
Best regards,
Marek Vasut
[toc] | [prev] | [next] | [standalone]
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Date | 2016-12-12 09:50 +0100 |
| Message-ID | <sNut4-25U-9@gated-at.bofh.it> |
| In reply to | #1540121 |
On Mon, 12 Dec 2016 08:30:04 +0530
Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:
> Here, If devm_ioremap will fail. It will return NULL.
> Kernel can run into a NULL-pointer dereference.
>
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/mtd/devices/docg3.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
> index b833e6c..ffe3db0 100644
> --- a/drivers/mtd/devices/docg3.c
> +++ b/drivers/mtd/devices/docg3.c
> @@ -2083,9 +2083,14 @@ static int __init docg3_probe(struct platform_device *pdev)
> dev_err(dev, "No I/O memory resource defined\n");
> return ret;
> }
> - base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
>
> ret = -ENOMEM;
> + base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
> + if (!base) {
> + dev_err(dev, "failed to map I/O memory\n");
> + return ret;
> + }
> +
> cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,
> GFP_KERNEL);
> if (!cascade)
How about going even further and doing the following?
This way you can drop the test on rres (it's done for you in
devm_ioremap_resource()), and you can directly return the error
returned by devm_ioremap_resource().
--->8---
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index b833e6cc684c..c59b91734344 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -2077,13 +2077,10 @@ static int __init docg3_probe(struct
platform_device *pdev) int ret, floor;
struct docg3_cascade *cascade;
- ret = -ENXIO;
ress = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!ress) {
- dev_err(dev, "No I/O memory resource defined\n");
- return ret;
- }
- base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
+ base = devm_ioremap_resource(dev, ress);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
ret = -ENOMEM;
cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,
[toc] | [prev] | [next] | [standalone]
| From | arvind Yadav <arvind.yadav.cs@gmail.com> |
|---|---|
| Date | 2016-12-12 17:10 +0100 |
| Message-ID | <sNBkR-6tz-25@gated-at.bofh.it> |
| In reply to | #1540182 |
There is problem, if you will use devm_ioremap_resource instead of
devm_ioremap,
than devm_ioremap_resource will call request_mem_region().
request_mem_region() allows to tell the kernel that this driver is going
to use
this range of I/O addresses, which will prevent other drivers to make an
overlapping call to request_mem_region If other driver want to use same
address
space to access then it will not allow. Means we can not share same
address space
between two driver.
Thanks
-Arvind
On Monday 12 December 2016 02:12 PM, Boris Brezillon wrote:
> On Mon, 12 Dec 2016 08:30:04 +0530
> Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:
>
>> Here, If devm_ioremap will fail. It will return NULL.
>> Kernel can run into a NULL-pointer dereference.
>>
>> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
>> ---
>> drivers/mtd/devices/docg3.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
>> index b833e6c..ffe3db0 100644
>> --- a/drivers/mtd/devices/docg3.c
>> +++ b/drivers/mtd/devices/docg3.c
>> @@ -2083,9 +2083,14 @@ static int __init docg3_probe(struct platform_device *pdev)
>> dev_err(dev, "No I/O memory resource defined\n");
>> return ret;
>> }
>> - base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
>>
>> ret = -ENOMEM;
>> + base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
>> + if (!base) {
>> + dev_err(dev, "failed to map I/O memory\n");
>> + return ret;
>> + }
>> +
>> cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,
>> GFP_KERNEL);
>> if (!cascade)
> How about going even further and doing the following?
> This way you can drop the test on rres (it's done for you in
> devm_ioremap_resource()), and you can directly return the error
> returned by devm_ioremap_resource().
>
> --->8---
> diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
> index b833e6cc684c..c59b91734344 100644
> --- a/drivers/mtd/devices/docg3.c
> +++ b/drivers/mtd/devices/docg3.c
> @@ -2077,13 +2077,10 @@ static int __init docg3_probe(struct
> platform_device *pdev) int ret, floor;
> struct docg3_cascade *cascade;
>
> - ret = -ENXIO;
> ress = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - if (!ress) {
> - dev_err(dev, "No I/O memory resource defined\n");
> - return ret;
> - }
> - base = devm_ioremap(dev, ress->start, DOC_IOSPACE_SIZE);
> + base = devm_ioremap_resource(dev, ress);
> + if (IS_ERR(base))
> + return PTR_ERR(base);
>
> ret = -ENOMEM;
> cascade = devm_kzalloc(dev, sizeof(*cascade) * DOC_MAX_NBFLOORS,
[toc] | [prev] | [next] | [standalone]
| From | Robert Jarzmik <robert.jarzmik@free.fr> |
|---|---|
| Date | 2016-12-12 17:40 +0100 |
| Message-ID | <sNBNU-6Du-55@gated-at.bofh.it> |
| In reply to | #1540412 |
arvind Yadav <arvind.yadav.cs@gmail.com> writes: > There is problem, if you will use devm_ioremap_resource instead of devm_ioremap, > than devm_ioremap_resource will call request_mem_region(). > request_mem_region() allows to tell the kernel that this driver is going to use > this range of I/O addresses, which will prevent other drivers to make an > overlapping call to request_mem_region If other driver want to use same address > space to access then it will not allow. Means we can not share same address > space > between two driver. Hi, You're right Arvind, and still, it's worth noticing that the docg3 access semantics imply a "reserved" resource path (see how doc_register_readb() does a write and how this cannot be shared with another driver). Therefore I'll be willing to ack a mix of your both patches, the devm_ioremap_resource() from Boris and the error message from your patch. Cheers. -- Robert
[toc] | [prev] | [next] | [standalone]
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Date | 2016-12-12 18:10 +0100 |
| Message-ID | <sNCgW-72u-31@gated-at.bofh.it> |
| In reply to | #1540447 |
On Mon, 12 Dec 2016 17:32:58 +0100 Robert Jarzmik <robert.jarzmik@free.fr> wrote: > arvind Yadav <arvind.yadav.cs@gmail.com> writes: > > > There is problem, if you will use devm_ioremap_resource instead of devm_ioremap, > > than devm_ioremap_resource will call request_mem_region(). > > request_mem_region() allows to tell the kernel that this driver is going to use > > this range of I/O addresses, which will prevent other drivers to make an > > overlapping call to request_mem_region If other driver want to use same address > > space to access then it will not allow. Means we can not share same address > > space > > between two driver. > > Hi, > > You're right Arvind, and still, it's worth noticing that the docg3 access > semantics imply a "reserved" resource path (see how doc_register_readb() does a > write and how this cannot be shared with another driver). > > Therefore I'll be willing to ack a mix of your both patches, the > devm_ioremap_resource() from Boris and the error message from your patch. devm_ioremap_resource() already prints different error messages depending on the error type [1], no need to duplicate it. [1]http://lxr.free-electrons.com/source/lib/devres.c#L134
[toc] | [prev] | [next] | [standalone]
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Date | 2016-12-12 18:10 +0100 |
| Message-ID | <sNCgW-72u-25@gated-at.bofh.it> |
| In reply to | #1540412 |
Hi Arvind, On Mon, 12 Dec 2016 21:33:05 +0530 arvind Yadav <arvind.yadav.cs@gmail.com> wrote: > There is problem, if you will use devm_ioremap_resource instead of > devm_ioremap, > than devm_ioremap_resource will call request_mem_region(). > request_mem_region() allows to tell the kernel that this driver is going > to use > this range of I/O addresses, which will prevent other drivers to make an > overlapping call to request_mem_region If other driver want to use same > address > space to access then it will not allow. Means we can not share same > address space > between two driver. The question is, is it required here? In general, allowing 2 different drivers from touching the same iomem region is a bad idea, so, if there's a reason to allow that here, I'd like to know more about it. Thanks, Boris
[toc] | [prev] | [next] | [standalone]
| From | arvind Yadav <arvind.yadav.cs@gmail.com> |
|---|---|
| Date | 2016-12-12 19:20 +0100 |
| Message-ID | <sNDmF-7Fp-5@gated-at.bofh.it> |
| In reply to | #1540463 |
Hi Boris, Yes, It's possible that two driver can use same iomem region. For example you can check commit id - : 33cf75656923ff11d67a937a4f8e9344f58cea77 Here, It's not required. Thanks -Arvind On Monday 12 December 2016 10:34 PM, Boris Brezillon wrote: > Hi Arvind, > > On Mon, 12 Dec 2016 21:33:05 +0530 > arvind Yadav <arvind.yadav.cs@gmail.com> wrote: > >> There is problem, if you will use devm_ioremap_resource instead of >> devm_ioremap, >> than devm_ioremap_resource will call request_mem_region(). >> request_mem_region() allows to tell the kernel that this driver is going >> to use >> this range of I/O addresses, which will prevent other drivers to make an >> overlapping call to request_mem_region If other driver want to use same >> address >> space to access then it will not allow. Means we can not share same >> address space >> between two driver. > The question is, is it required here? In general, allowing 2 different > drivers from touching the same iomem region is a bad idea, so, if > there's a reason to allow that here, I'd like to know more about it. > > Thanks, > > Boris
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web