diff mbox

devm_memremap: Fix error value when memremap failed

Message ID 1454722827-15744-1-git-send-email-toshi.kani@hpe.com (mailing list archive)
State Accepted
Commit 93f834df9c2d
Headers show

Commit Message

Kani, Toshi Feb. 6, 2016, 1:40 a.m. UTC
devm_memremap() returns an ERR_PTR() value in case of error.
However, it returns NULL when memremap() failed.  This causes
the caller, such as the pmem driver, to proceed and oops later.

Change devm_memremap() to return ERR_PTR(-ENXIO) when memremap()
failed.

Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 kernel/memremap.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ross Zwisler Feb. 6, 2016, 1:24 a.m. UTC | #1
On Fri, Feb 05, 2016 at 06:40:27PM -0700, Toshi Kani wrote:
> devm_memremap() returns an ERR_PTR() value in case of error.
> However, it returns NULL when memremap() failed.  This causes
> the caller, such as the pmem driver, to proceed and oops later.
> 
> Change devm_memremap() to return ERR_PTR(-ENXIO) when memremap()
> failed.
> 
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>

Yep, good catch.

Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>

> ---
>  kernel/memremap.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/memremap.c b/kernel/memremap.c
> index 70ee377..3427cca 100644
> --- a/kernel/memremap.c
> +++ b/kernel/memremap.c
> @@ -136,8 +136,10 @@ void *devm_memremap(struct device *dev, resource_size_t offset,
>  	if (addr) {
>  		*ptr = addr;
>  		devres_add(dev, ptr);
> -	} else
> +	} else {
>  		devres_free(ptr);
> +		return ERR_PTR(-ENXIO);
> +	}
>  
>  	return addr;
>  }
> _______________________________________________
> Linux-nvdimm mailing list
> Linux-nvdimm@lists.01.org
> https://lists.01.org/mailman/listinfo/linux-nvdimm
Dan Williams Feb. 6, 2016, 1:49 a.m. UTC | #2
On Fri, Feb 5, 2016 at 5:40 PM, Toshi Kani <toshi.kani@hpe.com> wrote:
> devm_memremap() returns an ERR_PTR() value in case of error.
> However, it returns NULL when memremap() failed.  This causes
> the caller, such as the pmem driver, to proceed and oops later.
>
> Change devm_memremap() to return ERR_PTR(-ENXIO) when memremap()
> failed.
>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>

Acked-by: Dan Williams <dan.j.williams@intel.com>
Dan Williams Feb. 6, 2016, 1:52 a.m. UTC | #3
On Fri, Feb 5, 2016 at 5:49 PM, Dan Williams <dan.j.williams@intel.com> wrote:
> On Fri, Feb 5, 2016 at 5:40 PM, Toshi Kani <toshi.kani@hpe.com> wrote:
>> devm_memremap() returns an ERR_PTR() value in case of error.
>> However, it returns NULL when memremap() failed.  This causes
>> the caller, such as the pmem driver, to proceed and oops later.
>>
>> Change devm_memremap() to return ERR_PTR(-ENXIO) when memremap()
>> failed.
>>
>> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
>> Cc: Dan Williams <dan.j.williams@intel.com>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>
> Acked-by: Dan Williams <dan.j.williams@intel.com>

Should also go to -stable, I'll add that and include this with some
other fixes I have brewing.
diff mbox

Patch

diff --git a/kernel/memremap.c b/kernel/memremap.c
index 70ee377..3427cca 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -136,8 +136,10 @@  void *devm_memremap(struct device *dev, resource_size_t offset,
 	if (addr) {
 		*ptr = addr;
 		devres_add(dev, ptr);
-	} else
+	} else {
 		devres_free(ptr);
+		return ERR_PTR(-ENXIO);
+	}
 
 	return addr;
 }