netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Aditya Pakki <pakki001@umn.edu>
Cc: kjlu@umn.edu, "David S. Miller" <davem@davemloft.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Markus Elfring <elfring@users.sourceforge.net>,
	Richard Fontana <rfontana@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hdlcdrv: replace assertion with recovery code
Date: Sun, 15 Dec 2019 11:20:17 -0800	[thread overview]
Message-ID: <20191215112017.07502383@hermes.lan> (raw)
In-Reply-To: <20191215175842.30767-1-pakki001@umn.edu>

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

      parent reply	other threads:[~2019-12-15 19:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191215112017.07502383@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=davem@davemloft.net \
    --cc=elfring@users.sourceforge.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pakki001@umn.edu \
    --cc=rfontana@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).