All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ryan Mallon <rmallon@gmail.com>
To: Dave Jones <davej@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Myklebust, Trond" <Trond.Myklebust@netapp.com>,
	Joerg Roedel <joro@8bytes.org>,
	Joerg Roedel <joerg.roedel@amd.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: BUG_ON/panic proliferation.
Date: Fri, 28 Sep 2012 10:52:50 +1000	[thread overview]
Message-ID: <5064F4E2.6010301@gmail.com> (raw)
In-Reply-To: <20120927173057.GA13142@redhat.com>

On 28/09/12 03:30, Dave Jones wrote:
> On Thu, Sep 27, 2012 at 09:59:13AM -0700, Linus Torvalds wrote:
>
>  > We have too many f*cking BUG_ON's in the kernel, and the fact that one
>  > triggers and it has taken a month and a half without it even being
>  > resolved is a problem.
>
> This has bothered me for a while.
>
> $ rgrep BUG_ON drivers/ | wc -l
> 4018
> $ rgrep WARN_ON drivers/ | wc -l
> 2415
> $ rgrep panic drivers/ | wc -l
> 997
>
> $ rgrep BUG_ON fs | wc -l
> 2792
> $ rgrep WARN_ON fs | wc -l
> 524
> $ rgrep panic fs | wc -l
> 381

The situation isn't quite that bad. Your grep picks up a few variables
with panic in the name and some wrapper functions around panic. This
gets closer to the real counts (still finds some instances in comments):

  $git grep "[^_]panic *(" drivers/  | wc -l
  282

  $git grep "[^_]panic *(" fs/  | wc -l
  53

Some of those look reasonably easy to remove. For example, the panics in
the module_init path for drivers/tty/pty.c could be modified to simply
return -ENOMEM. Something like the below removes 9 panic calls
(completely untested).

~Ryan

---

Remove panic calls from drivers/tty/pty.c
    
There is no need to panic the system if the allocation/registration of
the pty drivers fails. Instead return an error and fail the module load.
    
Signed-off-by: Ryan Mallon <rmallon@gmail.com>

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 5505ffc..69af453 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -382,20 +382,21 @@ static const struct tty_operations slave_pty_ops_bsd = {
 	.resize = pty_resize
 };
 
-static void __init legacy_pty_init(void)
+static int __init legacy_pty_init(void)
 {
 	struct tty_driver *pty_driver, *pty_slave_driver;
+	int err = -ENOMEM;
 
 	if (legacy_count <= 0)
-		return;
+		return 0;
 
 	pty_driver = alloc_tty_driver(legacy_count);
 	if (!pty_driver)
-		panic("Couldn't allocate pty driver");
+		goto fail;
 
 	pty_slave_driver = alloc_tty_driver(legacy_count);
 	if (!pty_slave_driver)
-		panic("Couldn't allocate pty slave driver");
+		goto fail_put_pty_driver;
 
 	pty_driver->driver_name = "pty_master";
 	pty_driver->name = "pty";
@@ -429,13 +430,35 @@ static void __init legacy_pty_init(void)
 	pty_slave_driver->other = pty_driver;
 	tty_set_operations(pty_slave_driver, &slave_pty_ops_bsd);
 
-	if (tty_register_driver(pty_driver))
-		panic("Couldn't register pty driver");
-	if (tty_register_driver(pty_slave_driver))
-		panic("Couldn't register pty slave driver");
+	err = tty_register_driver(pty_driver);
+	if (err)
+		goto fail_put_pty_slave_driver;
+	err = tty_register_driver(pty_slave_driver);
+	if (err)
+		goto fail_unregister_pty_driver;
+
+	return 0;
+
+fail_unregister_pty_driver:
+	tty_unregister_driver(pty_driver);
+fail_put_pty_slave_driver:
+	tty_driver_put(pty_slave_driver);
+fail_put_pty_driver:
+	tty_driver_put(pty_driver);
+fail:
+	return err;
+}
+
+static void __init legacy_pty_free(void)
+{
+	tty_unregister_driver(pty_slave_driver);
+	tty_unregister_driver(pty_driver);
+	tty_driver_put(pty_slave_driver);
+	tty_driver_put(pty_driver);
 }
 #else
 static inline void legacy_pty_init(void) { }
+static inline void legacy_pty_free(void) { }
 #endif
 
 /* Unix98 devices */
@@ -670,14 +693,16 @@ err_file:
 
 static struct file_operations ptmx_fops;
 
-static void __init unix98_pty_init(void)
+static int __init unix98_pty_init(void)
 {
+	int err = -ENOMEM;
+
 	ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
 	if (!ptm_driver)
-		panic("Couldn't allocate Unix98 ptm driver");
+		goto fail;
 	pts_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
 	if (!pts_driver)
-		panic("Couldn't allocate Unix98 pts driver");
+		goto fail_put_ptm_driver;
 
 	ptm_driver->driver_name = "pty_master";
 	ptm_driver->name = "ptm";
@@ -712,20 +737,40 @@ static void __init unix98_pty_init(void)
 	pts_driver->other = ptm_driver;
 	tty_set_operations(pts_driver, &pty_unix98_ops);
 
-	if (tty_register_driver(ptm_driver))
-		panic("Couldn't register Unix98 ptm driver");
-	if (tty_register_driver(pts_driver))
-		panic("Couldn't register Unix98 pts driver");
+	err = tty_register_driver(ptm_driver);
+	if (err)
+		goto fail_put_pts_driver;
+	err = tty_register_driver(pts_driver);
+	if (err)
+		goto fail_unregister_ptm_driver;
 
 	/* Now create the /dev/ptmx special device */
 	tty_default_fops(&ptmx_fops);
 	ptmx_fops.open = ptmx_open;
 
 	cdev_init(&ptmx_cdev, &ptmx_fops);
-	if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
-	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
-		panic("Couldn't register /dev/ptmx driver\n");
+	err = cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1);
+	if (err)
+		goto fail_unregister_pts_driver;
+	err = register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx");
+	if (err)
+		goto fail_cdev_del;
+
 	device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
+	return 0;
+
+fail_cdev_del:
+	cdev_del(&ptmx_cdev);
+fail_unregister_pts_driver:
+	tty_unregister_driver(pts_driver);
+fail_unregister_ptm_driver:
+	tty_unregister_driver(ptm_driver);
+fail_put_pts_driver:
+	tty_put_driver(pts_driver);
+fail_put_ptm_driver:
+	tty_put_driver(ptm_driver);
+fail:
+	return err;
 }
 
 #else
@@ -734,8 +779,17 @@ static inline void unix98_pty_init(void) { }
 
 static int __init pty_init(void)
 {
-	legacy_pty_init();
-	unix98_pty_init();
+	int err;
+
+	err = legacy_pty_init();
+	if (err)
+		return err;
+
+	err = unix98_pty_init();
+	if (err) {
+		legacy_pty_free();
+		return err;
+	}
 	return 0;
 }
 module_init(pty_init);


  reply	other threads:[~2012-09-28  0:53 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07 13:41 kernel BUG at /data/lemmy/linux.trees.git/fs/nfs/idmap.c:681! Joerg Roedel
2012-08-07 13:55 ` Bryan Schumaker
2012-08-07 14:15   ` Joerg Roedel
2012-08-07 14:17     ` Bryan Schumaker
2012-08-07 14:27       ` Joerg Roedel
2012-08-07 14:36         ` Bryan Schumaker
2012-08-07 14:50           ` Joerg Roedel
2012-08-07 15:12             ` Bryan Schumaker
2012-08-07 15:19             ` Myklebust, Trond
2012-08-07 15:19               ` Myklebust, Trond
2012-08-07 15:14           ` Myklebust, Trond
2012-08-07 15:14             ` Myklebust, Trond
2012-08-07 15:18             ` Bryan Schumaker
2012-09-27 14:52 ` Joerg Roedel
2012-09-27 15:32   ` Myklebust, Trond
2012-09-27 15:39     ` Joerg Roedel
2012-09-27 16:16       ` Myklebust, Trond
2012-09-27 16:16         ` Myklebust, Trond
2012-09-27 16:59         ` Linus Torvalds
2012-09-27 17:30           ` BUG_ON/panic proliferation Dave Jones
2012-09-28  0:52             ` Ryan Mallon [this message]
2012-09-28 10:08               ` Alan Cox
2012-09-27 21:21           ` kernel BUG at /data/lemmy/linux.trees.git/fs/nfs/idmap.c:681! Myklebust, Trond
2012-09-27 21:21             ` Myklebust, Trond
2012-09-27 17:56         ` Joerg Roedel
2012-09-27 18:15           ` Bryan Schumaker
2012-09-28 12:17             ` Joerg Roedel
2012-09-28 13:21               ` Bryan Schumaker
2012-09-28 13:34                 ` Joerg Roedel

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=5064F4E2.6010301@gmail.com \
    --to=rmallon@gmail.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=davej@redhat.com \
    --cc=joerg.roedel@amd.com \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.