[-next] firmware: google: fix a NULL vs IS_ERR() check in cbmem_entry_probe()

Message ID 20221115091138.51614-1-wupeng58@huawei.com
State New
Headers
Series [-next] firmware: google: fix a NULL vs IS_ERR() check in cbmem_entry_probe() |

Commit Message

Peng Wu Nov. 15, 2022, 9:11 a.m. UTC
  The devm_memremap() function returns error pointers on error,
it doesn't return NULL.

Fixes: 19d54020883c ("firmware: google: Implement cbmem in sysfs driver")
Signed-off-by: Peng Wu <wupeng58@huawei.com>
---
 drivers/firmware/google/cbmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Guenter Roeck Nov. 15, 2022, 1:52 p.m. UTC | #1
On Tue, Nov 15, 2022 at 1:14 AM Peng Wu <wupeng58@huawei.com> wrote:
>
> The devm_memremap() function returns error pointers on error,
> it doesn't return NULL.
>
> Fixes: 19d54020883c ("firmware: google: Implement cbmem in sysfs driver")
> Signed-off-by: Peng Wu <wupeng58@huawei.com>

Reviewed-by: Guenter Roeck <groeck@chromium.org>

> ---
>  drivers/firmware/google/cbmem.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/firmware/google/cbmem.c b/drivers/firmware/google/cbmem.c
> index 685f3070ce9d..88e587ba1e0d 100644
> --- a/drivers/firmware/google/cbmem.c
> +++ b/drivers/firmware/google/cbmem.c
> @@ -106,8 +106,8 @@ static int cbmem_entry_probe(struct coreboot_device *dev)
>         entry->mem_file_buf = devm_memremap(&dev->dev, dev->cbmem_entry.address,
>                                             dev->cbmem_entry.entry_size,
>                                             MEMREMAP_WB);
> -       if (!entry->mem_file_buf)
> -               return -ENOMEM;
> +       if (IS_ERR(entry->mem_file_buf))
> +               return PTR_ERR(entry->mem_file_buf);
>
>         entry->size = dev->cbmem_entry.entry_size;
>
> --
> 2.17.1
>
  
Jack Rosenthal Nov. 15, 2022, 5:01 p.m. UTC | #2
On 2022-11-15 at 09:11 +0000, Peng Wu wrote:
> The devm_memremap() function returns error pointers on error,
> it doesn't return NULL.
> 
> Fixes: 19d54020883c ("firmware: google: Implement cbmem in sysfs driver")
> Signed-off-by: Peng Wu <wupeng58@huawei.com>

Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>

> ---
>  drivers/firmware/google/cbmem.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/google/cbmem.c b/drivers/firmware/google/cbmem.c
> index 685f3070ce9d..88e587ba1e0d 100644
> --- a/drivers/firmware/google/cbmem.c
> +++ b/drivers/firmware/google/cbmem.c
> @@ -106,8 +106,8 @@ static int cbmem_entry_probe(struct coreboot_device *dev)
>  	entry->mem_file_buf = devm_memremap(&dev->dev, dev->cbmem_entry.address,
>  					    dev->cbmem_entry.entry_size,
>  					    MEMREMAP_WB);
> -	if (!entry->mem_file_buf)
> -		return -ENOMEM;
> +	if (IS_ERR(entry->mem_file_buf))
> +		return PTR_ERR(entry->mem_file_buf);
>  
>  	entry->size = dev->cbmem_entry.entry_size;
>  
> -- 
> 2.17.1
>
  

Patch

diff --git a/drivers/firmware/google/cbmem.c b/drivers/firmware/google/cbmem.c
index 685f3070ce9d..88e587ba1e0d 100644
--- a/drivers/firmware/google/cbmem.c
+++ b/drivers/firmware/google/cbmem.c
@@ -106,8 +106,8 @@  static int cbmem_entry_probe(struct coreboot_device *dev)
 	entry->mem_file_buf = devm_memremap(&dev->dev, dev->cbmem_entry.address,
 					    dev->cbmem_entry.entry_size,
 					    MEMREMAP_WB);
-	if (!entry->mem_file_buf)
-		return -ENOMEM;
+	if (IS_ERR(entry->mem_file_buf))
+		return PTR_ERR(entry->mem_file_buf);
 
 	entry->size = dev->cbmem_entry.entry_size;