From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Michal Simek <michal.simek@xilinx.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Michal Simek <monstr@monstr.eu>, Arnd Bergmann <arnd@arndb.de>,
Linux-Arch <linux-arch@vger.kernel.org>
Subject: Re: [PATCH] dma-mapping: Add BUG_ON for uninitialized dma_ops
Date: Tue, 11 Jun 2013 06:54:18 -0700 [thread overview]
Message-ID: <1370958858.2286.5.camel@dabdike> (raw)
In-Reply-To: <51B703D7.8050804@samsung.com>
On Tue, 2013-06-11 at 13:02 +0200, Marek Szyprowski wrote:
> Hello,
>
> On 6/11/2013 4:34 AM, Bjorn Helgaas wrote:
> > [+cc Marek]
> >
> > On Mon, Jun 3, 2013 at 6:44 AM, Michal Simek <michal.simek@xilinx.com> wrote:
> > > Check that dma_ops are initialized correctly.
> > >
> > > Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> > > ---
> > > Functions dma_mmap_attrs(), dma_get_sgtable_attrs()
> > > already have this checking.
> > >
> > > ---
> > > include/asm-generic/dma-mapping-common.h | 12 ++++++++++++
> > > 1 file changed, 12 insertions(+)
> > >
> > > diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
> > > index de8bf89..d430cab 100644
> > > --- a/include/asm-generic/dma-mapping-common.h
> > > +++ b/include/asm-generic/dma-mapping-common.h
> > > @@ -16,6 +16,7 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
> > > dma_addr_t addr;
> > >
> > > kmemcheck_mark_initialized(ptr, size);
> > > + BUG_ON(!ops);
> >
> > Does this actually help anything? I expected that if "ops" is NULL,
> > we would just oops anyway when we attempted to call "ops->map_page()"
> > because we already trap null pointer dereferences. At least, when I
> > tried leaving a pci_bus.ops pointer NULL, I got a nice panic and
> > backtrace even without adding an explicit BUG_ON().
> >
> > I cc'd Marek, who added the similar BUG_ON()s in dma_mmap_attrs() and
> > dma_get_sgtable_attrs() with d2b7428eb0 and 64ccc9c033.
>
> I think that I've copied it from dma_alloc_coherent() in microblaze. You
> are right that lack
> of this check will also trigger oops in ops==NULL case, but I think that
> adding explicit check
> in all functions, which use it, is a good idea. It serves as a kind of
> documentation and
> emphasizes that missing ops is really an issue.
Really, no, it's not a good idea at all. It invites tons of patches
littering the code with BUG_ONs where we might possibly get a NULL
dereference. All it does is add extra instructions to a code path for
no actual benefit.
If you can answer the question: what more information does the BUG_ON
give you than the NULL deref Oops would not? then it might be
reasonable.
James
next prev parent reply other threads:[~2013-06-11 13:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-03 12:44 [PATCH] dma-mapping: Add BUG_ON for uninitialized dma_ops Michal Simek
2013-06-10 9:00 ` Michal Simek
2013-06-11 2:34 ` Bjorn Helgaas
2013-06-11 11:02 ` Marek Szyprowski
2013-06-11 13:54 ` James Bottomley [this message]
2013-06-12 15:06 ` Arnd Bergmann
2013-06-13 8:51 ` Marek Szyprowski
2013-06-13 20:59 ` James Bottomley
2013-06-14 14:36 ` Arnd Bergmann
2013-06-14 16:14 ` James Bottomley
2013-06-19 15:20 ` Arnd Bergmann
2013-06-26 12:58 ` Michal Simek
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=1370958858.2286.5.camel@dabdike \
--to=james.bottomley@hansenpartnership.com \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=michal.simek@xilinx.com \
--cc=monstr@monstr.eu \
/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.