linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: kpc2000: kpc2000_spi: Check for null pointer after calling devm_ioremap
@ 2022-01-06  9:22 Jiasheng Jiang
  2022-01-06 14:01 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2022-01-06  9:22 UTC (permalink / raw)
  To: gregkh, knv418; +Cc: linux-staging, linux-kernel, Jiasheng Jiang

As the possible failure of the allocation, the devm_ioremap() may return
NULL pointer.
Then the kpspi->base is assigned to cs->base in kp_spi_setup() and used
in kp_spi_read_reg() and kp_spi_write_reg().
Therefore, it should be better to add the sanity check and return error
in order to avoid the dereference of the NULL pointer.

Fixes: 677b993a5749 ("staging: kpc2000: kpc_spi: use devm_* API to manage mapped I/O space")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/staging/kpc2000/kpc2000_spi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
index 16ca18b8aa15..ead4aa0c988c 100644
--- a/drivers/staging/kpc2000/kpc2000_spi.c
+++ b/drivers/staging/kpc2000/kpc2000_spi.c
@@ -466,6 +466,10 @@ kp_spi_probe(struct platform_device *pldev)
 
 	kpspi->base = devm_ioremap(&pldev->dev, r->start,
 				   resource_size(r));
+	if (!kpspi->base) {
+		status = -ENOMEM;
+		goto free_master;
+	}
 
 	status = spi_register_master(master);
 	if (status < 0) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: kpc2000: kpc2000_spi: Check for null pointer after calling devm_ioremap
  2022-01-06  9:22 [PATCH] staging: kpc2000: kpc2000_spi: Check for null pointer after calling devm_ioremap Jiasheng Jiang
@ 2022-01-06 14:01 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-01-06 14:01 UTC (permalink / raw)
  To: Jiasheng Jiang; +Cc: knv418, linux-staging, linux-kernel

On Thu, Jan 06, 2022 at 05:22:57PM +0800, Jiasheng Jiang wrote:
> As the possible failure of the allocation, the devm_ioremap() may return
> NULL pointer.
> Then the kpspi->base is assigned to cs->base in kp_spi_setup() and used
> in kp_spi_read_reg() and kp_spi_write_reg().
> Therefore, it should be better to add the sanity check and return error
> in order to avoid the dereference of the NULL pointer.
> 
> Fixes: 677b993a5749 ("staging: kpc2000: kpc_spi: use devm_* API to manage mapped I/O space")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/staging/kpc2000/kpc2000_spi.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
> index 16ca18b8aa15..ead4aa0c988c 100644
> --- a/drivers/staging/kpc2000/kpc2000_spi.c
> +++ b/drivers/staging/kpc2000/kpc2000_spi.c
> @@ -466,6 +466,10 @@ kp_spi_probe(struct platform_device *pldev)
>  
>  	kpspi->base = devm_ioremap(&pldev->dev, r->start,
>  				   resource_size(r));
> +	if (!kpspi->base) {
> +		status = -ENOMEM;
> +		goto free_master;
> +	}
>  
>  	status = spi_register_master(master);
>  	if (status < 0) {
> -- 
> 2.25.1
> 
> 


Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch did not apply to any known trees that Greg is in control
  of.  Possibly this is because you made it against Linus's tree, not
  the linux-next tree, which is where all of the development for the
  next version of the kernel is at.  Please refresh your patch against
  the linux-next tree, or even better yet, the development tree
  specified in the MAINTAINERS file for the subsystem you are submitting
  a patch for, and resend it.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-06 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-06  9:22 [PATCH] staging: kpc2000: kpc2000_spi: Check for null pointer after calling devm_ioremap Jiasheng Jiang
2022-01-06 14:01 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).