netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hdlcdrv: replace assertion with recovery code
@ 2019-12-15 17:58 Aditya Pakki
  2019-12-15 18:50 ` Markus Elfring
  2019-12-15 19:20 ` Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Aditya Pakki @ 2019-12-15 17:58 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, David S. Miller, Greg Kroah-Hartman, Markus Elfring,
	Richard Fontana, Thomas Gleixner, netdev, linux-kernel

In hdlcdrv_register, failure to register the driver causes a crash.
However, by returning the error to the caller in case ops is NULL
can avoid the crash. The patch fixes this issue.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/net/hamradio/hdlcdrv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index df495b5595f5..38e5d1e54800 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -687,7 +687,8 @@ struct net_device *hdlcdrv_register(const struct hdlcdrv_ops *ops,
 	struct hdlcdrv_state *s;
 	int err;
 
-	BUG_ON(ops == NULL);
+	if (!ops)
+		return ERR_PTR(-EINVAL);
 
 	if (privsize < sizeof(struct hdlcdrv_state))
 		privsize = sizeof(struct hdlcdrv_state);
-- 
2.20.1


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

* Re: [PATCH] hdlcdrv: replace assertion with recovery code
  2019-12-15 17:58 [PATCH] hdlcdrv: replace assertion with recovery code Aditya Pakki
@ 2019-12-15 18:50 ` Markus Elfring
  2019-12-15 19:20 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-12-15 18:50 UTC (permalink / raw)
  To: Aditya Pakki, netdev
  Cc: Kangjie Lu, David S. Miller, Greg Kroah-Hartman, Richard Fontana,
	Thomas Gleixner, linux-kernel

> However, by returning the error to the caller in case ops is NULL
> can avoid the crash.

I suggest to improve this change description by choosing also
a more imperative wording.


> The patch fixes this issue.
Please replace this sentence by the tag “Fixes”.

Regards,
Markus

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

* Re: [PATCH] hdlcdrv: replace assertion with recovery code
  2019-12-15 17:58 [PATCH] hdlcdrv: replace assertion with recovery code Aditya Pakki
  2019-12-15 18:50 ` Markus Elfring
@ 2019-12-15 19:20 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2019-12-15 19:20 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: kjlu, David S. Miller, Greg Kroah-Hartman, Markus Elfring,
	Richard Fontana, Thomas Gleixner, netdev, linux-kernel

On Sun, 15 Dec 2019 11:58:41 -0600
Aditya Pakki <pakki001@umn.edu> wrote:

> In hdlcdrv_register, failure to register the driver causes a crash.
> However, by returning the error to the caller in case ops is NULL
> can avoid the crash. The patch fixes this issue.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/net/hamradio/hdlcdrv.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
> index df495b5595f5..38e5d1e54800 100644
> --- a/drivers/net/hamradio/hdlcdrv.c
> +++ b/drivers/net/hamradio/hdlcdrv.c
> @@ -687,7 +687,8 @@ struct net_device *hdlcdrv_register(const struct hdlcdrv_ops *ops,
>  	struct hdlcdrv_state *s;h
>  	int err;
>  
> -	BUG_ON(ops == NULL);
> +	if (!ops)
> +		return ERR_PTR(-EINVAL);
>  
>  	if (privsize < sizeof(struct hdlcdrv_state))
>  		privsize = sizeof(struct hdlcdrv_state);

It is good to remove BUG_ON's but this is not a good way to fix it.
The original code was being over paranoid.  There are only 3 places
this function is called in the current kernel and all pass a valid
pointer.  Better just remove the BUG_ON all together; it is not
worth carrying bug checks for "some day somebody might add broken code".

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

end of thread, other threads:[~2019-12-15 19:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-15 17:58 [PATCH] hdlcdrv: replace assertion with recovery code Aditya Pakki
2019-12-15 18:50 ` Markus Elfring
2019-12-15 19:20 ` Stephen Hemminger

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