public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pete Zaitcev <zaitcev@redhat.com>
To: Stephan von Krawczynski <skraw@ithnet.com>
Cc: Peter Wong <wpeter@us.ibm.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Encountered a Null Pointer Problem on the SCSI Layer
Date: Mon, 18 Feb 2002 19:04:07 -0500	[thread overview]
Message-ID: <20020218190407.A16616@devserv.devel.redhat.com> (raw)
In-Reply-To: <OFC7A42817.7DD2C3FB-ON85256B64.00725D00@raleigh.ibm.com> <200202182301.AAA23425@webserver.ithnet.com>
In-Reply-To: <200202182301.AAA23425@webserver.ithnet.com>; from skraw@ithnet.com on Tue, Feb 19, 2002 at 12:01:39AM +0100

> Date: Tue, 19 Feb 2002 00:01:39 +0100
> From: Stephan von Krawczynski <skraw@ithnet.com>

> Are you 100% sure, that there is no case where                        
> dpnt==NULL? Because if there is such a possibility, your patch will   
> blow up.                                                              

If there is such a possibility, everything will blow up.

Please bear with me while I am ranting at your expense, but
your example is very educational.

It seems to me that many people consider that putting a check
for NULL in front of every pointer dereference is an answer
to everything, including a missing understanding of the code.
It actually is not the case, IMHO. In well written code,
checks for NULL are not introduced to prevent oopses locally.
Instead, they implement a functionality, according to the
master plan. To distinguish these two conditions, mentally
consider a replacement of the check with something more descriptive.
When my eye sees a code that does this:

	if (p->foo == NULL)
		return -EINVAL;

my mind sees either this:

	/*
	 * Our brains are too small to wrap arouund this module,
	 * and we saw an oops somewhere. Let's plug it with
	 * a check and pray that nobody will notice.
	 */
	if (p->foo == NULL)
		return -EINVAL;

or this:

	if (device_is_attached(dpnt))
		return -EINVAL;		/* XXX TODO: -ENODEV, not -EINVAL */

The code may be conductive to such interpretation by the mind,
or it may be not. In latter case we do what is called "a cleanup".

Often, the interpretation can only be done by looking at the
code as a whole, but this particular patch is nearly obvious
by itself:

> >       dpnt = &rscsi_disks[target];                                  
> > -     if (!dpnt)                                                    
> > +     if (!dpnt->device)                                            
> >             return NULL;      /* No such device */                  
> >       return &dpnt->device->request_queue;                          

The dpnt may be null ONLY if we do I/O to the first partition
of a first disk. Is anything special about that case?
I think not. Also, look at the comment. Obviously, the if() was
meant for something other than a corner case of partition zero.
It seems probable that the data layout was modified
but the check was forgotten.

-- Pete

  reply	other threads:[~2002-02-19  0:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-18 21:03 [PATCH] Encountered a Null Pointer Problem on the SCSI Layer Peter Wong
2002-02-18 23:01 ` Stephan von Krawczynski
2002-02-19  0:04   ` Pete Zaitcev [this message]
2002-02-19 11:55     ` Stephan von Krawczynski

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=20020218190407.A16616@devserv.devel.redhat.com \
    --to=zaitcev@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skraw@ithnet.com \
    --cc=wpeter@us.ibm.com \
    /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