driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: kpc2000: replace assertion with recovery code
@ 2019-12-15 18:12 Aditya Pakki
  2019-12-15 18:28 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Aditya Pakki @ 2019-12-15 18:12 UTC (permalink / raw)
  To: pakki001
  Cc: devel, Vandana BN, Harsh Jain, Greg Kroah-Hartman, kjlu,
	linux-kernel, Simon Sandström

In kpc_dma_transfer, if either priv or ldev is NULL, crashing the
process is excessive and is not needed. Instead of asserting, by
passing the error upstream, the error can be handled.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/staging/kpc2000/kpc_dma/fileops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kpc2000/kpc_dma/fileops.c
index cb52bd9a6d2f..1c4633267cc1 100644
--- a/drivers/staging/kpc2000/kpc_dma/fileops.c
+++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
@@ -49,9 +49,11 @@ static int kpc_dma_transfer(struct dev_private_data *priv,
 	u64 dma_addr;
 	u64 user_ctl;
 
-	BUG_ON(priv == NULL);
+	if (!priv)
+		return -EINVAL;
 	ldev = priv->ldev;
-	BUG_ON(ldev == NULL);
+	if (!ldev)
+		return -EINVAL;
 
 	acd = kzalloc(sizeof(*acd), GFP_KERNEL);
 	if (!acd) {
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] staging: kpc2000: replace assertion with recovery code
  2019-12-15 18:12 [PATCH] staging: kpc2000: replace assertion with recovery code Aditya Pakki
@ 2019-12-15 18:28 ` Greg Kroah-Hartman
  2020-01-03  8:49   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-12-15 18:28 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: devel, Harsh Jain, Vandana BN, kjlu, linux-kernel, Simon Sandström

On Sun, Dec 15, 2019 at 12:12:37PM -0600, Aditya Pakki wrote:
> In kpc_dma_transfer, if either priv or ldev is NULL, crashing the
> process is excessive and is not needed. Instead of asserting, by
> passing the error upstream, the error can be handled.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/staging/kpc2000/kpc_dma/fileops.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kpc2000/kpc_dma/fileops.c
> index cb52bd9a6d2f..1c4633267cc1 100644
> --- a/drivers/staging/kpc2000/kpc_dma/fileops.c
> +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
> @@ -49,9 +49,11 @@ static int kpc_dma_transfer(struct dev_private_data *priv,
>  	u64 dma_addr;
>  	u64 user_ctl;
>  
> -	BUG_ON(priv == NULL);
> +	if (!priv)
> +		return -EINVAL;

How can prive ever be NULL here?  Can you track back to all callers to
verify this?  If so, just remove the check.

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] staging: kpc2000: replace assertion with recovery code
  2019-12-15 18:28 ` Greg Kroah-Hartman
@ 2020-01-03  8:49   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-01-03  8:49 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: devel, Harsh Jain, Greg Kroah-Hartman, Simon Sandström,
	kjlu, linux-kernel, Vandana BN

On Sun, Dec 15, 2019 at 07:28:14PM +0100, Greg Kroah-Hartman wrote:
> On Sun, Dec 15, 2019 at 12:12:37PM -0600, Aditya Pakki wrote:
> > In kpc_dma_transfer, if either priv or ldev is NULL, crashing the
> > process is excessive and is not needed. Instead of asserting, by
> > passing the error upstream, the error can be handled.
> > 
> > Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> > ---
> >  drivers/staging/kpc2000/kpc_dma/fileops.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kpc2000/kpc_dma/fileops.c
> > index cb52bd9a6d2f..1c4633267cc1 100644
> > --- a/drivers/staging/kpc2000/kpc_dma/fileops.c
> > +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
> > @@ -49,9 +49,11 @@ static int kpc_dma_transfer(struct dev_private_data *priv,
> >  	u64 dma_addr;
> >  	u64 user_ctl;
> >  
> > -	BUG_ON(priv == NULL);
> > +	if (!priv)
> > +		return -EINVAL;
> 
> How can prive ever be NULL here?  Can you track back to all callers to
> verify this?  If so, just remove the check.
> 

Smatch says that "priv" can't be NULL.

Also if you have a NULL dereference the kernel prints a nice stack
trace.  Normally just doing the NULL dereference and Oopsing is better
than doing a BUG_ON().  The one exception would be when the Oops leads
to filesystem corruption.

regards,
dan carpenter
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, other threads:[~2020-01-03  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-15 18:12 [PATCH] staging: kpc2000: replace assertion with recovery code Aditya Pakki
2019-12-15 18:28 ` Greg Kroah-Hartman
2020-01-03  8:49   ` 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).