Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3507295ybl; Sun, 15 Dec 2019 11:21:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxhgHa0jW1+aeEXtqOpxvYzIDIWmiLgbPWMyQgz+C8EcYHKweVCB1T5Tvi1s/4zw6hgY3ea X-Received: by 2002:a05:6830:2081:: with SMTP id y1mr28351815otq.55.1576437679652; Sun, 15 Dec 2019 11:21:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576437679; cv=none; d=google.com; s=arc-20160816; b=aQdzlEfRKnUZvNDl/Irr/HAgfLgUNDRmtrAFbSHyueI/PURizFdGBRot4bOaUq+7Rw gBbTSLPlcUIxI4acVMNmjm95NRW1vnfr0bCz54reg1bzFq7i3+6dfcxZd6p8vkAkPhYh W06AZzzDWEz38a34YCubXlY/iJD1PFpAeZWZBitGVlyayuh7k4dG+fFPncydBed+nvsk gYWHgQ+hf/PPP/Chf1UPHbnWllmWqrrSSOiaixVDyCg7Y6EdqNo3/GkVAeqOwDPQNoAE x9P3eI1Q9NpJu0a4EtJqUvr4Ikg4SupkTU26Y1TBsg6J7KG1G1AZUJJDDj3cpVsoLRVc sOCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=TD8eJUgG1fhr01DWCx63pJF7m5T34fG5E5EbI/ICcoE=; b=PEtteI3XM+v+Sy0nMWShzTI3ylQ6rmPq1wJIMP7gLxU+39M1evYftG39aaH+QRoW42 RZ8xOuNth7XssB19ITEl/7szDg7cDaJP8GAio5SuAr6LE2lW1b2wW3ifr1QK8M7NplN+ 9BacB063tgvRfVjgSqec4eVxgaz0FaaSFq/ID5o4gH1BPDg1qlOufJOQUjTIyxl5nQPv UzP317njNHXl099Mf0v0S+cVXDXyCS0Yhsz4Ib137djmvumRJzpJOUwro07MgKHbPM2F Aqtgw+uuuHbdY7dutIWojxZ+fz9in6ykHWDAbib5XCc9dL6nLWGCGnGluRcNQka0Nnp8 CQkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@networkplumber-org.20150623.gappssmtp.com header.s=20150623 header.b=eNI6ibgc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si9483269oic.119.2019.12.15.11.21.08; Sun, 15 Dec 2019 11:21:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@networkplumber-org.20150623.gappssmtp.com header.s=20150623 header.b=eNI6ibgc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbfLOTU1 (ORCPT + 99 others); Sun, 15 Dec 2019 14:20:27 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45880 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbfLOTU0 (ORCPT ); Sun, 15 Dec 2019 14:20:26 -0500 Received: by mail-pg1-f193.google.com with SMTP id b9so2379275pgk.12 for ; Sun, 15 Dec 2019 11:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TD8eJUgG1fhr01DWCx63pJF7m5T34fG5E5EbI/ICcoE=; b=eNI6ibgcFTrrNyxWgMtfTebJC9mSh5Q5F8xaII86wD8vHx73easJ4146o+yjnYIJbM ws2Wm0h3cDcDvR8T1BITJqBgIdPYKgD71N5Z03EQaCZJOZTSL40Ag1iWjun9L+3FIrQC fLyCzGpRUGC7oFuIUcsWFjggKnxODgBmUrT35/3w3isurbucshyLaooKntvVP4atoc0c OWbRW9VaCfpQ+vDkqbsbUhan7QMIQzB9pQSH4fyPfluSd6EmdIMb5lwrXTJ511AXBA9w M+RTcV+j4Yz2c4r4sAqzeigj7bd4z+7Xvw+pk5/JwhOBHdmXQDcMxFiWEzJb1ariwe9R 4G3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TD8eJUgG1fhr01DWCx63pJF7m5T34fG5E5EbI/ICcoE=; b=EGnWtvciKQZS4nfKk8wsNsPMRWiaZrtKReBNec8oj96yvOGz8XADOZ9XZsV4EZHpIn k90XEmTLSJyyIOAHFSfJxucPcwPtdoaNO6e6FrTs8yzF+luHon4U3eSmy5sgNnlMw+vC QFgGbuIr5kAg97don26d4QswnEU2bxcEM0wCFctKw7Udzdn/V2P0FHqh61UtxlmJIidE U1BAKoampAUL7pnaoq060Iv5Q3Ka6wmscIPfwl4iYvyVNborAwA4kR7sbC8BHg4+VJ1M 88YTpZb8yltOLoVtJB1p6RZ2ful9cz9siczvUSXICLxn/rNreuANYC6jBYdV+iUV8120 IgGA== X-Gm-Message-State: APjAAAWsbrl3zn5c5VBdRRw0YxSL1yENQTjn+Gburrz7ekx2eEe9IE+A CSiKo6usc9uWMVZAwWml6rdvPYKWIDUx6g== X-Received: by 2002:a63:dc41:: with SMTP id f1mr14067497pgj.119.1576437625797; Sun, 15 Dec 2019 11:20:25 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id d77sm20483423pfd.126.2019.12.15.11.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2019 11:20:25 -0800 (PST) Date: Sun, 15 Dec 2019 11:20:17 -0800 From: Stephen Hemminger To: Aditya Pakki Cc: kjlu@umn.edu, "David S. Miller" , Greg Kroah-Hartman , Markus Elfring , Richard Fontana , Thomas Gleixner , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] hdlcdrv: replace assertion with recovery code Message-ID: <20191215112017.07502383@hermes.lan> In-Reply-To: <20191215175842.30767-1-pakki001@umn.edu> References: <20191215175842.30767-1-pakki001@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 15 Dec 2019 11:58:41 -0600 Aditya Pakki 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 > --- > 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".