All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Russell King - ARM Linux <linux@armlinux.org.uk>
Cc: Nathan Jones <nathanj439@gmail.com>,
	Vladimir Murzin <vladimir.murzin@arm.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Christoph Hellwig <hch@lst.de>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2] ARM: dma-mapping: fix potential uninitialized return
Date: Thu, 29 Nov 2018 17:26:27 +0100	[thread overview]
Message-ID: <20181129162627.GB27068@lst.de> (raw)
In-Reply-To: <20181129102259.GR30658@n2100.armlinux.org.uk>

On Thu, Nov 29, 2018 at 10:22:59AM +0000, Russell King - ARM Linux wrote:
> I don't think so - if we were to remove the call to
> dma_mmap_from_dev_coherent(), it reintroduces the bug.
> 
> Quite why we have dma_mmap_from_dev_coherent() returning a 0/1 and
> error code via pointer I'm really not sure.
> 
> 	ret = dma_mmap_from_dev_coherent(...);
> 	if (ret)
> 		return ret > 0 ? 0 : ret;
> 
> and have dma_mmap_from_dev_coherent() return -ve for errnos, 1 if
> mapped via the coherent pool mechanism, or 0 otherwise.
> 
> The down-side is that 'ret' would be zero for the follow-on code,
> which would need explicit initialisation - but at least it's then
> obvious what is going on.

The above would be better than the current calling conventions, which
are horrible.  But the magic positive error code also tends to lead
to subtle errors sometimes.  My preference for this pattern is something
like:

	bool mapped;

	ret = dma_mmap_from_dev_coherent(..., &mapped);
	if (ret || mapped)
		return ret;

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2018-11-29 16:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28 17:39 [PATCH] ARM: dma-mapping: fix potential uninitialized return Nathan Jones
2018-11-28 17:47 ` Russell King - ARM Linux
2018-11-28 18:59 ` [PATCH v2] " Nathan Jones
2018-11-29  9:50   ` Vladimir Murzin
2018-11-29 10:11     ` Vladimir Murzin
2018-11-29 10:22       ` Russell King - ARM Linux
2018-11-29 16:26         ` Christoph Hellwig [this message]
2018-11-29 10:14     ` Russell King - ARM Linux
2018-11-29 14:58     ` Nathan Jones
2018-11-29 15:24       ` Russell King - ARM Linux
2018-11-30  9:00       ` Vladimir Murzin
2018-11-29 15:17   ` Robin Murphy
2018-11-30 13:07   ` [PATCH v3] " Nathan Jones
2018-12-04  9:09     ` Vladimir Murzin

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=20181129162627.GB27068@lst.de \
    --to=hch@lst.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=nathanj439@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=vladimir.murzin@arm.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 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.