public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Mackall <mpm@selenic.com>
To: Hareesh Nagarajan <hnagar2@gmail.com>
Cc: linux-kernel@vger.kernel.org, ak@suse.de
Subject: Re: [TRIVIAL] Error checks omitted in init_tmpfs() in mm/tiny-shmem.c
Date: Mon, 24 Oct 2005 13:45:18 -0700	[thread overview]
Message-ID: <20051024204518.GI26160@waste.org> (raw)
In-Reply-To: <435CA1CF.3070204@gmail.com>

On Mon, Oct 24, 2005 at 03:56:47AM -0500, Hareesh Nagarajan wrote:
> Matt Mackall wrote:
> >On Mon, Oct 24, 2005 at 12:29:45AM -0500, Hareesh Nagarajan wrote:
> >>The existing code in init_tmpfs() in mm/tiny-shmem.c does not handle the 
> >>cases when the calls to register_filesystem() and kern_mount() fail. 
> >>This patch adds those checks.
> >
> >Hmm. Did you actually encounter this?
> 
> No, I haven't. I was just reading the source code when I chanced upon 
> these trivial error checking omissions.
> 
> >I'd rather use BUG_ON. Passing up errors is only useful when the code
> >above can and will do something useful with the information. 
> 
> [ Snip ]
> 
> >And what could the higher level, which is simply looping through init
> >functions, do to handle the error? Retry? Print a warning? Better to
> >stop everything outright when we encounter a problem we expect should
> >never happen so it doesn't go by undiagnosed.
> 
> Makes sense. New patch attached.

A couple more comments..

> Signed-off-by: Hareesh Nagarajan <hnagar2@gmail.com>

> --- linux-2.6.13.4/mm/tiny-shmem.c	2005-10-10 13:54:29.000000000 -0500
> +++ linux-2.6.13.4-edit/mm/tiny-shmem.c	2005-10-24 03:43:38.614071000 -0500
> @@ -31,12 +31,18 @@
>  
>  static int __init init_tmpfs(void)
>  {
> -	register_filesystem(&tmpfs_fs_type);
> +	int error;
> +
> +	error = register_filesystem(&tmpfs_fs_type);
> +	BUG_ON(error);

Can we just do BUG_ON(register_filesystem() != 0)?

Strictly speaking, the != 0 is redundant, but as this goes slightly
against the grain of normal usage, it's a good indicator of intent.

> +
>  #ifdef CONFIG_TMPFS
>  	devfs_mk_dir("shm");
>  #endif
>  	shm_mnt = kern_mount(&tmpfs_fs_type);
> -	return 0;
> +	BUG_ON(IS_ERR(shm_mnt));
> +
> +	return error;

We can never return non-zero here. Returning error implies we can, so
it's confusing.

-- 
Mathematics is the supreme nostalgia of our time.

  reply	other threads:[~2005-10-24 20:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-24  5:29 [TRIVIAL] Error checks omitted in init_tmpfs() in mm/tiny-shmem.c Hareesh Nagarajan
2005-10-24  7:09 ` Matt Mackall
2005-10-24  8:56   ` Hareesh Nagarajan
2005-10-24 20:45     ` Matt Mackall [this message]
2005-10-24 21:00       ` Muli Ben-Yehuda
2005-10-24 21:08         ` Matt Mackall
2005-10-25  0:16       ` Hareesh Nagarajan

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=20051024204518.GI26160@waste.org \
    --to=mpm@selenic.com \
    --cc=ak@suse.de \
    --cc=hnagar2@gmail.com \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox