linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] soc: fsl: dpio: fix dereference of pointer p before null check
@ 2020-02-21 23:11 Colin King
  2020-02-21 23:18 ` Leo Li
  2020-02-24  6:35 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2020-02-21 23:11 UTC (permalink / raw)
  To: Roy Pledge, Li Yang, Youri Querry, linuxppc-dev, linux-arm-kernel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Pointer p is currently being dereferenced before it is null
checked on a memory allocation failure check. Fix this by
checking if p is null before dereferencing it.

Addresses-Coverity: ("Dereference before null check")
Fixes: 3b2abda7d28c ("soc: fsl: dpio: Replace QMAN array mode with ring mode enqueue")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/soc/fsl/dpio/qbman-portal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/fsl/dpio/qbman-portal.c b/drivers/soc/fsl/dpio/qbman-portal.c
index 740ee0d19582..d1f49caa5b13 100644
--- a/drivers/soc/fsl/dpio/qbman-portal.c
+++ b/drivers/soc/fsl/dpio/qbman-portal.c
@@ -249,10 +249,11 @@ struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
 	u32 mask_size;
 	u32 eqcr_pi;
 
-	spin_lock_init(&p->access_spinlock);
-
 	if (!p)
 		return NULL;
+
+	spin_lock_init(&p->access_spinlock);
+
 	p->desc = d;
 	p->mc.valid_bit = QB_VALID_BIT;
 	p->sdq = 0;
-- 
2.25.0


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

* RE: [PATCH][next] soc: fsl: dpio: fix dereference of pointer p before null check
  2020-02-21 23:11 [PATCH][next] soc: fsl: dpio: fix dereference of pointer p before null check Colin King
@ 2020-02-21 23:18 ` Leo Li
  2020-02-24  6:35 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Leo Li @ 2020-02-21 23:18 UTC (permalink / raw)
  To: Colin King, Roy Pledge, Youri Querry, linuxppc-dev, linux-arm-kernel
  Cc: kernel-janitors, linux-kernel



> -----Original Message-----
> From: Colin King <colin.king@canonical.com>
> Sent: Friday, February 21, 2020 5:12 PM
> To: Roy Pledge <roy.pledge@nxp.com>; Leo Li <leoyang.li@nxp.com>; Youri
> Querry <youri.querry_1@nxp.com>; linuxppc-dev@lists.ozlabs.org; linux-
> arm-kernel@lists.infradead.org
> Cc: kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [PATCH][next] soc: fsl: dpio: fix dereference of pointer p before null
> check
> 
> From: Colin Ian King <colin.king@canonical.com>
> 
> Pointer p is currently being dereferenced before it is null checked on a
> memory allocation failure check. Fix this by checking if p is null before
> dereferencing it.
> 
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 3b2abda7d28c ("soc: fsl: dpio: Replace QMAN array mode with ring
> mode enqueue")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied for next.  Thanks.

> ---
>  drivers/soc/fsl/dpio/qbman-portal.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/fsl/dpio/qbman-portal.c
> b/drivers/soc/fsl/dpio/qbman-portal.c
> index 740ee0d19582..d1f49caa5b13 100644
> --- a/drivers/soc/fsl/dpio/qbman-portal.c
> +++ b/drivers/soc/fsl/dpio/qbman-portal.c
> @@ -249,10 +249,11 @@ struct qbman_swp *qbman_swp_init(const struct
> qbman_swp_desc *d)
>  	u32 mask_size;
>  	u32 eqcr_pi;
> 
> -	spin_lock_init(&p->access_spinlock);
> -
>  	if (!p)
>  		return NULL;
> +
> +	spin_lock_init(&p->access_spinlock);
> +
>  	p->desc = d;
>  	p->mc.valid_bit = QB_VALID_BIT;
>  	p->sdq = 0;
> --
> 2.25.0


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

* Re: [PATCH][next] soc: fsl: dpio: fix dereference of pointer p before null check
  2020-02-21 23:11 [PATCH][next] soc: fsl: dpio: fix dereference of pointer p before null check Colin King
  2020-02-21 23:18 ` Leo Li
@ 2020-02-24  6:35 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-02-24  6:35 UTC (permalink / raw)
  To: Colin King
  Cc: Roy Pledge, Li Yang, Youri Querry, linuxppc-dev,
	linux-arm-kernel, kernel-janitors, linux-kernel

On Fri, Feb 21, 2020 at 11:11:43PM +0000, Colin King wrote:
> ---
>  drivers/soc/fsl/dpio/qbman-portal.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/fsl/dpio/qbman-portal.c b/drivers/soc/fsl/dpio/qbman-portal.c
> index 740ee0d19582..d1f49caa5b13 100644
> --- a/drivers/soc/fsl/dpio/qbman-portal.c
> +++ b/drivers/soc/fsl/dpio/qbman-portal.c
> @@ -249,10 +249,11 @@ struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
>  	u32 mask_size;
>  	u32 eqcr_pi;
>  
> -	spin_lock_init(&p->access_spinlock);
> -
>  	if (!p)
>  		return NULL;
> +
> +	spin_lock_init(&p->access_spinlock);

Allocations in the declaration blog are not super common in the kernel,
but they're more bug prone.  Generally, it's not beautiful to call a
function which can fail in the allocation block.

regards,
dan carpenter


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

end of thread, other threads:[~2020-02-24  6:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-21 23:11 [PATCH][next] soc: fsl: dpio: fix dereference of pointer p before null check Colin King
2020-02-21 23:18 ` Leo Li
2020-02-24  6:35 ` Dan Carpenter

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).